Jump to content

[SOLVED] php functions in variables


wrathican

Recommended Posts

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

}

$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

 

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

?>

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.

$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

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);

?>

Archived

This topic is now archived and is closed to further replies.

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