Jump to content

Archived

This topic is now archived and is closed to further replies.

1042

page.php?id=1 or whatever id not working

Recommended Posts

Hello All,

im creating this sort of news script and im having an issue, the code to display the date, title and the read more link is below the name of this page events.php

[code] $getpress = mysql_query("SELECT * FROM press ORDER BY pressid DESC");//query the database for all of the news

while($r=mysql_fetch_array($getpress)){//while there are rows in the table
extract($r);//remove the $r so its just $variable

echo("
<font class=\"bluetext\">$date</font> - <font class=\"blueboldpress\"><strong>$title</strong></font><br>
<a href=\"press.php?id=$pressid\">[Read More]</font></a><br><br>");

} [/code]

and the code to display the complete news article is below the name of this page is press.php

[code]
$detailpress = mysql_query("SELECT * FROM press WHERE id= '$pressid'");//query the database for detail news article
while($r=mysql_fetch_array($detailpress)){//while there are rows in the table
extract($r);//remove the $r so its just $variable

echo("
<font class=\"bluetext\">$date</font> - <font class=\"blueboldpress\"><strong>$title</strong></font>
<font class=\"bluetext\">$content</font><br>");
} [/code]


the problem is that i get an error "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\interactive\press.php on line 173"

line 173 would be were the "while" statement starts on the press.php file, any ideas what im doing wrong, any help is appreciated, thank you in advance.

Share this post


Link to post
Share on other sites
change line 172 in press.php to this:

[code]$detailpress = mysql_query("SELECT * FROM press WHERE id= '$pressid'") or die(mysql_error());[/code]

looks like your query is not working properly, so your resource ID isn't valid to use in mysql_fetch_array().  chances are you should be using $_GET['pressid'], not $pressid.  if it works upon changing it to $_GET['pressid'], search google about register_globals, and why you shouldn't rely on it.

Share this post


Link to post
Share on other sites
Hi thanks for the help, i change that line and i got this error

Unknown column 'id' in 'where clause'

so i change the code to this

[code]$detailpress = mysql_query("SELECT * FROM press WHERE pressid= '$pressid'") or die(mysql_error())[/code]

instead of this

[code]$detailpress = mysql_query("SELECT * FROM press WHERE id= '$pressid'") or die(mysql_error());[/code]

if i do this i can see the first record on the database but if i do press.php?id=2 i still see tha same record, it wont change to that particular record

if i do this:

[code]$detailpress = mysql_query("SELECT * FROM press WHERE id= $_GET['pressid']") or die(mysql_error());[/code]

i get this error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Program Files\xampp\htdocs\headinteractive\press.php on line 171

any ideas? thanks in advance.

Share this post


Link to post
Share on other sites
try [code]$detailpress = mysql_query("SELECT * FROM press WHERE id= {$_GET['pressid']}") or die(mysql_error());[/code]

Share this post


Link to post
Share on other sites
You need to use a limit clause, basiacllay look into pagination with a limit of 1 record:

[url=http://www.phpfreaks.com/tutorials/43/0.php]http://www.phpfreaks.com/tutorials/43/0.php[/url]

hth

Share this post


Link to post
Share on other sites
[quote author=sasa link=topic=110111.msg444867#msg444867 date=1159734607]
try [code]$detailpress = mysql_query("SELECT * FROM press WHERE id= {$_GET['pressid']}") or die(mysql_error());[/code]
[/quote]

Thanks SASA and to everybody for the help, this is a great community specially for newbies like me  , i was able to solve the issue following the advice given in this post, here is how my query looks now:

PHP Code:
[code]$detailpress = mysql_query("SELECT * FROM press WHERE pressid= {$_GET['pressid']}") or die(mysql_error());[/code]


once again, you help was greatly appreciated, thanks all.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.