Help with news script

Hey there.

I have just constructed my first PHP/MySQL script, and despite careful debugging, can’t seem to find the source of this error:

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /fpgs/fpgshttpd/nsac/index.php on line 20

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /fpgs/fpgshttpd/nsac/index.php on line 21

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /fpgs/fpgshttpd/nsac/index.php on line 22

Now, I’ve gone through the entire thing, and I can’t seem to find the problem. These are lines 20, 21, and 22:

$date=mysql_result($date,$i,"date"); $news=mysql_result($news,$i,"news"); $tag=mysql_result($tag,$i,"tag");

I’ve quintuple-checked my database, and I’m certain that there are columns called “date”, “news”, and “tag”.

I must be overlooking something incredibly stupid.

Thanks so much in advance for your help.

What does the mysql_query() part look like (and the lines between them and the 20th, 21st and 22nd line)? Usually such errors pop up when the’re no result returned by the query function.

If the small snippet was not enough help, here is all of the code:

<html>
<head>
<?
include("dbinfo.inc.php");
mysql_connect("mysql5.freepgs.com",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM news";
$result=mysql_query($query);

$num=mysql_numrows($result); 

mysql_close();
?>
<title>...</title>
</head>
<body>
<?
$i=0;
while ($i < $num) {
$date=mysql_result($date,$i,"date");
$news=mysql_result($news,$i,"news");
$tag=mysql_result($tag,$i,"tag"); 
?>
<sub>nsac.</sub>
<tr>
<td><sub><? echo "$date"; ?></sub></td>
<td><sub><? echo "$news"; ?></sub></td>
<td><sub><? echo "$tag"; ?></sub></td>
<?
++$i;
} 
echo "</table>";


?>
</body>
</html>

Thanks again.

Okay, where are the bold variables instantiated?

$date=mysql_result($date,$i,“date”);
$news=mysql_result($news,$i,“news”);
$tag=mysql_result($tag,$i,“tag”);

I’m sorry, I’m not following you.

Sounds like a third-party script from your last reply.

You’re using unassigned variables as the result resource. Naturally mysql_result() (as well as PHP) isn’t going to like that. Try substituting those three for the result resource from mysql_query().

Well, I’m sorry if I don’t understand your technical jargon. I did indeed write this, and this is my first attempt at PHP, so I would appreciate it if you would not accuse me of that.

no worries. I fixed it. it required $result in the mysql queries instead of $i and the other variable.

No technical jargon involved, what I was talking about is pretty basic PHP. Anyway, would you mind posting the solution, for other pplz with the same or similar problems?

Sponsor our Newsletter | Privacy Policy | Terms of Service