1042 Posted October 1, 2006 Share Posted October 1, 2006 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 newswhile($r=mysql_fetch_array($getpress)){//while there are rows in the tableextract($r);//remove the $r so its just $variableecho("<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 articlewhile($r=mysql_fetch_array($detailpress)){//while there are rows in the tableextract($r);//remove the $r so its just $variableecho("<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. Link to comment https://forums.phpfreaks.com/topic/22626-pagephpid1-or-whatever-id-not-working/ Share on other sites More sharing options...
akitchin Posted October 1, 2006 Share Posted October 1, 2006 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. Link to comment https://forums.phpfreaks.com/topic/22626-pagephpid1-or-whatever-id-not-working/#findComment-101656 Share on other sites More sharing options...
1042 Posted October 1, 2006 Author Share Posted October 1, 2006 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 recordif 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 171any ideas? thanks in advance. Link to comment https://forums.phpfreaks.com/topic/22626-pagephpid1-or-whatever-id-not-working/#findComment-101978 Share on other sites More sharing options...
sasa Posted October 1, 2006 Share Posted October 1, 2006 try [code]$detailpress = mysql_query("SELECT * FROM press WHERE id= {$_GET['pressid']}") or die(mysql_error());[/code] Link to comment https://forums.phpfreaks.com/topic/22626-pagephpid1-or-whatever-id-not-working/#findComment-101983 Share on other sites More sharing options...
bob_the _builder Posted October 1, 2006 Share Posted October 1, 2006 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 Link to comment https://forums.phpfreaks.com/topic/22626-pagephpid1-or-whatever-id-not-working/#findComment-101984 Share on other sites More sharing options...
1042 Posted October 2, 2006 Author Share Posted October 2, 2006 [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. Link to comment https://forums.phpfreaks.com/topic/22626-pagephpid1-or-whatever-id-not-working/#findComment-102159 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.