/    Sign up×
Community /Pin to ProfileBookmark

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.

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@DetectAug 01.2007 — Change the SQL statement. Make sure it doesn't have a LIMIT 1 in it. Make sure the function that gets the response has a loop in it to print out each row in the table.
Copy linkTweet thisAlerts:
@TJ111Aug 01.2007 — First of all if you want any real help you'll have to post your source code (delete private information and database login stuff). It sounds like yuo are trying to fetch the results from a DB without any type of looping function, which by default only lists the last entry to match the query.

Assuming you have a table in your database with only the following fields "ID, client_ID, event_date, event_type":

[code=php]
$qry = "SELECT * FROM table_name_here";
/*WHERE client_id='".$_SESSION['client_id']."' if you want personal only*/

$result = mysql_query($qry, $db) or die(mysql_error());

echo "<table>
<tr>
<th>ID</th>
<th>Client Id</th>
<th>Event Type</th>
<th>Event Date</th></tr>";

while(list($ID,$client_id,$event_date,$event_type)=(mysql_fetch_array($result)))
{
echo " <tr>
<td>$ID</td>
<td>$event_date</td>
<td>$event_type</td></tr>";
}
echo "</table>";
[/code]
Copy linkTweet thisAlerts:
@focus310authorAug 01.2007 — Hi,

This is my code.

This 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>
[/CODE]


This bit of code should produce the list for the chosen client.
[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>
[/CODE]


I do have a loop going. I don't know why the result is only selecting one record for the client instead of all.

Thanks for the help.
Copy linkTweet thisAlerts:
@DetectAug 02.2007 — Hey...

You're right...you do have a loop, BUT since you don't print out anything inside the loop, every time it loops, it overwrites the variables with the latest row of information. So make sure you are printing out info inside your loop by turning it into a function and running the function below where the HTML table is, or just move your PHP code down to where the table is.
Copy linkTweet thisAlerts:
@focus310authorAug 02.2007 — Hi,

How do I include all the HTML code which has my reference to CSS coding?

How do I create a function to be able to print like this?
Copy linkTweet thisAlerts:
@TJ111Aug 02.2007 — You can echo or print all your HTML information, just make sure you have your classes right. Remember PHP is executed on the server, and CSS and HTML are interpreted by the browser. The browser will only see the resulting HTML from your PHP function, so it has no idea it even existed. Going on your code, something like this (correcting for the out of place table tags).

[code=php]
<!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">
<?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());

$rowCheck = mysql_num_rows($result9);

//Checks to see if there's any entries
if ($rowCheck >= 1) {
//Might as well declare variables here, save time
while(list($progress_note_id,$client_id,$event_date,$event_type,$event_entry,$loc)=@mysql_fetch_array($result9,MYSQL_ASSOC))
{
?>

<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>

<?php
}
echo "</table><table class='apptable'>";

while(list($progress_note_id,$client_id,$event_date,$event_type,$event_entry,$loc)=@mysql_fetch_array($result9,MYSQL_ASSOC))
{
?>

<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>

<?php
}
?>
</table>
[/code]


It's sloppy, but shows the general idea.
Copy linkTweet thisAlerts:
@focus310authorAug 02.2007 — Hi,

I had to do some minor adjustments. It works great.

Thanks for the help.
×

Success!

Help @focus310 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...