SunQuest
           PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old July 20th, 2002, 10:58 PM
mhoward mhoward is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: UK
Posts: 49 mhoward User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
MySQL results display

I have a script where a user can connect to my MySQL server and view information in any of their databases. Problem I am having is that when I want to display the content of any one of their tables, I cannot place them neatly into a table.
I have worked out how to put the tables field names into a table using...

$fields = mysql_list_fields("$userdbase", "$tbls");
$columns = @mysql_num_fields($fields);

$content = "<div align="center">n";
$content .= "<table border="1" cellspacing="0" cellpadding="0"n>";
$content .= "<tr>n";

for ($i = 0; $i < $columns; $i++) {
$headers = mysql_field_name($fields, $i) . "n";

$content .= "<td align="center" class="mainboxfont"><b>$headers</b></td>n";
}
$content .= "</tr>n";
but am struggling to put the actual information from the table into new rows in the same table.
I am using PHP templates which is the reason the code may look unusual.
Any help appreciated.

thanks

Reply With Quote
  #2  
Old July 21st, 2002, 01:06 AM
mikesgt2 mikesgt2 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 21 mikesgt2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: MySQL results display

I wrote a script like that once for some IT coursework, the script is copied here:
php Code:
Original - php Code
  1. <html>
  2. <head>
  3. <title>Accessing data from a MySql Database with PHP</title>
  4. </head>
  5. <body>
  6. <h2>Listing Data From a MySql Table</h2>
  7. <table border="1" width="300">
  8. <?php
  9. $link = mysql_connect() or die("Could not connect to Server");
  10. mysql_select_db("sample", $link);
  11. $result = mysql_query("SELECT * FROM blah", $link);
  12. print "<tr>";
  13.     for($i = 0; $i < mysql_num_fields($result); $i++)
  14.     {
  15.         print "<th>".mysql_field_name($result, $i)."</th>";
  16.     }
  17. print "</tr>n";
  18.     while($row = mysql_fetch_row($result))
  19.     {
  20.         print "<tr>";
  21.             foreach($row as $val)
  22.             {
  23.                 print "<td>$val</td>";
  24.             }
  25.         print "</tr>n";
  26.     }
  27. mysql_close($link);
  28. ?>
  29. </table>
  30. </body>
  31. </html>
Hope this helps!

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > MySQL results display


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway