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 7 of 7
  1. #1
    New Coder
    Join Date
    May 2007
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Echo-ing data from table

    Hello:

    I have a table which looks like this:
    ID | client_id | event_date | event_type
    1 | 4 | 08/01/2007 | SV
    2 | 4 | 09/01/2007 | AD

    All I need to do is display this information in an HTML format. Thus far, all I get is the last entry for that client.

    How can I print both entries into a report?

    Thanks for the help.

  • #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're only getting the last row? Where's the code that does this?

  • #3
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    I posted an answer to your post on the Larry Ullman php/mysql forum, below is a cut/paste of my post.

    --------------------------------------------

    Use a while loop. Below is a VERY rough code but should give you an idea of what to do.

    PHP Code:
    <?php
    $sql 
    mysql_query("SELECT * FROM");
    ?>
    <table>
    <?php
    while($row mysql_fetch_array($sql)){
    echo 
    "<tr><td>row[client_id]</td>";
    echo 
    "<td>row[event_type]</td>";
    echo 
    "<td>row[event_date ]</td></tr>";
    }
    ?>
    </table>
    Leonard Whistler

  • #4
    New Coder
    Join Date
    May 2007
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    This is my code.

    This first bit of code selects the client from a drop down box.
    Code:
    <?php
    include('header_admin.html');
    require_once('mysql_connect.php');
    
    ?>  
    <fieldset><legend>Please select a client</legend>
    <form action="testing.php" method="post">        
    <p><label for="client_id">Client Name:</label>
      <select name="client_id">
       <option value="">- Please Select -</option>
    	<?php
              $query="SELECT * FROM client";
    	  $result = @mysql_query ($query) or die (mysql_error());
    	
                 while($row=@mysql_fetch_array($result, MYSQL_ASSOC))
                   {
                    
                     $client_id = $row['client_id'];
                     $client_name = $row['client_name'];
    
    
    	
                         print '<option value="' . $client_id . "\"  >" . $client_name . "</option>\n";
    		}
    	?>
      </select>
    </p>
      
      <p><label for="blank">&nbsp;</label><input type="submit" name="btnSubmit" id="btnSubmit" value="Submit" class="btn" /></p>
    <input type="hidden" name="submitted" value="TRUE" />
    </fieldset>
    </form>
    This bit of code should print the information for the client which was selected.
    Code:
    <?php 
    
    require_once ('mysql_connect.php');
    
    $query="SELECT client_name
            FROM client 
            WHERE client_id = $_POST[client_id]";
    
    $result = @mysql_query ($query) or die (mysql_error()); 
    
    if ($result) {
    
    while($row=@mysql_fetch_array($result, MYSQL_ASSOC))
    {
                     
                     $client_name = $row['client_name'];
    }
    }
    
    
    $query9="SELECT * FROM progress_note WHERE client_id = $_POST[client_id]";
    
    $result9 = @mysql_query ($query9) or die (mysql_error()); 
    
    if ($result9) {
    
    while($row9=@mysql_fetch_array($result9, MYSQL_ASSOC))
    {
                     
                     $progress_note_id = $row9['progress_note_id'];
                     $client_id = $row9['client_id'];
                     $event_date = $row9['event_date'];
                     $event_type = $row9['event_type'];
                     $event_entry = $row9['event_entry'];
                     $loc = $row9['loc'];
    
    }
    }
    
    
    ?>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <link href="output_style.css" rel="stylesheet" type="text/css">
    
    </head>
    <body>
    <div id="container">
    </div>
    <div id="content">
    
    <table class="apptable">
    <tr>
    <td class="j"><b>Client's Name:</b></td><td class="j"><?php echo $client_name; ?></td>
    <td class="j"><b>LOC:</b></td><td class="j"><?php echo $loc; ?></td></tr>
    </table>
    
    <tr><td>&nbsp;</td></tr>
    <table class="apptable">
    <tr><th>Date</th><th scope="col">Type of Event</th><th scope="col">Entry</th></tr>
    <tr><td class="d"><?php echo $event_date; ?></td><td class="d"><?php echo $event_type; ?></td><td class="d"><?php echo $event_entry; ?></td></tr>
    </table>
    I don't understand why only one record for the client appears rather than all.

    Thanks for the help.

  • #5
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    The <td><tr></td></tr> has to be inside the while loop.
    Leonard Whistler

  • #6
    New Coder
    Join Date
    May 2007
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    Do I place all of my HTML code in the while loop? Otherwise, how do I get the HTML formatting I have now?

  • #7
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Quote Originally Posted by focus310 View Post
    Hi,

    Do I place all of my HTML code in the while loop? Otherwise, how do I get the HTML formatting I have now?
    Only the <td> </td> <tr> and </tr> go inside the loop.
    Leonard Whistler


  •  

    Posting Permissions

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