dubfoundry Posted July 31, 2009 Share Posted July 31, 2009 I'm working with a simple straight forward code and keep getting this error message mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource here is the code $query = "SELECT * FROM tbl_gallery g, tbl_subgallery s WHERE s.gal_id=g.gal_id ORDER BY s.gal_id"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { echo '<pre>' . print_r($row, true) .' </pre>'; } the query works fine in php admin but i keep getting this message... thanx for your help Link to comment https://forums.phpfreaks.com/topic/168309-solved-mysql_fetch_assoc-supplied-argument-error/ Share on other sites More sharing options...
wildteen88 Posted July 31, 2009 Share Posted July 31, 2009 This error usually means your query is failing. To find out why change this line $result = mysql_query($query); to $result = mysql_query($query) or die(mysql_error()); What is the error? Link to comment https://forums.phpfreaks.com/topic/168309-solved-mysql_fetch_assoc-supplied-argument-error/#findComment-887767 Share on other sites More sharing options...
TeNDoLLA Posted July 31, 2009 Share Posted July 31, 2009 Have you connected to mysql via php before running query? Maybe it woul dhelp also if you gave the link identifier to as second parameter to mysql_query. Link to comment https://forums.phpfreaks.com/topic/168309-solved-mysql_fetch_assoc-supplied-argument-error/#findComment-887769 Share on other sites More sharing options...
dubfoundry Posted July 31, 2009 Author Share Posted July 31, 2009 This error usually means your query is failing. To find out why change this line $result = mysql_query($query); to $result = mysql_query($query) or die(mysql_error()); What is the error? OK it said no database selected ..i forgot that line...its now working thank fellows.. hey if i have any other problem with it ill let you know.... appreciate it. Link to comment https://forums.phpfreaks.com/topic/168309-solved-mysql_fetch_assoc-supplied-argument-error/#findComment-887837 Share on other sites More sharing options...
dubfoundry Posted July 31, 2009 Author Share Posted July 31, 2009 ok it works but just with one problem it only out puts a single row under each category it doesnt do the rest...here is the final code i have...i cant figure out why it would only print one row... mysql_select_db($database, $makeconnection); $query = "SELECT * FROM tbl_gallery g, tbl_subgallery s WHERE s.gal_id=g.gal_id ORDER BY s.gal_id"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_assoc($result); $prev_section = null; $sectionHeading = false; //echo '<table border="1" cellpadding="5" cellspacing="2">'; do{ if($prev_section != $row['gal_name']) { $prev_section = $row['gal_name']; $sectionHeading = false; } if(!$sectionHeading) { echo '<h1>' . $row['gal_name'] . '</h1>'; $sectionHeading = true; } else { echo $row['subgal_name'].'<p> </p'; } }while($row = mysql_fetch_assoc($result)); } Link to comment https://forums.phpfreaks.com/topic/168309-solved-mysql_fetch_assoc-supplied-argument-error/#findComment-888010 Share on other sites More sharing options...
lonewolf217 Posted July 31, 2009 Share Posted July 31, 2009 is this the code for the entire page, because i think that last bracket is not needed ? Link to comment https://forums.phpfreaks.com/topic/168309-solved-mysql_fetch_assoc-supplied-argument-error/#findComment-888011 Share on other sites More sharing options...
dubfoundry Posted August 2, 2009 Author Share Posted August 2, 2009 no there is a if statement before the code if(isset($_GET['upload'])&& !isset($_GET['edit_gal'])){ require_once('upload.php'); }elseif(isset($_GET['edit_gal'])){ Link to comment https://forums.phpfreaks.com/topic/168309-solved-mysql_fetch_assoc-supplied-argument-error/#findComment-888900 Share on other sites More sharing options...
dubfoundry Posted August 3, 2009 Author Share Posted August 3, 2009 So any thaughts why this is not printing the complete sublist guys??? help Link to comment https://forums.phpfreaks.com/topic/168309-solved-mysql_fetch_assoc-supplied-argument-error/#findComment-889885 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.