focus310
08-01-2007, 07:14 PM
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.
Fumigator
08-01-2007, 09:50 PM
You're only getting the last row? Where's the code that does this?
Len Whistler
08-01-2007, 11:02 PM
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
$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>
focus310
08-01-2007, 11:44 PM
Hi,
This is my code.
This first bit of code selects the client from a drop down box.
<?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"> </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.
<?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> </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.
Len Whistler
08-01-2007, 11:58 PM
The <td><tr></td></tr> has to be inside the while loop.
focus310
08-02-2007, 12:02 AM
Hi,
Do I place all of my HTML code in the while loop? Otherwise, how do I get the HTML formatting I have now?
Len Whistler
08-02-2007, 12:07 AM
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.