IT Community - Software Programming, Web Development and Technical Support

MySQL

This is a discussion on MySQL within the PHP Programming forums, part of the Web Development category; Hello, can someone tell me how can I output all fields of a row in a mysql db using php? ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read
  #1  
Old 02-04-2009, 11:10 AM
lldcrb328 lldcrb328 is offline
D-Web Trainee
 
Join Date: Feb 2009
Posts: 3
lldcrb328 is on a distinguished road
Default MySQL

Hello, can someone tell me how can I output all fields of a row in a mysql db using php? and then write.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 02-09-2009, 08:55 PM
maneetpuri maneetpuri is offline
D-Web Trainee
 
Join Date: Feb 2009
Posts: 7
maneetpuri is on a distinguished road
Default Re: MySQL

Hi,

Here is a small piece of code that will generate a table with field names as headings and then rows for the data: -



<?

$qstr = “Select * from table_name”;

$qry = mysql_query($qstr);

$flds = mysql_fetc_field($qry);



Echo “<table border =1>”;

Echo “<tr>”;

$i = 0;
while ($i < mysql_num_fields($qry)) {

echo “<td>” . mysql_fetch_field($qry, $i) . “</td>”;
$i++;

}



$j = 0;

While ($arr = mysql_fetch_array($qyr)) {

Echo “<tr>”;

While ($j <= $i) {

Echo “<td>” . $arr[$j] . “</td>”;

$j++;

}

Echo “</tr>”;

$j = 0;

}

Echo “</tr>”;

Echo “</table>”

?>
__________________
Maneet Puri
Web Design Company / Data Processing Services
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 02-15-2009, 09:45 PM
hkp819 hkp819 is offline
D-Web Trainee
 
Join Date: Dec 2008
Posts: 41
hkp819 is on a distinguished road
Default Re: MySQL

Quote:
Originally Posted by maneetpuri View Post
Hi,

Here is a small piece of code that will generate a table with field names as headings and then rows for the data: -



<?

$qstr = “Select * from table_name”;

$qry = mysql_query($qstr);

$flds = mysql_fetc_field($qry);



Echo “<table border =1>”;

Echo “<tr>”;

$i = 0;
while ($i < mysql_num_fields($qry)) {

echo “<td>” . mysql_fetch_field($qry, $i) . “</td>”;
$i++;

}



$j = 0;

While ($arr = mysql_fetch_array($qyr)) {

Echo “<tr>”;

While ($j <= $i) {

Echo “<td>” . $arr[$j] . “</td>”;

$j++;

}

Echo “</tr>”;

$j = 0;

}

Echo “</tr>”;

Echo “</table>”

?>
that is very good answer.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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 Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
I Can Help With MYSQL theseokit Database Support 9 01-21-2009 11:01 PM
php-mysql lekshmy PHP Programming 0 01-21-2009 10:58 PM
Why to use MySQL Amisha_Sharma Database Support 1 01-07-2009 07:56 PM


All times are GMT -7. The time now is 12:09 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0