displaying records in a table
Posted: Sat Oct 29, 2011 8:47 pm
Hi,
I have this code it displays records from the table in 2 columns
So right now the records are displayed in table like this
I want to show 500 records in first and second table cell and 500 records in other 2 table cell so then i want my table to look like this
Here is my actual code
I have this code it displays records from the table in 2 columns
So right now the records are displayed in table like this
Code: Select all
<table>
<tr>
<td></td>
<td></td>
</tr>
</table>I want to show 500 records in first and second table cell and 500 records in other 2 table cell so then i want my table to look like this
Code: Select all
<table>
<tr>
<td>first 500 records</td>
<td>first 500 records</td>
<td>Other 500 records</td>
<td>Other 500 records</td>
</tr>
</table>Here is my actual code
Code: Select all
<?php
$db_host = 'mysql12.abc.com';
$db_user = 'test1';
$db_pwd = 'Test123';
$database = 'testdatabase';
$table = 'pricing';
if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");
if (!mysql_select_db($database))
die("Can't select database");
// sending query
$result = mysql_query("SELECT * FROM {$table}");
if (!$result) {
die("Query to show fields from table failed");
}
$fields_num = mysql_num_fields($result);
echo "<table border='1'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
$field = mysql_fetch_field($result);
echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result))
{
echo "<tr>";
// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo "<td>$cell</td>";
echo "</tr>\n";
}
mysql_free_result($result);
echo "</table>\n";
?>