Jump to content

Sql Statement Inside PHP Variable


aeafisme23

Recommended Posts

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
Share on other sites

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
Share on other sites

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
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.