Help with news script


#1

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.


#2

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.


#3

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.


#4

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”);


#5

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


#6

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().


#7

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.


#8

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


#9

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?