...

View Full Version : How to display multiple (unknown) mysql query results in one html?



toolglutton
12-26-2010, 06:13 AM
I am trying to use the following php code to show my results ($search[] is an array with multiple rows):

$theResults=<<<EOD
<html>
<body>

<table>
<tr>
<td>Results:</td> <td>$search[]</td>
</tr>
</table>

</body>
</html>
EOD;

echo "$theResults";

The problem is that there are multiple results, and I want to show all of them in one page. How do I create a while loop inside the <<<EOD and achieve this?

Thank you.

Fumigator
12-26-2010, 07:33 AM
You wouldn't; you'd escape out of the heredoc block and work your looping magic.

toolglutton
12-26-2010, 01:44 PM
Thank you so much for the reply. ;)

So bad to know I can not achieve this using <<<EOD. Does anyone here know how I can get around this? :confused:

My search results range from 1 to 50. And I really want them to appear in a nice html with my navigation bar and other stuff.


You wouldn't; you'd escape out of the heredoc block and work your looping magic.

DJCMBear
12-26-2010, 03:21 PM
Thank you so much for the reply. ;)

So bad to know I can not achieve this using <<<EOD. Does anyone here know how I can get around this? :confused:

My search results range from 1 to 50. And I really want them to appear in a nice html with my navigation bar and other stuff.


You can you need to add a fullstop just before the equals sign so instead of this = you would put this .= this way you can still use <<<EDO EDO;, but you will only the word Array for the result $search[] as you can not output an array like this.

Example1


$theResults = <<<EOD
<html>
<body>

<table>
<tr>
<td>Results:</td> <td>
EOD;
foreach($search As $row) {
$theResults .= <<<EOD
// Your HTML Here
EOD;
}
$theResults .= <<<EOD
</td>
</tr>
</table>

</body>
</html>
EOD;

print $theResults;


Example2


foreach($search As $row) {
$searchResults .= <<<EOD
// Your HTML Here
EOD;
}

$search = implode("\n",$searchResults);

$theResults = <<<EOD
<html>
<body>

<table>
<tr>
<td>Results:</td> <td>{$search}</td>
</tr>
</table>

</body>
</html>
EOD;

print $theResults;

toolglutton
12-26-2010, 04:10 PM
Thank you so much, Man. :)

I will give it a try and let you know how it goes.

toolglutton
12-26-2010, 05:11 PM
Thank you again for your kind help.

Now I kept getting an error message. Would you mind to correct my code? :confused:


$theResults=<<<EOD
<html>
<body>
<!-- This is the container -->
<div style="position:relative; width:960px;height:auto;margin-left:auto;margin-right:auto; padding: 0 20px; background: #FFFFFF;border: 0px solid #000000;z-index:1;">
<table>
<tr>
<td style="text-align:right;font-weight:bold;">applies to: </td>
<td>
EOD;

foreach($make as $row){
$theResults.=<<<EOD
<p>$row</p>;
EOD;
}

$theResults.=<<<EOD
</td>
</tr>
</table>
</div>

</div> <!-- container ending -->
</body>
</html>
EOD;
print "$theResults";

DJCMBear
12-26-2010, 05:17 PM
Why not do this.



$theResults = <<<EOD
<html>
<body>
<!-- This is the container -->
<div style="position:relative;width:960px;height:auto;margin:0 auto;padding:0 20px;background:#FFFFFF;border:0px solid #000000;z-index:1;">
<table>
<tr>
<td style="text-align:right;font-weight:bold;">applies to: </td>
<td>
EOD;

foreach($make as $row){
$theResults .= " <p>{$row}</p>";
}

$theResults .= <<<EOD
</td>
</tr>
</table>
</div> <!-- container ending -->
</body>
</html>
EOD;

print $theResults;

toolglutton
12-26-2010, 05:49 PM
Oh my Gosh, it worked :eek:

I appreciate your precious time in helping me out very much. :thumbsup:

Merry Christmas.

[QUOTE=DJCMBear;1032000]Why not do this.

DJCMBear
12-26-2010, 06:04 PM
No problem, anytime =)

And Merry Christmas to you as well.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum