473,769 Members | 7,375 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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","roo t")
or die ("Keine Verbindung moeglich");

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

$abfrage = "SELECT * FROM tabelle";
$ergebnis = mysql_query($ab frage);
while($row = mysql_fetch_obj ect($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 8564
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","roo t")
or die ("Keine Verbindung moeglich");

mysql_select_db ("datenbank" )
or die ("Die Datenbank existiert nicht");
echo "<table>";
echo "<tr><th>Refere nznummer</th></tr>"; $abfrage = "SELECT * FROM tabelle";
$ergebnis = mysql_query($ab frage);
while($row = mysql_fetch_obj ect($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","roo t")
or die ("Keine Verbindung moeglich");

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

$abfrage = "SELECT * FROM tabelle";
$ergebnis = mysql_query($ab frage); 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_a ll($result, $tableFeatures= "") {
$table .= "<!--Debugging output for SQL query-->\n\n";
$table .= "<table $tableFeatures> \n\n";
$noFields = mysql_num_field s($result);
$table .= "<tr>\n";
for ($i = 0; $i < $noFields; $i++) {
$field = mysql_field_nam e($result, $i);
$table .= "\t<th>$fie ld</th>\n";
}
while ($r = mysql_fetch_row ($result)) {
$table .= "<tr>\n";
foreach ($r as $column) {
$table .= "\t<td>$col umn</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_a ll($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
2892
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. Value selected is used as the 'where' clause of the 2nd query. If $site is a single word, the 2nd query works like a charm. If $site is more than one word (has spaces), the query returns a null
0
2458
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 v4.0.13-standard for pc-linux. there must be a better way to query for this information than the method i'm using, since the result with v4.0 is not what i expected, nor what i received with v3.23. i'm including sample data and queries with my...
0
1569
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 custom pricing for users = where they logon.
0
3948
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 version of this document can be found at: http://prdownloads.sourceforge.net/souptonuts/README_mysql.txt?download
2
3891
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 = $result->fetch_assoc(); $count = $temprec; That doesn't seem efficient. How should I do it? Or is this as efficient
4
3519
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 doesn't return any result. We have tried on our server and we always get a result. BUT, trying on the hosting server, many times the query doesn't return any result and doesn't get any error. Any idea ? does Union have any problem ? how to check if...
1
3217
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 is set to 'auto' which is supposed to grow the HTML page height to the size necessary to display the contents within the page. The query count is correct, but the MySQL Result Set is being truncated on the html page. This happens for MySQL Results on...
2
18903
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 - view_users.php (2nd version after Script 7.4) // This script retrieves all the records from the users table. $page_title = 'View the Current Users'; include ('./includes/header.html');
8
2446
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 the customer browse (from a dynamically created drop down list - which i've done) the items by furniture class, and then have the query results limited to 26 items per page, in two columns using DIVs. The CSS for the DIVs is taken care of, as is the...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10216
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9997
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.