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 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. 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)){ ?> 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. 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 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 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)) { ?> 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? 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 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. 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 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. 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 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. 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 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. 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 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` 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 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? Link to comment https://forums.phpfreaks.com/topic/260611-php-errer/#findComment-1335678 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.