Jump to content

Yet another mysql_fetch_array error


jkewlo

Recommended Posts

i keep getting

 

 

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\Neanix\index.php on line 338

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\Neanix\index.php on line 344

This is the code

 

Note: i have also taken out

$rows=mysql_fetch_array($result);

and left the

while($rows=mysql_fetch_array($result)){

and vise verse. still no luck

<?php
	$sql=mysql_query("SELECT * FROM members WHERE Broadcasting=1" )or die(mysql_error());
	$result=mysql_query($sql);
	$rows=mysql_fetch_array($result); //error here line 338
	$showname = $rows['ShowName'];
	$view = $rows['Views'];
	$path = $rows['Path'];
	$username = $rows['Username'];

	while($rows=mysql_fetch_array($result)){ // error here line 344

	if($broadcast = '1'){
	echo "Username: ". $username ."<br>";
	echo "ShowName: ". $showname ." | Views: ". $view ."";
	echo "<img src=". $path ." border=0 width=100 height=100 >"; 
	} else {
	echo "NO SHOWS!"; 
	}
	}
	?>

Link to comment
https://forums.phpfreaks.com/topic/118522-yet-another-mysql_fetch_array-error/
Share on other sites

You call mysql_query() twice, except you do it on the result set the second time...Try:

 

<?php
	$result=mysql_query("SELECT * FROM members WHERE Broadcasting=1" )or die(mysql_error());
	$rows=mysql_fetch_array($result); //error here line 338
	$showname = $rows['ShowName'];
	$view = $rows['Views'];
	$path = $rows['Path'];
	$username = $rows['Username'];

	while($rows=mysql_fetch_array($result)){ // error here line 344

	if($broadcast = '1'){
	echo "Username: ". $username ."<br>";
	echo "ShowName: ". $showname ." | Views: ". $view ."";
	echo "<img src=". $path ." border=0 width=100 height=100 >"; 
	} else {
	echo "NO SHOWS!"; 
	}
	}
	?>

Wow, your code was pretty messed up.  I fixed it:

 

<?php
	$result=mysql_query("SELECT * FROM members WHERE Broadcasting=1" )or die(mysql_error());
	$showname = $rows['ShowName'];
	$view = $rows['Views'];
	$path = $rows['Path'];
	$username = $rows['Username'];

	while($rows=mysql_fetch_array($result)){
	$showname = $rows['ShowName'];
	$view = $rows['Views'];
	$path = $rows['Path'];
	$username = $rows['Username'];
	if($broadcast = '1'){
	echo "Username: ". $username ."<br>";
	echo "ShowName: ". $showname ." | Views: ". $view ."";
	echo "<img src=". $path ." border=0 width=100 height=100 >"; 
	} else {
	echo "NO SHOWS!"; 
	}
	}
?>

 

And you should honestly try to indent your code more so it's readable.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.