getting errors .... mysql_fetch_array ....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
HormonX
Forum Commoner
Posts: 50
Joined: Tue Dec 10, 2002 7:43 pm
Location: Toronto

getting errors .... mysql_fetch_array ....

Post by HormonX »

this the code i used many times before and it workd just fine .. not it doesn't .... can anyone find something wrong with this ? :)

The code works great when i initially log in .. i shows the number of messages for tthe user .. but as soon i click on a link to display messages i get this error .....

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/domain/public_html/portal/sindex.php on line 56

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/domain/public_html/portal/sindex.php on line 59

Code: Select all

<?
	  		$query = "SELECT * FROM table1 WHERE username='user'";
			$result = mysql_query($query, $link);
			
			while($row = mysql_fetch_array($result))
			&#123;
			
			$uid = $row&#1111;'uid'];
					
			$count = mysql_query("SELECT COUNT(*) FROM msg_system WHERE msg_to='$uid' AND msg_viewed='0'");
			$counter=mysql_result($count,0);
			
		  ?>
		  <td align="right" height="20"><a href="?page=msg&uid=<? echo $uid; ?>">your mail&#1111;<? echo $counter; ?>]</a> 
		  <?
		  &#125;
thank you.

Greg
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

place the usual mysql debugging stuffs:

Code: Select all

mysql_query(...) or die(mysql_error());
thegreatone2176
Forum Contributor
Posts: 102
Joined: Sun Jul 11, 2004 1:27 pm

Post by thegreatone2176 »

$query = "SELECT * FROM table1 WHERE username='user'";

add a $ in 'user'

and its always good a idea to put or die(mysql_error()) after $result

also the code would like alot cleaner if you just echoed all the html out instead of ?> <? everywhere
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

It'd be even cleaner if he built output variables then used them below, essentially putting all his html together..

theres tons of ways to do everything, I think his way is fine ;)
Post Reply