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

 

Link to comment
Share on other sites

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

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

</td>

        </tr>';

}

$variable.='</table>';

 

i think this is what your are talking about or tell me y im wrong

Link to comment
Share on other sites

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