PHP Parsing and text

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rilus
Forum Newbie
Posts: 3
Joined: Mon Jul 07, 2003 7:30 pm

PHP Parsing and text

Post by rilus »

I'm not sure this question has been asked before, but since I wasn't even sure how to look for it, I couldn't find anything about it on the forums.

First of all, I am a 2-day PHP newbie.

Now, I am trying to retrieve some info from a database, then I want to include whatever I retrieved into a php file.

Over simplified example:

name field contains:

Code: Select all

<?php
     print "Here's the info";
?>
Here's the php file which will be retrieving the info

Code: Select all

<?php
     $info=mysql_query("select name from table");
     $name=mysql_fetch_row($info);

     //the next part is what confuses me...
     //if I use echo or print all it does is output:
     //<?php
     //     print "Here's the info";
     //?>
?>
I need to know what to do so it will actually execute the code in the database field and not just print it.

It's kind of hard for me articulate this question, but I hope someone can give me some pointers on this.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

first off you don't need to re-open php. that might be part of the issue. the other part is you're giving a string without a variable

Code: Select all

<?php 
     $info=mysql_query("select name from table"); 
     $name=mysql_fetch_row($info); 

     //the next part is what confuses me... 
     //if I use echo or print all it does is output: 
     echo "Here's the $info"; 
?>
this still wont do what you want. however, it will now print whatever the return of $info was.

http://us3.php.net/manual/en/control-st ... oreach.php

use that link. it will show you a function called "foreach"

this function strikes me as the way to accomplish what i think you want to accomplish.

sorry if you expected something functional in response, but i know that personally it wouldn't teach me much, and i want you to learn why your problem is occuring and how to fix it so you wont encounter it again
rilus
Forum Newbie
Posts: 3
Joined: Mon Jul 07, 2003 7:30 pm

Post by rilus »

well...
what I want is for php to not simply ouput the text straight off from the database, as is... I want it to include it or somehow execute it as part of the php file that's retrieving the data...
macewan
Forum Commoner
Posts: 97
Joined: Mon Jul 07, 2003 8:27 pm

Post by macewan »

while ($row = mysql_fetch_array($sql_result_info)){
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

http://us2.php.net/manual/en/control-st ... .while.php

what else do you want? just to show as you retreive it? or is this a debug as you put together what you're really doing?

if the latter, then use the foreach i have suggeasted, then you can modify that at each debug step
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

In your example $name is an array with a key=>value pair: 0=>'whatever is in the name col'.

If that is code, you would use eval() to execute it.

However, rather than storing php in a database, it's more common to include code from a script file, ie:

include('path/to/script.php'');
rilus
Forum Newbie
Posts: 3
Joined: Mon Jul 07, 2003 7:30 pm

Post by rilus »

Thank you so much, McGruff! That answered my question... I needed the eval() function... And yea, I do use includes, but I need this code to be more dynamic.

Thanks again
Post Reply