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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.