Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-26-2010, 06:13 AM   PM User | #1
toolglutton
New Coder

 
Join Date: Dec 2010
Posts: 25
Thanks: 16
Thanked 0 Times in 0 Posts
toolglutton is an unknown quantity at this point
How to display multiple (unknown) mysql query results in one html?

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.

Last edited by toolglutton; 12-26-2010 at 06:17 AM..
toolglutton is offline   Reply With Quote
Old 12-26-2010, 07:33 AM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
You wouldn't; you'd escape out of the heredoc block and work your looping magic.
__________________
Fumigator is offline   Reply With Quote
Users who have thanked Fumigator for this post:
toolglutton (12-26-2010)
Old 12-26-2010, 01:44 PM   PM User | #3
toolglutton
New Coder

 
Join Date: Dec 2010
Posts: 25
Thanks: 16
Thanked 0 Times in 0 Posts
toolglutton is an unknown quantity at this point
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?

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.

Quote:
Originally Posted by Fumigator View Post
You wouldn't; you'd escape out of the heredoc block and work your looping magic.
toolglutton is offline   Reply With Quote
Old 12-26-2010, 03:21 PM   PM User | #4
DJCMBear
Senior Coder

 
DJCMBear's Avatar
 
Join Date: Mar 2010
Location: United Kindom
Posts: 1,173
Thanks: 14
Thanked 136 Times in 136 Posts
DJCMBear is on a distinguished road
Quote:
Originally Posted by toolglutton View Post
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?

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
PHP Code:
$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
PHP Code:
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
__________________
Official BinPress hand picked coder.
For anyone worried about SQL injection go have a look at my small yet powerful script here.
Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
I am 1 of 65,608 people to get a Pebble Watch :P

Last edited by DJCMBear; 12-26-2010 at 03:30 PM..
DJCMBear is offline   Reply With Quote
Users who have thanked DJCMBear for this post:
toolglutton (12-26-2010)
Old 12-26-2010, 04:10 PM   PM User | #5
toolglutton
New Coder

 
Join Date: Dec 2010
Posts: 25
Thanks: 16
Thanked 0 Times in 0 Posts
toolglutton is an unknown quantity at this point
Thank you so much, Man.

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

Last edited by toolglutton; 12-26-2010 at 05:11 PM..
toolglutton is offline   Reply With Quote
Old 12-26-2010, 05:11 PM   PM User | #6
toolglutton
New Coder

 
Join Date: Dec 2010
Posts: 25
Thanks: 16
Thanked 0 Times in 0 Posts
toolglutton is an unknown quantity at this point
Thank you again for your kind help.

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


$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";
toolglutton is offline   Reply With Quote
Old 12-26-2010, 05:17 PM   PM User | #7
DJCMBear
Senior Coder

 
DJCMBear's Avatar
 
Join Date: Mar 2010
Location: United Kindom
Posts: 1,173
Thanks: 14
Thanked 136 Times in 136 Posts
DJCMBear is on a distinguished road
Why not do this.

PHP Code:
$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
__________________
Official BinPress hand picked coder.
For anyone worried about SQL injection go have a look at my small yet powerful script here.
Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
I am 1 of 65,608 people to get a Pebble Watch :P
DJCMBear is offline   Reply With Quote
Users who have thanked DJCMBear for this post:
toolglutton (12-26-2010)
Old 12-26-2010, 05:49 PM   PM User | #8
toolglutton
New Coder

 
Join Date: Dec 2010
Posts: 25
Thanks: 16
Thanked 0 Times in 0 Posts
toolglutton is an unknown quantity at this point
Oh my Gosh, it worked

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

Merry Christmas.

[QUOTE=DJCMBear;1032000]Why not do this.
toolglutton is offline   Reply With Quote
Old 12-26-2010, 06:04 PM   PM User | #9
DJCMBear
Senior Coder

 
DJCMBear's Avatar
 
Join Date: Mar 2010
Location: United Kindom
Posts: 1,173
Thanks: 14
Thanked 136 Times in 136 Posts
DJCMBear is on a distinguished road
No problem, anytime =)

And Merry Christmas to you as well.
__________________
Official BinPress hand picked coder.
For anyone worried about SQL injection go have a look at my small yet powerful script here.
Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
I am 1 of 65,608 people to get a Pebble Watch :P
DJCMBear is offline   Reply With Quote
Users who have thanked DJCMBear for this post:
toolglutton (12-26-2010)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:09 AM.


Advertisement
Log in to turn off these ads.