Jump to content

sql problem with $wpdb class


JamesThePanda

Recommended Posts

Hi Guys

Im trying to learn how to make wordpress plugins. This is the error Im getting.

 

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\wamp\www\wordpress\wp-content\plugins\myplugin\myplugin.php  on line 40

 

This is the offending piece of code have I done everything right here?

 

$wpresults = $wpdb->get_var("SELECT * FROM ".$wpdb->prefix."wp_users WHERE post_id = 1");
  
  while ($row = mysql_fetch_array($wpresults)){;
  
    echo '<table><tr><td width="160">';
echo $wpresults ;
echo '</td></tr></table>';
  }
  

 

I tried using query and get results but nothing seems to do it  :'(

 

Thanks

 

James

Link to comment
https://forums.phpfreaks.com/topic/207746-sql-problem-with-wpdb-class/
Share on other sites

What does your get_var() method return. Currently it is not returning anything and is why you're receiving the error you're getting. mysql_fetch_array is expecting a result resource from mysql_query, this result resource should be returned from your get_var() method, provided your query executed without any errors.

 

Can you post the code to your get_var() method.

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.