Two sql queries
| From: | Bzdpltd at aol dot com | Date: | Wed, 02 Oct 2002 13:12:45 +0000 |
| Subject: | Two sql queries | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-22152@lists.php.net to get a copy of this message | ||
Hi there,
Wonder if someone could help me, I have not touched PHP in a while now so a little rusty.
What i have is a news page now the news story is disaplayed when someone clicks the item from the
home page, which then loads a news page, but the problem I am having is when the news page loads it
has the links down the left with the other news stories, all with the correct id numbers appended to
the link, but the news item on the page is loading as the last one, and when you click the links it
does not load the correct item.
Now I know this is something to do with having two sql queries on the same page, and the id number
being fetched.
Here is the code for the two sql statements on the same page, if someone could help it would be most
appreciated.
<?
//start query code
$sql= "SELECT * FROM news WHERE 'Corporate' = division ";
$sql_result = mysql_query($sql);
if (mysql_num_rows($sql_result) ==0)
{
echo (" \n");
}
else {
while ($row = mysql_fetch_array($sql_result)){
$title = $row["title"];
$id = $row["id"];
echo ("<tr> \n");
echo ("<td width=\"13%\" class=\"body\"><p>
</p></td> \n");
echo ("<td width=\"87%\"><p><a
href=\"news.php?id=$id\">$title</a></p></td> \n");
echo ("</tr> \n");
}}
?>
<?
//start query code
$sql= "SELECT * FROM news WHERE ('$id' = id) ";
$sql_result = mysql_query($sql);
if (mysql_num_rows($sql_result) ==0)
{
echo (" \n");
}
else {
while ($row = mysql_fetch_array($sql_result)){
$division = $row["division"];
$title = $row["title"];
$date = $row["date"];
$content = $row["content"];
$link = $row["link"];
echo ("<h3>$title</h3> \n");
echo ("<p>" . date ('F jS Y',strtotime($date)) . " </p>
\n");
echo ("<p>$content</p> \n");
echo ("<p> </p> \n");
}}
?>
There is html code inbetween these two statements, and the id number is passed from the index page
with the news item listed.
Hope someone can help me in the right direction.
Thanks
Barry Zimmermn