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. Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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 ?> Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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); ?> Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.