Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more

Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Web Programming > PHP Development
User Name
Password

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-02-2005, 07:57 PM   #1 (permalink)
goldfish
Junior Member
 
Join Date: Jul 2005
Posts: 27
Default Display mysql table fields and data

Hello All,

I need to create a php script to display a mysql table fields and the data. Any assistance is much appreciated.

thanks
goldfish is offline   Reply With Quote
Sponsored Links
Old 08-02-2005, 08:42 PM   #2 (permalink)
Jim_Westergren
Junior Member
 
Join Date: Aug 2005
Posts: 7
Default

Here I give you:

<CENTER>
<H1>MySQL Database</H1>
</CENTER>

<?php

// Database connection
require ("../db.cnf.php");


$sql = mysql_query("SELECT * FROM table ORDER BY column ASC");

echo "<table border='0' CELLPADDING=5 STYLE='font-size:13px'>";
echo "<tr> <td><H3>Column 1 Name</h3></td> <td><H3>Column 2 Name</H3></td> <td><H3>Column 3 Name</H3></td><td><H3>Column 4 Name</H3></td></tr>";
// keeps getting the next row until there are no more to get
while ($row = mysql_fetch_array($sql)) {

// Print out the contents of each row into a table
echo "<tr><td>";
echo $row['Column 1 Name'];
echo "</td><td>";
echo $row['Column 2 Name'];
echo "</td><td>";
echo $row['Column 3 Name'];
echo "</td><td>";
echo $row['Column 4 Name'];
echo "</td></tr>";
}
echo "</table>";

?>

Hope this helped you.
__________________
Jim Westergren
AddURL-Free.com | ArcadeShack.com | JW-Network.com | JW-Webbdesign.se
PM me if you are interested in buying/exchanging text links.
Jim_Westergren is offline   Reply With Quote
Old 08-02-2005, 08:55 PM   #3 (permalink)
sandman
Junior Member
 
Join Date: Jul 2005
Posts: 34
Default

Here is another example although ~Jim_Westergren's code should work fine. Replace the connection and table variables with your own.

viewall.php
PHP Code:
<html> 
<head><title>Your Page Title</title></head> 
<body> 
<?php 
$database
="yourdbname"
mysql_connect ("localhost""yourusername""yourpassword"); 
@
mysql_select_db($database) or die( "Unable to select database"); 
$result mysql_query"SELECT * FROM yourtable" 
or die(
"SELECT Error: ".mysql_error()); 
$num_rows mysql_num_rows($result); 
print 
"There are $num_rows records.<P>"
print 
"<table width=400 border=1>\n"
while (
$get_info mysql_fetch_row($result)){ 
print 
"<tr>\n"
foreach (
$get_info as $field
print 
"\t<td><font face=arial size=1/>$field</font></td>\n"
print 
"</tr>\n"

print 
"</table>\n"
?> 
</body> 
</html>


viewcertainfields.php
PHP Code:
<html> 
<head><title>Your Page Title</title></head> 
<body> 
<?php 
$database
="yourdbname"
mysql_connect ("localhost""yourusername""yourpassword"); 
@
mysql_select_db($database) or die( "Unable to select database"); 
$result mysql_query"SELECT field1, field2, field3 FROM yourtable" 
or die(
"SELECT Error: ".mysql_error()); 
$num_rows mysql_num_rows($result); 
print 
"There are $num_rows records.<P>"
print 
"<table width=200 border=1>\n"
while (
$get_info mysql_fetch_row($result)){ 
print 
"<tr>\n"
foreach (
$get_info as $field
print 
"\t<td><font face=arial size=1/>$field</font></td>\n"
print 
"</tr>\n"

print 
"</table>\n"
?> 
</body> 
</html>

You can also add limit and order to the query...
sandman is offline   Reply With Quote
Old 09-04-2006, 10:44 AM   #4 (permalink)
Chikenty
Junior Member
 
Join Date: Sep 2006
Posts: 4
Default Re: Display mysql table fields and data

wondering if any1 could help me with to put a limit and to put a sort on it..oh yeah and if colum names if u could :-) i just need sum help thanks
Chikenty is offline   Reply With Quote
Old 09-04-2006, 11:51 AM   #5 (permalink)
pr0gr4mm3r
Junior Member
 
Join Date: Sep 2006
Location: Behind You
Posts: 12
Default Re: Display mysql table fields and data

I have this function in my main include file to debug SQL queries:

PHP Code:
function DumpSQL($result)
{    
    if(
$result == 0)
    {
        echo 
"<b>Error ".mysql_errno().": ".mysql_error()."</b>";
    }
    elseif (@
mysql_num_rows($result) == 0)
    {
        echo(
"<b>Query completed. No results returned.</b><br>");
    }
    else
    {
        echo 
"<table border='1'>
            <thead>
            <tr><th>[Num]</th>"
;
        for(
$i 0;$i mysql_num_fields($result);$i++)
        {
            echo 
"<th>" $i "&nbsp;-&nbsp;" mysql_field_name($result$i) . "</th>";
        }
        echo 
"  </tr>
            </thead>
            <tbody>"
;
        for (
$i 0$i mysql_num_rows($result); $i++)
        {
            echo 
"<tr><td>[$i]</td>";
            
$row mysql_fetch_row($result);
            for(
$j 0;$j mysql_num_fields($result);$j++) 
            {
                echo(
"<td>" $row[$j] . "</td>");
            }
            echo 
"</tr>";
        }
        echo 
"</tbody>
        </table>"
;
    }  
//end else


Then to use it, do it this way:

PHP Code:
$query "SELECT * FROM Table";
$result mysql_query($query);
DumpSQL($result); 

Query to limit your results (The limit clause goes after the WHERE, ORDER BY clause if exists):

Code:
SELECT * FROM table LIMIT 20

Query that sorts:

Code:
SELECT * FROM table ORDER BY field
__________________
Life would be easier if I had the source code.
pr0gr4mm3r is offline   Reply With Quote
Old 09-04-2006, 04:42 PM   #6 (permalink)
Chikenty
Junior Member
 
Join Date: Sep 2006
Posts: 4
Default Re: Display mysql table fields and data

nittounlimited.com/view.php shows All Ratios is my current display page..and nittounlimited.com/view3.php is the 1 i want to add something similar of sorting to..thanks
Chikenty is offline   Reply With Quote
Old 05-14-2008, 04:49 AM   #7 (permalink)
ganeshkmb
Junior Member
 
Join Date: May 2008
Posts: 1
Default Re:How and we manage Inbox and Outbox

[quote=goldfish]Hello All,

I need to have INBOX and Sent Items ina form . how can i receive a mail from the others and how can i send a file from my PHP script.. How can i save the mails ..

Tell me its very Urgent.
Thank u all..
ganeshkmb is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Points Per Thread View: 1.00
Points Per Thread: 11.00
Points Per Reply: 5.00


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP form for entering data to MySQL database vvaldir PHP Development 31 08-26-2006 12:44 PM
Listing mysql data using php kayla Other Programming - Perl, C++, Java, ASP, .NET Development 1 06-26-2005 10:07 PM


» Sponsors

» Links

» Affiliates
Web Hosting
Online Backup Reviews
Marketing Find
Merchant Select
SiteMap Builder
Host Compare
Dedicated Servers

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 07:04 PM.



LinkBacks Enabled by vBSEO 3.0.0 RC8
Webmaster Forums