Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Dec 2010
    Posts
    25
    Thanks
    16
    Thanked 0 Times in 0 Posts

    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.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You wouldn't; you'd escape out of the heredoc block and work your looping magic.

  • Users who have thanked Fumigator for this post:

    toolglutton (12-26-2010)

  • #3
    New Coder
    Join Date
    Dec 2010
    Posts
    25
    Thanks
    16
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    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
    Last edited by DJCMBear; 12-26-2010 at 03:30 PM.
    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

  • Users who have thanked DJCMBear for this post:

    toolglutton (12-26-2010)

  • #5
    New Coder
    Join Date
    Dec 2010
    Posts
    25
    Thanks
    16
    Thanked 0 Times in 0 Posts
    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.

  • #6
    New Coder
    Join Date
    Dec 2010
    Posts
    25
    Thanks
    16
    Thanked 0 Times in 0 Posts
    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";

  • #7
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    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

  • Users who have thanked DJCMBear for this post:

    toolglutton (12-26-2010)

  • #8
    New Coder
    Join Date
    Dec 2010
    Posts
    25
    Thanks
    16
    Thanked 0 Times in 0 Posts
    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.

  • #9
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    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

  • Users who have thanked DJCMBear for this post:

    toolglutton (12-26-2010)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •