 |
ross96 Level: Protégé
 Registered: 01-09-2005 Posts: 8
|
Create HTML table from recordset
Can anyone please tell me how can i create a HTML table based on a MySQL table... please
thx
|
|
01-09-2005 at 03:45 PM |
|
|
JLRodgers Level: Moderator
 Registered: 04-04-2002 Posts: 16
|
Re: Create HTML table from recordset
I'll just link the page
http://us2.php.net/manual/en/function.mysqli-fetch-field.php
But it has this:
Example 1. Object oriented style
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "SELECT Name, SurfaceArea from Country ORDER BY Code LIMIT 5";
if ($result = $mysqli->query($query)) {
/* Get field information for all columns */
while ($finfo = $result->fetch_field()) {
printf("Name: %s\n", $finfo->name);
printf("Table: %s\n", $finfo->table);
printf("max. Len: %d\n", $finfo->max_length);
printf("Flags: %d\n", $finfo->flags);
printf("Type: %d\n\n", $finfo->type);
}
$result->close();
}
/* close connection */
$mysqli->close();
?>
|
Example 2. Procedural style
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "SELECT Name, SurfaceArea from Country ORDER BY Code LIMIT 5";
if ($result = mysqli_query($link, $query)) {
/* Get field information for all fields */
while ($finfo = mysqli_fetch_field($result)) {
printf("Name: %s\n", $finfo->name);
printf("Table: %s\n", $finfo->table);
printf("max. Len: %d\n", $finfo->max_length);
printf("Flags: %d\n", $finfo->flags);
printf("Type: %d\n\n", $finfo->type);
}
mysqli_free_result($result);
}
/* close connection */
mysqli_close($link);
?>
|
Once you have the colum names, all you'd have to do is loop through the actual data, and put them inside the table tags.
Well... it's easier than the above... however if you're just wondering how to display the data or whatnot, please reply.
[Edited by JLRodgers on 02-09-2005 at 02:19 AM GMT]
____________________________
Everywhere's Local (pre-release), My company's website
|
|
02-09-2005 at 08:16 AM |
|
|
ross96 Level: Protégé
 Registered: 01-09-2005 Posts: 8
|
Re: Create HTML table from recordset
well, I'd like to display a table with the fields name in the first row (with a different style or backcolor) and then all the records of the table, without knowing how many fields and how many rows are in the table, simple using a "SELECT * FROM TableName".
maybe by calling a procedure passing connection parameters and table name that will return the HTML code to be displayed
|
|
02-09-2005 at 09:17 AM |
|
|
|
|
 |
 |