Forum Moderators: coopster

Message Too Old, No Replies

Passing Variable through URL

want to send news article to a new page

         

mcjohnson

1:25 pm on Jun 3, 2006 (gmt 0)

10+ Year Member



Hello all,

I have a nice full database containing all the elements of news articles, including title, summary, dates posted, content, and so on.

I am displaying the TITLE and the SUMMARY of those articles on the home page, extracting them from the MySQL table.

So far, so good. Now, I am trying to create a URL so that when the user clicks "more", he/she will be taken to a new page where the entire article can be read.

this is what I have on the index.php page to set the variables I am displaying on that page:

$date = date("Y-m-d");
$title =$row['title'];
$summary =$row['summary'];
$news_id = $row['news_id'];

(the news_id is not being displayed on the home page, it's simply the primary key...I thought I might need that to pass the varible to the new page. What I need to do is send the specific artcile that the user clicks on "more" over to "news1.php" and display whatever parts of the SQL table, particularly the main content. So, I've crafted the code in the Index page to look like this:

$results=mysql_query($query) or die (mysql_error());
while ($rows=mysql_fetch_array($results)) {
extract ($rows);
echo "<b>$title</b>";
echo "<br>";
echo $summary;
echo "&nbsp<a href='news1.php?news_id=$row[news_id]'>";
echo "(more)";
echo "</a>";
echo "<br><br>";
}

I have set up the news1.php page to receive the variable as such:

<?php echo $_REQUEST['news_id']?>

and then trying to display at least fow now, the summary by doing this:

<?php echo $summary?>

but nothing is happening. I get the blank page, but even the title does not reflect the name that I am tryign to pass over so clearly the info is not getting passed.

Am I way off base here? I would truly appreciate any comments or feedback you might provide.

As always, THANKS!

Pat

eelixduppy

2:12 pm on Jun 3, 2006 (gmt 0)



Change the following:

echo "&nbsp<a href='news1.php?news_id=$row[news_id]'>";

TO


echo "&nbsp<a href='news1.php?news_id=$rows[news_id]'>";//or just use $news_id

Secondly, you are going to have to retrieve the article from the table again once you pass the news id to news1.php. You can use $_GET["news_id"] to retrieve the id from this page. An example query for news1.php would go something like this:
$query = "SELECT * FROM news WHERE news_id = ".$_GET["news_id"];

For future debugging, add error_reporting [us3.php.net](E_ALL); to the top of the script you are having trouble with.

Good luck!

mcjohnson

5:02 pm on Jun 3, 2006 (gmt 0)

10+ Year Member



perfect! Thanks very much. I appreciate the help!

Pat

eelixduppy

5:03 pm on Jun 3, 2006 (gmt 0)



You're welcome. I'm glad you got it! ;)