Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > create dynamic table with php for web

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-01-08, 04:12
goksu goksu is offline
Registered User
 
Join Date: Nov 2008
Posts: 3
Question create dynamic table with php for web

Hello,
Can somebody help me out with this?
I have previously done this in asp. I need to do it in php.

I have some mdb tables that I need to print on screen (through a dynamic web page).
the table dimensions vary. I can connect to the table without a problem (odbc).

I need some code to structure the table from the data inside the table.

for the three columns, to create three columns (or five if there are five),
for the column headers to use the column names (as used inside the dbtable),
and have lines as much as there is data (10, 20 maybe).

the asp code I wrote a while back is of no use for the apache server.
Reply With Quote
  #2 (permalink)  
Old 12-01-08, 05:12
Frunkie Frunkie is offline
Gives Bad Advice
 
Join Date: Mar 2007
Location: 010101010110100
Posts: 706
PHP Code:
<?php
include("conn.php");
$query "
select col1,
   col2,
   col3
FROM
   yourTable
WHERE
   something..."
;

$result conn($query);
if ((
$result)||(mysql_errno == 0))
{
  echo 
"<table width='100%'><tr>";
  if (
mysql_num_rows($result)>0)
  {
          
//loop thru the field names to print the correct headers
          
$i 0;
          while (
$i mysql_num_fields($result))
          {
       echo 
"<th>"mysql_field_name($result$i) . "</th>";
       
$i++;
    }
    echo 
"</tr>";
   
    
//display the data
    
while ($rows mysql_fetch_array($result,MYSQL_ASSOC))
    {
      echo 
"<tr>";
      foreach (
$rows as $data)
      {
        echo 
"<td align='center'>"$data "</td>";
      }
    }
  }else{
    echo 
"<tr><td colspan='" . ($i+1) . "'>No Results found!</td></tr>";
  }
  echo 
"</table>";
}else{
  echo 
"Error in running query :"mysql_error();
}
?>

This should get you going in the right direction. Of course you'll need to interchange the mysql functions for M$ functions throughout the script.
__________________
I and many others around the world are of the strong belief that the universe was created by the Flying Spaghetti Monster. It was He who created all that we see and all that we feel. We feel strongly that the overwhelming scientific evidence pointing towards evolutionary processes is nothing but a coincidence, put in place by Him.
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On