473,387 Members | 1,407 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Result of Mysql Query in a PHP table

Hi,

I've a problem:

I want to have the result of my Mysql Query in a Table in my php file.
Now I've this:
<?

mysql_connect("localhost","root")
or die ("Keine Verbindung moeglich");

mysql_select_db("datenbank")
or die ("Die Datenbank existiert nicht");

$abfrage = "SELECT * FROM tabelle";
$ergebnis = mysql_query($abfrage);
while($row = mysql_fetch_object($ergebnis))

{
echo $row->Referenznummer;
}

?>
But I want that the result is in a Table. With the heading "Referenznummer".
It should be like:
---------------
Referenznummer:
---------------
Result 1
---------------
Result 2
......
....
...
I searched a long time in google without success, please help me

Thanks
Felix

Btw: sorry for my bad english
Jul 16 '05 #1
2 8538
Felix wrote:
Hi,

I've a problem:

I want to have the result of my Mysql Query in a Table in my php file.
Now I've this:
<?

mysql_connect("localhost","root")
or die ("Keine Verbindung moeglich");

mysql_select_db("datenbank")
or die ("Die Datenbank existiert nicht");
echo "<table>";
echo "<tr><th>Referenznummer</th></tr>"; $abfrage = "SELECT * FROM tabelle";
$ergebnis = mysql_query($abfrage);
while($row = mysql_fetch_object($ergebnis))

{ echo "<tr><td>"; echo $row->Referenznummer; echo "</td></tr>"; } echo "</table>";
?>
But I want that the result is in a Table. With the heading "Referenznummer".
It should be like:


Jul 16 '05 #2
Felix wrote:
mysql_connect("localhost","root")
or die ("Keine Verbindung moeglich");

mysql_select_db("datenbank")
or die ("Die Datenbank existiert nicht");

$abfrage = "SELECT * FROM tabelle";
$ergebnis = mysql_query($abfrage); But I want that the result is in a Table. With the heading "Referenznummer".
It should be like:
---------------
Referenznummer:
---------------
Result 1
---------------
Result 2


Hi, Felix
I've written a small utility function that I use for this. It takes a
MySQL result set as an argument, and returns an HTML table (string)
containing all the column headers and rows, formatted.

Here's the function:

function _mysql_result_all($result, $tableFeatures="") {
$table .= "<!--Debugging output for SQL query-->\n\n";
$table .= "<table $tableFeatures>\n\n";
$noFields = mysql_num_fields($result);
$table .= "<tr>\n";
for ($i = 0; $i < $noFields; $i++) {
$field = mysql_field_name($result, $i);
$table .= "\t<th>$field</th>\n";
}
while ($r = mysql_fetch_row($result)) {
$table .= "<tr>\n";
foreach ($r as $column) {
$table .= "\t<td>$column</td>\n";
}
$table .= "</tr>\n";
}
$table .= "</table>\n\n";
$table .= "<!--End debug from SQL query-->\n\n";
return $table;
}

You could use it like this, using your $ergebnis variable:

print _mysql_result_all($ergebnis);

That is, copy the function above into your script, and then use the
preceding line to output the result.

Enjoy...

--
//Marius

Jul 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: dogu | last post by:
Noob alert. Code is below. File is saved as a .php. What I'm trying to do: User uses 'select' box drop down list to pick a value. Value ($site) is derived from a db query. This works fine....
0
by: Doug Reese | last post by:
hello, i have what seems to me a very common operation i'm performing. i need to find the balance on an invoice. i was not having any problems until the production server was upgraded to mysql...
0
by: Brian Newsham | last post by:
------=_NextPart_000_004F_01C352B1.E5B8FA20 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, I'm working on a PHP based website that loads...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
2
by: Belmin | last post by:
Hi all, Wanted to know what is the most efficient way of doing a select query for mysql that only returns one value. For example: $mysqli->query('select count(*) from log'); $temprec =...
4
by: Bob Bedford | last post by:
We have no access to a mysql NG on my provider's server, so we ask here: We have a long query (long in text) with a UNION between 2 select. We have been informed that some times the query...
1
by: automation | last post by:
There is a truncation error of my Web Application using PHP 5.04, MySQL 5.022, and HTML(IE 6.0) whereby the MySQL Result Set is being truncated on the HTML page, even though the CSS Div Page Height...
2
by: 00webman | last post by:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /var/www/html/scripts/07/view_users.php on line 15 Can anyone spot my error?!? Thanks. <?php # Script 7.6 -...
8
siridyal
by: siridyal | last post by:
I have a wholesale website that i'm working on that shows hundreds of items that are updated from time to time. These items are kept in a mysql database with several tables. I want to let the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.