Call value from another page [closed]

0

Hello everyone. I'm having a problem with passing data from one page to another. I have already tried for session and not very sure and I will explain the reason:

I have a news page that distributes them for a for $ arr [] where I embed the title, news body etc. Then, when entering a specific news (that read more), I have to give a SELECT in the database again and distribute the title, body etc of the news and this I do by the ID of it in the database. It turns out that to pass the ID of the news he clicked pro SELECT the other page I get all mixed up. In my attempts there was something of the sort:

1st saving the data in the variable: $ variable = array ("$ arr [2]")

2nd taking this data through the session: SELECT bla bla bla WHERE id = $ variable and it does not return the value of this variable I did more or less up, of course I opened the sessions and everything else kkkkkk

Anyway, thank you in advance!

    
asked by anonymous 17.09.2015 / 06:56

2 answers

1

I could not quite understand your doubt, but I'll try to help you.

If what you wanted to say is this: "You have a news site and you want to get the news ID when the visitor clicks 'Read more ...'.

If this is the case, the correct procedure for you to get the ID would be as follows. To load the news you use the $_GET method to load news content.

So the site looks like this: When the visitor clicks on "Read more ..." it will be redirected to a page with the link 'site.com/?noticia=3'(Noticia=3, is an example of $_GET['noticia'] , this is at your disposal.

I hope your question has been resolved.

    
17.09.2015 / 10:22
1

Trying to be didactic, I think you could try it as follows ... (I do not know which database it uses, I've done an example using MYSQL).

On the page that lists the news, do the following in the "read more" link for each news:

for($i = 0; $i < mysql_num_rows($rs_noticias); $i++){    
     echo '<div>';
     echo '<h2>' . mysql_result($rs_noticias, $i, 'titulo_noticia') . '</h2>';
     echo mysql_result($rs_noticias, $i, 'texto_noticia');
     echo '<a href="leia_mais.php?id_noticia=' . mysql_result($rs_noticias, $i, 'codigo_noticia') . '">Leia mais...</a>';
     echo '</div>';
}

In the page that will detail the news, which in the example is called 'leia_mais.php', you can do the following:

<?php
$codigo_noticia = $_GET['id_noticia'];
$sql = 'SELECT bla bla bla WHERE id =' . $codigo_noticia;
echo $sql;

I hope I have helped! Any questions just ask!

    
17.09.2015 / 13:12