Jump to content

mysql_fetch_array()


Marsha

Recommended Posts

Heya, I am making a code that shows users that are on a database with a postid, for each post on my forum, this will run and any username with the current postid will be shown.

 

Problem is, I get an error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/SITENAME/public_html/SITENAME/forums/likeusers.php on line 9

 

Heres the code:

 

<font size="1">

<?

$postid=$_GET['postid'];

$view=$_GET['view'];

mysql_connect("localhost", "USERNAME", "PASSWORD") or die(mysql_error());

mysql_select_db("DATABASE") or die(mysql_error());

 

$result = mysql_query("SELECT username FROM data WHERE postid=$postid");

$rows = mysql_fetch_array($result);                                                                              < -- LINE 9

 

$query_multiplecheck = "SELECT username FROM data WHERE postid='$postid'";

$multiplecheck = mysql_query($query_multiplecheck) or die(mysql_error());

$row_multiplecheck = mysql_fetch_assoc($multiplecheck);

$totalRows_multiplecheck = mysql_num_rows($multiplecheck);

 

if($view == "1") {

 

 

 

} else {

if ( $totalRows_multiplecheck > 0 ) { echo $rows[username]; } else { }

if ( $totalRows_multiplecheck == "1" ) { echo ' likes this post.'; } else { }

if ( $totalRows_multiplecheck == "2" ) { echo ' and ', $totalRows_multiplecheck - "1", ' other like this post. <a href="likeusers.php?=', $postid, '&view=1">View Likes</a>'; } else { }

if ( $totalRows_multiplecheck > 2 ) { echo ' and ', $totalRows_multiplecheck - "1", ' others like this post. <a href="likeusers.php?=', $postid, '&view=1">View Likes</a>'; } else { }

}

 

 

 

 

?>

</font>

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/223059-mysql_fetch_array/
Share on other sites

No. Remove the query string from the query execution, and store it in a variable. Then use the variable when executing the query. Doing so makes debugging and error handling much easier.

$query = "SELECT username FROM data WHERE postid=$postid";
mysql_query($query);
echo $query;

Link to comment
https://forums.phpfreaks.com/topic/223059-mysql_fetch_array/#findComment-1153266
Share on other sites

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.