Jump to content

I want tables for my data by $id


vetman

Recommended Posts

I have this acript:

 

<?php

// Make a MySQL Connection

include 'config.php';

 

$con = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

mysql_select_db("rwts_webmaster") or die(mysql_error());

 

echo "Connected to Database <br>";

 

// Retrieve all the data from the "ufm_form_data" table

$result = mysql_query("SELECT * FROM ufm_form_data")

or die(mysql_error());

 

// store the record of the "ufm_form_data" table into $row

echo "<table border='1' width='800'>";

// keeps getting the next row until there are no more to get

while($row = mysql_fetch_array( $result )) {

// Print out the contents of each row into a table

echo "<tr><th>Company</th><td> {$row['company']}</td><tr>";

echo "<tr><th>FirstName</th><td> {$row['firstName']}</td><tr>";

echo "<tr><th>LastName</th><td> {$row['lastName']}</td><tr>";

echo "<tr><th>Email</th><td> {$row['email']}</td><tr>";

echo "<tr><th>Address</th><td> {$row['address1']}</td><tr>";

echo "<tr><th>City</th><td> {$row['city']}</td><tr>";

echo "<tr><th>State</th><td> {$row['state']}</td><tr>";

echo "<tr><th>Zip Code</th><td> {$row['postalCode']}</td><tr>";

echo "<tr><th>Phone</th><td> {$row['phone']}</td><tr>";

echo "<tr><th>Info</th><td> {$row['info']}</td><tr>";

echo "<tr><th>Quote</th><td> {$row['quote']}</td><tr>";

echo "<tr><th>Comments</th><td> {$row['comments']}</td><tr>";

 

 

}

 

echo "</table>";

 

 

It shows up in a table, vertically, down the page, but it includes all the data. I want to break up the data by $id,

 

$id1 table

 

$id2 table

 

$id3 table

 

I guess in other words I want it to loop thru the total number of $id's showing each in it's own table.

I hope this explains it right.

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/102551-i-want-tables-for-my-data-by-id/
Share on other sites

try

$result = mysql_query("SELECT * FROM ufm_form_data")
or die(mysql_error());

// store the record of the "ufm_form_data" table into $row
$current = '';
//echo "<table border='1' width='800'>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
$id = $row['id'];
if (!$current) {
echo "<table border='1' width='800'>";
$current = $id;
} elseif ($current != $id){
echo "</table><table border='1' width='800'>";
$current = $id;
}
// Print out the contents of each row into a table
echo "<tr><th>Company</th><td> {$row['company']}</td><tr>";
echo "<tr><th>FirstName</th><td> {$row['firstName']}</td><tr>";
echo "<tr><th>LastName</th><td> {$row['lastName']}</td><tr>";
echo "<tr><th>Email</th><td> {$row['email']}</td><tr>";
echo "<tr><th>Address</th><td> {$row['address1']}</td><tr>";
echo "<tr><th>City</th><td> {$row['city']}</td><tr>";
echo "<tr><th>State</th><td> {$row['state']}</td><tr>";
echo "<tr><th>Zip Code</th><td> {$row['postalCode']}</td><tr>";
echo "<tr><th>Phone</th><td> {$row['phone']}</td><tr>";
echo "<tr><th>Info</th><td> {$row['info']}</td><tr>";
echo "<tr><th>Quote</th><td> {$row['quote']}</td><tr>";
echo "<tr><th>Comments</th><td> {$row['comments']}</td><tr>";
}
echo "</table>";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.