jboku Posted November 16, 2009 Share Posted November 16, 2009 Hello everyone, I am having a problem and am kind of new to PHP but not to coding. I have 4 files I am using, index.php, functions.php, connect.php, and database.php. When I go to index.php I get the following error: Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /var/www/html/charm/functions.php on line 9 Below is the code in Functions.php: <?php //FUNCTION: GET TABLE DATA function get_table_data($database_connection,$sql_query){ //TABLE DATA //get all of the data from the table and record it to an array with the keys recording the primary key and the field attributes - field name|primary key value|field type|field length eg. title|13|text|128 $all_data_array=array(); $query_result=mysql_query($sql_query,$database_connection); while($query_row=mysql_fetch_row($query_result)){ for($d=0;$d<sizeof($query_row);$d++){ $key=mysql_field_table($query_result,$d).".".mysql_field_name($query_result,$d); //define the array if(!isset($all_data_array[$key])){ $all_data_array[$key]=array(); } //add the item's attribute to the attributes array $all_data_array[$key][sizeof($all_data_array[$key])]=$query_row[$d]; } } return $all_data_array; } ?> Line 9 is while($query_row=mysql_fetch_row($query_result)){ Can I get some help please? I don't know why it's getting the error. It happened after a friend copied the files over to a new directory. Quote Link to comment https://forums.phpfreaks.com/topic/181752-mysql_fetch_row-supplied-argument-is-not-valid/ Share on other sites More sharing options...
premiso Posted November 16, 2009 Share Posted November 16, 2009 Chances are you have an error in your sql query. $query_result=mysql_query($sql_query,$database_connection) or die("Error: " . mysql_error()); Add that in there and see what error gets spit out (if any). Quote Link to comment https://forums.phpfreaks.com/topic/181752-mysql_fetch_row-supplied-argument-is-not-valid/#findComment-958584 Share on other sites More sharing options...
jboku Posted November 16, 2009 Author Share Posted November 16, 2009 Chances are you have an error in your sql query. $query_result=mysql_query($sql_query,$database_connection) or die("Error: " . mysql_error()); Add that in there and see what error gets spit out (if any). Thanks for the speedy response. I get the following error message: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\n", "%' OR STYLE_NUM LIKE '%", $extra_styles)."%'"; , $custom_order_string="Cha' at line 4 That is actually some code found in my database.php file: <?php include "./connect.php"; include "./functions.php"; ?> <?php //Pull in some additional styles $extra_styles=file_get_contents("./extra_styles.txt"); $extra_styles_sql=" OR STYLE_NUM LIKE '%".str_replace("\n", "%' OR STYLE_NUM LIKE '%", $extra_styles)."%'"; $custom_order_string="Charms & More,Necklaces,Bracelets"; $sql= 'SELECT webstyle.STYLE_NUM, webcategory.DESCRIPTION, IF( FIND_IN_SET( webcategory.DESCRIPTION, "'.$custom_order_string.'" )!=0, FIND_IN_SET( webcategory.DESCRIPTION, "'.$custom_order_string.'" ), 99 ) AS custom_order FROM webstyle JOIN webcategory ON webstyle.CATEGORY=webcategory.CATEGORY_CODE WHERE (webstyle.WEB_SUB_CATEGORY LIKE "Charm>%" OR webstyle.WEB_SUB_CATEGORY LIKE "Spacers>%" OR webstyle.WEB_SUB_CATEGORY LIKE "Base>%" '.$extra_styles_sql.' OR webstyle.COLLECTION="BR ABC\'S" ) AND SUBSTRING(webstyle.VIEW_ORDER_RETAIL, 1, 1) = "Y" ORDER BY custom_order, WEB_SUB_CATEGORY DESC '; $style_numbers=get_table_data( $bright1_shopping_connection, $sql ); //Because the ordering involves a regular expression, it's more efficient to loop through the list of styles /* print "<pre>"; print_r($style_numbers); print "</pre>"; */ $code=implode("\n", $style_numbers["webstyle.STYLE_NUM"] ); print $code; ?> Quote Link to comment https://forums.phpfreaks.com/topic/181752-mysql_fetch_row-supplied-argument-is-not-valid/#findComment-958595 Share on other sites More sharing options...
jboku Posted November 16, 2009 Author Share Posted November 16, 2009 Anyone? :/ Quote Link to comment https://forums.phpfreaks.com/topic/181752-mysql_fetch_row-supplied-argument-is-not-valid/#findComment-958741 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.