Jump to content

file_get_contents


jboku

Recommended Posts

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.