raptor30506090 Posted April 9, 2012 Share Posted April 9, 2012 Hi Can any one help please iv have this error Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/80/5047580/html/helen/sub.php on line from this $query = mysql_query("SELECT * FROM $table"); Thanks Quote Link to comment https://forums.phpfreaks.com/topic/260611-php-errer/ Share on other sites More sharing options...
AyKay47 Posted April 9, 2012 Share Posted April 9, 2012 What does $table hold? There is an error in the SQL most likely. Post all of the relevant code, including the mysql_Fetch_assoc() call. Quote Link to comment https://forums.phpfreaks.com/topic/260611-php-errer/#findComment-1335635 Share on other sites More sharing options...
raptor30506090 Posted April 9, 2012 Author Share Posted April 9, 2012 $query = mysql_query("SELECT * FROM sub_nav WHERE subNav_ID=" . mysql_real_escape_string((int)$id)); $row = mysql_fetch_assoc($query); $table = $row['subNavName']; // ******************************* This if statment controls the content ************************ if($row['show_hide'] == 1){ $query = mysql_query("SELECT * FROM ('$table')"); while($row = mysql_fetch_assoc($query)){ ?> Quote Link to comment https://forums.phpfreaks.com/topic/260611-php-errer/#findComment-1335636 Share on other sites More sharing options...
AyKay47 Posted April 9, 2012 Share Posted April 9, 2012 $query = mysql_query("SELECT * FROM ('$table')"); this is not what you had in your OP, and makes a big difference, as it's invalid syntax. The way you wrote it in your OP is how it should be written, as long as $table is just a table name. Quote Link to comment https://forums.phpfreaks.com/topic/260611-php-errer/#findComment-1335638 Share on other sites More sharing options...
raptor30506090 Posted April 9, 2012 Author Share Posted April 9, 2012 no i was just trying diffrent things out Quote Link to comment https://forums.phpfreaks.com/topic/260611-php-errer/#findComment-1335640 Share on other sites More sharing options...
raptor30506090 Posted April 9, 2012 Author Share Posted April 9, 2012 no its holding a database name Quote Link to comment https://forums.phpfreaks.com/topic/260611-php-errer/#findComment-1335642 Share on other sites More sharing options...
AyKay47 Posted April 9, 2012 Share Posted April 9, 2012 output the SQL to see what it looks like: $query = mysql_query("SELECT * FROM sub_nav WHERE subNav_ID=" . mysql_real_escape_string((int)$id)); $row = mysql_fetch_assoc($query); $table = $row['subNavName']; if($row['show_hide'] == 1) { $sql = "SELECT * FROM $table"; $query = mysql_query($sql) or die(mysql_error() . '<br />' . $sql); while($row = mysql_fetch_assoc($query)) { ?> Quote Link to comment https://forums.phpfreaks.com/topic/260611-php-errer/#findComment-1335643 Share on other sites More sharing options...
AyKay47 Posted April 9, 2012 Share Posted April 9, 2012 no its holding a database name oh, that's a different ballgame. 1. don't name the variable $table if it's not a table. 2. You can't query a db like that, so this depends on what you want to do? Quote Link to comment https://forums.phpfreaks.com/topic/260611-php-errer/#findComment-1335644 Share on other sites More sharing options...
raptor30506090 Posted April 9, 2012 Author Share Posted April 9, 2012 im getting a syntex error from $sql = SELECT * FROM $table; Im trying to select a new table from a drop down menu works fine localhost Quote Link to comment https://forums.phpfreaks.com/topic/260611-php-errer/#findComment-1335646 Share on other sites More sharing options...
AyKay47 Posted April 9, 2012 Share Posted April 9, 2012 then use the script I posted in reply #6 and post the results. Quote Link to comment https://forums.phpfreaks.com/topic/260611-php-errer/#findComment-1335654 Share on other sites More sharing options...
raptor30506090 Posted April 9, 2012 Author Share Posted April 9, 2012 yes i tryed that but got the error above Quote Link to comment https://forums.phpfreaks.com/topic/260611-php-errer/#findComment-1335655 Share on other sites More sharing options...
AyKay47 Posted April 9, 2012 Share Posted April 9, 2012 post EXACTLY what you receive. It will post an error along the the SQL. Quote Link to comment https://forums.phpfreaks.com/topic/260611-php-errer/#findComment-1335657 Share on other sites More sharing options...
raptor30506090 Posted April 9, 2012 Author Share Posted April 9, 2012 ok error gone now sorry about that it says that is no table of that name when there is localhost is fine only when i upload it i have the problem Quote Link to comment https://forums.phpfreaks.com/topic/260611-php-errer/#findComment-1335661 Share on other sites More sharing options...
AyKay47 Posted April 9, 2012 Share Posted April 9, 2012 is the database structure the same as localhost? As I stated before, if you are trying to use a select statement on a db name, it won't work, it has to be a table name. Quote Link to comment https://forums.phpfreaks.com/topic/260611-php-errer/#findComment-1335662 Share on other sites More sharing options...
raptor30506090 Posted April 9, 2012 Author Share Posted April 9, 2012 yes iv just imported it in Quote Link to comment https://forums.phpfreaks.com/topic/260611-php-errer/#findComment-1335663 Share on other sites More sharing options...
AyKay47 Posted April 9, 2012 Share Posted April 9, 2012 well check the tables, because the one you are trying to query doesn't exist on the server. Quote Link to comment https://forums.phpfreaks.com/topic/260611-php-errer/#findComment-1335664 Share on other sites More sharing options...
raptor30506090 Posted April 9, 2012 Author Share Posted April 9, 2012 it is a table the error is Table 'helenowen.Textiles' doesn't exist SELECT * FROM Textiles Quote Link to comment https://forums.phpfreaks.com/topic/260611-php-errer/#findComment-1335670 Share on other sites More sharing options...
AyKay47 Posted April 9, 2012 Share Posted April 9, 2012 If you are using *nix, table and db names are case-sensitive, so watch out for that. That is if you are sure that you have a table `Textiles` in the db `helenowen` Quote Link to comment https://forums.phpfreaks.com/topic/260611-php-errer/#findComment-1335671 Share on other sites More sharing options...
raptor30506090 Posted April 9, 2012 Author Share Posted April 9, 2012 Thank you so much for your help it works Quote Link to comment https://forums.phpfreaks.com/topic/260611-php-errer/#findComment-1335677 Share on other sites More sharing options...
AyKay47 Posted April 9, 2012 Share Posted April 9, 2012 Thank you so much for your help it works Great, what was wrong? Quote Link to comment https://forums.phpfreaks.com/topic/260611-php-errer/#findComment-1335678 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.