wrathican Posted June 28, 2007 Share Posted June 28, 2007 im wondering if i can something like this. $maincontent = echo '<table width="443" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable-->' while($row = mysql_fetch_array($result, MYSQL_NUM)) { $title = $row[0]; $level = $row[1]; $location = $row[2]; $price = $row[3]; $description = $row[4]; echo '<tr> <td width="300" height="19" valign="top">'.$title.'</td> <td colspan="2" valign="top">'.$level.'</td> </tr> <tr> <td height="19" colspan="2" valign="top">'.$location.'</td> <td width="61" valign="top">'.$price.'</td> </tr> <tr> <td height="19" colspan="3" valign="top">'.$description.'<br></td> </tr>' } '</table>'; PS i know ive missed out my qury and result variables. Link to comment https://forums.phpfreaks.com/topic/57636-solved-php-functions-in-variables/ Share on other sites More sharing options...
teng84 Posted June 28, 2007 Share Posted June 28, 2007 you will get syntax error from that code Link to comment https://forums.phpfreaks.com/topic/57636-solved-php-functions-in-variables/#findComment-285321 Share on other sites More sharing options...
wrathican Posted June 28, 2007 Author Share Posted June 28, 2007 ahh, any reason why? and any idea how i can do it without returning errors? Link to comment https://forums.phpfreaks.com/topic/57636-solved-php-functions-in-variables/#findComment-285325 Share on other sites More sharing options...
teng84 Posted June 28, 2007 Share Posted June 28, 2007 } $variable.='<tr> <td width="300" height="19" valign="top">'.$title.'</td> <td colspan="2" valign="top">'.$level.'</td> </tr> <tr> <td height="19" colspan="2" valign="top">'.$location.'</td> <td width="61" valign="top">'.$price.'</td> </tr> <tr> <td height="19" colspan="3" valign="top">'.$description.'<br></td> </tr>'; } $variable.='</table>'; echo the variable the loop runs continuesly and need to see the terminator on the echo for it will nottouch the thing outside the loop unless it is done looping Link to comment https://forums.phpfreaks.com/topic/57636-solved-php-functions-in-variables/#findComment-285327 Share on other sites More sharing options...
pocobueno1388 Posted June 28, 2007 Share Posted June 28, 2007 <?php $maincontent = '<table width="443" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable-->'; //Forgot the semicolon //You also can't echo inside of a variable. echo $maincontent; //display content from variable while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $title = $row[0]; $level = $row[1]; $location = $row[2]; $price = $row[3]; $description = $row[4]; echo '<tr> <td width="300" height="19" valign="top">'.$title.'</td> <td colspan="2" valign="top">'.$level.'</td> </tr> <tr> <td height="19" colspan="2" valign="top">'.$location.'</td> <td width="61" valign="top">'.$price.'</td> </tr> <tr> <td height="19" colspan="3" valign="top">'.$description.'<br></td> </tr>'; //forgot semicolon } echo '</table>'; //forgot to echo this ?> Link to comment https://forums.phpfreaks.com/topic/57636-solved-php-functions-in-variables/#findComment-285329 Share on other sites More sharing options...
wrathican Posted June 28, 2007 Author Share Posted June 28, 2007 the thing is i want all of that inside the $maincontent variable is this not possible? Link to comment https://forums.phpfreaks.com/topic/57636-solved-php-functions-in-variables/#findComment-285335 Share on other sites More sharing options...
pocobueno1388 Posted June 28, 2007 Share Posted June 28, 2007 You want the entire code you have posted to be stored in that variable? Why don't you just make a function? What are you trying to do? Link to comment https://forums.phpfreaks.com/topic/57636-solved-php-functions-in-variables/#findComment-285338 Share on other sites More sharing options...
Caesar Posted June 28, 2007 Share Posted June 28, 2007 You can use objects to do this... <?php //Assuming you've written the class and method.... $maincontent = $settings->load_page($content); ?> OOP Link to comment https://forums.phpfreaks.com/topic/57636-solved-php-functions-in-variables/#findComment-285340 Share on other sites More sharing options...
wrathican Posted June 28, 2007 Author Share Posted June 28, 2007 i think i should have described what im trying to do from the beggining. well to start from the beggining i have a switch statement that decides wether to pull something from a database or include a file. this is included in the parent file. im working on the file to be included. this particular file pulls data from the databse in the while statement and displays all the entries. in the parent page the place where i want the data to show echo's a variable($maincontent). what i want is the while statement showing all the entries in that variable so that when i echo it in the parent it shows everythinng from the DB. i hope that didnt confuse you too much. Link to comment https://forums.phpfreaks.com/topic/57636-solved-php-functions-in-variables/#findComment-285345 Share on other sites More sharing options...
wrathican Posted June 28, 2007 Author Share Posted June 28, 2007 im not familiar with these 'objects' you speak of Link to comment https://forums.phpfreaks.com/topic/57636-solved-php-functions-in-variables/#findComment-285347 Share on other sites More sharing options...
teng84 Posted June 28, 2007 Share Posted June 28, 2007 $variable.='<tr> <td width="300" height="19" valign="top">'.$title.'</td> <td colspan="2" valign="top">'.$level.'</td> </tr> <tr> <td height="19" colspan="2" valign="top">'.$location.'</td> <td width="61" valign="top">'.$price.'</td> </tr> <tr> <td height="19" colspan="3" valign="top">'.$description.' </td> </tr>'; } $variable.='</table>'; i think this is what your are talking about or tell me y im wrong Link to comment https://forums.phpfreaks.com/topic/57636-solved-php-functions-in-variables/#findComment-285350 Share on other sites More sharing options...
Caesar Posted June 28, 2007 Share Posted June 28, 2007 im not familiar with these 'objects' you speak of Object Oriented Programming Once you've written your class and method (And you pass a value to the method in the object that will determine which content is displayed) and initiated your objected...you can pull up content by simply doing... <?php $settings = new class; $settings->load_page($content); ?> Link to comment https://forums.phpfreaks.com/topic/57636-solved-php-functions-in-variables/#findComment-285356 Share on other sites More sharing options...
pocobueno1388 Posted June 28, 2007 Share Posted June 28, 2007 All you need to do is make that code into a function, then you can call it from your other page. Link to comment https://forums.phpfreaks.com/topic/57636-solved-php-functions-in-variables/#findComment-285359 Share on other sites More sharing options...
Caesar Posted June 28, 2007 Share Posted June 28, 2007 All you need to do is make that code into a function, then you can call it from your other page. That too. Though I prefer using classes/methods. Link to comment https://forums.phpfreaks.com/topic/57636-solved-php-functions-in-variables/#findComment-285360 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.