Reputation: 2413
I have a function that displays a few divs running through a loop using echo but when i put the function in it shows the info where i want it in the table cell but also next to the table
Here is my code
function getTestRows($appName)
{
$implodeArray =array();
$testsql = "SELECT DISTINCT app_instance_name FROM application_instances WHERE application_name ='$appName' AND environment = 'test' ";
$testres = mysql_query($testsql);
if(mysql_num_rows($testres) >=1)
{
while($test = mysql_fetch_array($testres))
{
echo("<div>".$test['app_instance_name']."</div>");
}
}
else
{
echo("<span>No results found</span>");
}
}
and the echo that displays it...
echo("<table id='ver-zebra' style='display: inline-table;'>
<colgroup>
<col class='vzebra-odd' />
<col class='vzebra-even'/>
</colgroup>
<thead>
<th id='appNameHead' OnMouseOver=\"this.style.cursor='pointer';\" onclick=\"openIndiv('$tmp[0]');\">
$tmp[0]
</th>
</thead>
<tbody>
<tr>
<th scope='col' id='test'>
Test
</th>
</tr>
<tr>
<td>
<div style='width: 300px; height: 100px; overflow: auto;'>");
getTestRows($tmp[0]);
echo("</div>
</td>
</tr>
Upvotes: 1
Views: 2132
Reputation: 360632
Don't output big chunks of text with echo (or print). It's far easier to just drop out of PHP mode (?>
) and output raw HTML instead. If you HAVE to do big chunks of text while in PHP, at least use a HEREDOC. They act exactly like a double-quoted string, but don't use quotes as delimiters, so you don't have to escape anything EXCEPT $
signs when you don't want them seen as variables.
Upvotes: 2
Reputation: 12080
When you call echo, it immediately gets put into the response. Have getTestRows()
return a String which is your HTML instead:
function getTestRows($appName)
{
$ret = '';
$implodeArray =array();
$testsql = "SELECT DISTINCT app_instance_name FROM application_instances WHERE application_name ='$appName' AND environment = 'test' ";
$testres = mysql_query($testsql);
if(mysql_num_rows($testres) >=1)
{
while($test = mysql_fetch_array($testres))
{
$ret .= "<div>".$test['app_instance_name']."</div>";
}
}
else
{
$ret .= "<span>No results found</span>";
}
return $ret;
}
Upvotes: 2