Jump to content


Photo

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


  • Please log in to reply
5 replies to this topic

#1 1042

1042
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 01 October 2006 - 01:08 AM

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

$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>");

}

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

 $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>");
}


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.

#2 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 01 October 2006 - 01:18 AM

change line 172 in press.php to this:

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

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.

#3 1042

1042
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 01 October 2006 - 08:16 PM

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

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

instead of this

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

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:

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

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.

#4 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 01 October 2006 - 08:30 PM

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


#5 bob_the _builder

bob_the _builder
  • Members
  • PipPipPip
  • Advanced Member
  • 207 posts

Posted 01 October 2006 - 08:37 PM

You need to use a limit clause, basiacllay look into pagination with a limit of 1 record:

http://www.phpfreaks...orials/43/0.php

hth

#6 1042

1042
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 02 October 2006 - 07:37 AM

try

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


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:
$detailpress = mysql_query("SELECT * FROM press WHERE pressid= {$_GET['pressid']}") or die(mysql_error());


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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users