473,385 Members | 1,824 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,385 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 8537
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.