jboku Posted November 17, 2009 Share Posted November 17, 2009 So I have a problem I can't figure out.... If I go to my database.php file it runs fine and grabs all the data. If I call it from a file and try and print / echo it out, it shows the source and not the output. What am I doing wrong? database.php: <?php include "./connect_test.php"; include "./functions_test.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 )."%'"; //$extra_styles_sql=" OR STYLE_NUM LIKE '%"%' OR STYLE_NUM LIKE '%%'"; $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; ?> I call it in my index.php: <?php include "./connect_test.php"; include "./functions_test.php"; ?> <?php $database=file_get_contents("./database_test.php"); $style_numbers=explode("\n",$database); If I run index.php I get this error: 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 )."%'"; , //$extra_styles_sql=" OR' at line 4 If I print it by doing echo $database it just echos the source and not the output. Can someone please help me? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/181906-file_get_contents/ Share on other sites More sharing options...
Alex Posted November 17, 2009 Share Posted November 17, 2009 Instead of printing the data in database.php just store the result you want in a variable, then on index.php include database.php and echo the variable you used to store it. Quote Link to comment https://forums.phpfreaks.com/topic/181906-file_get_contents/#findComment-959427 Share on other sites More sharing options...
jboku Posted November 17, 2009 Author Share Posted November 17, 2009 Instead of printing the data in database.php just store the result you want in a variable, then on index.php include database.php and echo the variable you used to store it. So like in database.php I have it written to $code. if I called that on index.php would that work? How would I call it over to index.php? Quote Link to comment https://forums.phpfreaks.com/topic/181906-file_get_contents/#findComment-959451 Share on other sites More sharing options...
Alex Posted November 17, 2009 Share Posted November 17, 2009 Yes it'll work as long as you're including the file before you're trying to use the variable. You would use it the same as any other variable. Quote Link to comment https://forums.phpfreaks.com/topic/181906-file_get_contents/#findComment-959455 Share on other sites More sharing options...
jboku Posted November 17, 2009 Author Share Posted November 17, 2009 Yes it'll work as long as you're including the file before you're trying to use the variable. You would use it the same as any other variable. I did echo $code but I get the same error I got previously: 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 )."%'"; , //$extra_styles_sql=" OR' at line 4 Quote Link to comment https://forums.phpfreaks.com/topic/181906-file_get_contents/#findComment-959521 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.