Error

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL r

Page 1 of 1

4 Replies - 594 Views - Last Post: 05 June 2010 - 09:28 PM Rate Topic: -----

#1 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Error

Posted 05 June 2010 - 05:41 PM

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/a6992714/public_html/test/index.php on line 7



That is the error I get. The code starts at line 7.
while($row = mysql_fetch_array($sql)){ 
	$id = $row["id"];
	$post_author = $row["post_author"];
	$post_author_id = $row["post_author_id"];
	$thread_author = $row["thread_author"];
	$original_thread_id = $row["original_thread_id"];
	$date_time = $row["date_time"];
    $date_time = strftime("%a %b %d, %Y %I:%M:%S %p", strtotime($date_time));
	$type = $row["type"];
	$view_count = $row["view_count"]; 
	$category = $row["category"];
	$category = substr('' . $category . '', 0, 15);  
	$cat_ref_num = $row["cat_ref_num"];	
	$title = stripslashes($row["title"]);
	$title = htmlentities($title);
	$title = substr('' . $title . '', 0, 48);  

This post has been edited by VB.Terry: 05 June 2010 - 05:42 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Error

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6036
  • View blog
  • Posts: 23,421
  • Joined: 23-August 08

Re: Error

Posted 05 June 2010 - 05:44 PM

Do you know how often we get this question??? Did you try searching the forum for your error?
Was This Post Helpful? 1
  • +
  • -

#3 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10376
  • View blog
  • Posts: 38,415
  • Joined: 27-December 08

Re: Error

Posted 05 June 2010 - 05:46 PM

Please respect rule #4 of this forum. "Error" is not a descriptive title in a forum dedicated to helping people with their coding problems.

Quote

while($row = mysql_fetch_array($sql)){

Your mysql_query() invocation probably returned a null result set, so $sql isn't a valid mysql resource.

Also, while this may be line #7 for you, it's line #1 on the segment you posted. In the future, please point out the offending line/code instead of line number. :)
Was This Post Helpful? 0
  • +
  • -

#4 webpeater  Icon User is offline

  • D.I.C Head

Reputation: 26
  • View blog
  • Posts: 95
  • Joined: 04-June 10

Re: Error

Posted 05 June 2010 - 05:56 PM

View PostVB.Terry, on 06 June 2010 - 12:41 AM, said:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/a6992714/public_html/test/index.php on line 7



That is the error I get. The code starts at line 7.
while($row = mysql_fetch_array($sql)){ 
	$id = $row["id"];
	$post_author = $row["post_author"];
	$post_author_id = $row["post_author_id"];
	$thread_author = $row["thread_author"];
	$original_thread_id = $row["original_thread_id"];
	$date_time = $row["date_time"];
    $date_time = strftime("%a %b %d, %Y %I:%M:%S %p", strtotime($date_time));
	$type = $row["type"];
	$view_count = $row["view_count"]; 
	$category = $row["category"];
	$category = substr('' . $category . '', 0, 15);  
	$cat_ref_num = $row["cat_ref_num"];	
	$title = stripslashes($row["title"]);
	$title = htmlentities($title);
	$title = substr('' . $title . '', 0, 48);  


As said before in other of your topics.
It is useless to give your variables another name. You could use $row['blabla'] directly.

This post has been edited by webpeater: 05 June 2010 - 05:57 PM

Was This Post Helpful? 0
  • +
  • -

#5 ShaneK  Icon User is offline

  • require_once("brain.php"); //Fatal error :/
  • member icon

Reputation: 240
  • View blog
  • Posts: 1,224
  • Joined: 10-May 09

Re: Error

Posted 05 June 2010 - 09:28 PM

View Postwebpeater, on 05 June 2010 - 05:56 PM, said:

As said before in other of your topics.
It is useless to give your variables another name. You could use $row['blabla'] directly.


I disagree with this. Most people like to remember a variable's name and not the element's key in the array... I'd much rather address a variable by $name than $row['name'], especially because code completion tools can't possibly predict array keys.

Yours,
Shane~

This post has been edited by ShaneK: 05 June 2010 - 09:40 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1