aeafisme23 Posted November 10, 2009 Share Posted November 10, 2009 I have about 50 pages that all use variables to display images and text. I did a bad job at coding in the first place and the project is too big to open all 50 pages and insert each statement in when I can use the variable that is there. $eventinfo = "This is just some random text and i want to include some info from my database inside this content // the info below I am trying to contain with in the variable $eventinfo $connect = mysql_pconnect('localhost", "xxxxx", "xxxxx") or die(mysql_error()); mysql_select_db("xxxxx", $connect) or die(mysql_error()); $sql_address = mysql_query("SELECT MAX(ID) as ID, Date, Time FROM events WHERE DMA='$Station'") or die (mysql_error()); $row_count = 0; while($results = mysql_fetch_array($sql_address)) { <tr> <td><p>' .$results['Date'] . '</p></td> </tr> <tr> <td><p>' .$results['Time'] . '</p></td> </tr>'; } mysql_free_result($sql_address); mysql_close($connect); this is more content below the sql statement and with in the variable eventinfo."; I have also tried to call an include statement of the sql inside $eventinfo but it's the same result. I understand the logic of why it will not work, I am declaring a variable and then putting variables inside but when i do that the semi colons are ending the statement early. I know there are other ways to do this besides putting it inside a variable but as of right now I am banking that this can be done some how to call the sql statement with in the variable. Any ideas? Link to comment https://forums.phpfreaks.com/topic/181021-sql-statement-inside-php-variable/ Share on other sites More sharing options...
iversonm Posted November 10, 2009 Share Posted November 10, 2009 First line is not closed with a " your mysql_pconnect('localhost", "xxxxx", "xxxxx") was never closed so it should be something like this $connect = mysql_pconnect("localhost", "xxxxx", "xxxxx"); your local host started with a ' and ended with a ". thats a bad sitatuation and was missing your ; Here this looks a little more fixed up. $eventinfo = "This is just some random text and i want to include some info from my database inside this content "; $connect = mysql_pconnect("localhost", "xxxxx", "xxxxx"); or die(mysql_error()); mysql_select_db("xxxxx", $connect) or die(mysql_error()); $sql_address = mysql_query("SELECT ID, Date, Time FROM events WHERE DMA='$Station'") or die (mysql_error()); $row_count = 0; while($results = mysql_fetch_array($sql_address)){ echo '<tr><td><p>' .$results['Date'] . '</p></td></tr>'; echo '<tr><td><p>' .$results['Time'] . '</p></td></tr>'; } mysql_free_result($sql_address); mysql_close($connect); To me it looks like your missing alot of ', ", and ; that will cause some major errors Link to comment https://forums.phpfreaks.com/topic/181021-sql-statement-inside-php-variable/#findComment-955089 Share on other sites More sharing options...
aeafisme23 Posted November 10, 2009 Author Share Posted November 10, 2009 Thanks for the info on i know what are the major issues of the '" and ;'s but I do not think this is nested inside the variable so when I call the variable $eventinfo it will never execute the mysql code. Any ideas? Thanks Link to comment https://forums.phpfreaks.com/topic/181021-sql-statement-inside-php-variable/#findComment-955129 Share on other sites More sharing options...
iversonm Posted November 10, 2009 Share Posted November 10, 2009 at the beggining of your script add this error_reporting(E_ALL) and let me know if any errors come up Link to comment https://forums.phpfreaks.com/topic/181021-sql-statement-inside-php-variable/#findComment-955132 Share on other sites More sharing options...
aeafisme23 Posted November 10, 2009 Author Share Posted November 10, 2009 Maybe this is a better example of what I am trying to do : $eventinfo = "'include("eventinclude.php");' <p class=\"left-align\">Hello this is text.</p>"; Of course I can not get the above to work and tried interchanging the " and the 's many times to no avail. With in the variable I want to execute an include statement along with text. UPDATE: $eventinfo = include("eventinclude.php"); I tried doing that and it is calling the include but it is executing right away and it is not fitting with in the html and where I want it to go it says 1 , just the number one. Is 1 an error code for something? Link to comment https://forums.phpfreaks.com/topic/181021-sql-statement-inside-php-variable/#findComment-955153 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.