Jump to content

Error : Please help me :)


beansandsausages

Recommended Posts

Hey all. I have a script that has been working fine, now all of a sudden i get this error :

 

 Warning: mysql_fetch_assoc(): 5 is not a valid MySQL result resource in c:\phpdev\www\public\mem.php on line 275

 

Thhis is the block of code the error line is referring to :

 

$sql = "SELECT * FROM `news` ORDER BY id DESC LIMIT 0,7";
				$result = mysql_query($sql);
				if (!$result) {
    				echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    					exit;
				}

				if (mysql_num_rows($result) == 0) {
    				echo "<p>No news posted. </div></p>";
    					include_once("layout_all/bottom.php");
				exit;
				}

			while ($row = mysql_fetch_assoc($result)) { 
    				
			$row[message] = str_replace($word, $image, $row[message]);
			$row[message] = str_replace($color, $text, $row[message]);
			$row[message] = str_replace($effect, $status, $row[message]);


			echo "<p> {$row["date"]} : {$row["time"]} : Poster {$row["poster"]} <br /> {$row["message"]} </p> <br /> "; 
				if($info[security] >= 8 ) { echo "<p><form action=\"?action=delete\" method=\"POST\"><input type=\"hidden\" name=\"delete_id\" id=\"delete_id\" value=\"{$row['id']}\"><input type=\"submit\" value=\"Delete Post\"> </form> <form action=\"?action=edit\" method=\"POST\"><input type=\"hidden\" name=\"edit_id\" id=\"edit_id\" value=\"{$row['id']}\"><input type=\"submit\" value=\"Edit Post\"></form></p> <br />"; } 




			mysql_free_result($result);


			echo " 	</div>  ";
			}

Any ideas people thanx

Link to comment
Share on other sites

In case you did not understand, that instruction "kills" your result. Actually, as it was inside the cycle, you got the error when you tried to read the second line. That's why 'limit 1' works.

It makes sense to have it when you're finished with your result. Anyway you don't need it (php does it for you at the end of the script), unless you need much more time and/or memory after processing your result.

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.