Current location: Hot Scripts Forums » Programming Languages » PHP » HTML tables from PHP/MySQL query


HTML tables from PHP/MySQL query

Reply
  #1 (permalink)  
Old 01-23-04, 08:40 AM
MikeNL MikeNL is offline
Newbie Coder
 
Join Date: Jan 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
HTML tables from PHP/MySQL query

Hi,

Does anyone know how to create HTML tables (3 rows, 4 colums) from a MySQL query in PHP?

I have a script that works, but the first row only has 3 colums, all the other rows have 4.

THX!!!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 01-23-04, 10:14 AM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,167
Thanks: 3
Thanked 8 Times in 8 Posts
Here is an example:

PHP Code:

<?php
    $location 
"localhost";
    
$username "username";
    
$password "password";
    
$database "database";
    
$conn mysql_connect("$location","$username","$password");
 
    if (!
$conn) die ("Could not connect MySQL");
    
mysql_select_db($database,$conn) or die ("Could not open database");
 
mysql_query("CREATE TABLE tablename (
column1 VARCHAR(20),
column2 VARCHAR(20),
column3 VARCHAR(20),
column4 VARCHAR(20))"
);
 
Repeat this set of code 3 times to insert 3 rows:
 
$insert "INSERT INTO users (column1,column2,column3, column4)
    VALUES ('Value1','Value2','Value3','Value4')"
;
    
mysql_query($insert) or die ("Could not add data to the table");
 
?>
Let me know if you have any other questions.




Quote:
Originally Posted by MikeNL
Hi,

Does anyone know how to create HTML tables (3 rows, 4 colums) from a MySQL query in PHP?

I have a script that works, but the first row only has 3 colums, all the other rows have 4.

THX!!!!!
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 01-23-04, 05:37 PM
Volte Volte is offline
New Member
 
Join Date: Jan 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Dude, Create HTML tables FROM MySQL Querys, Not Create Tables in MySQL.

PHP Code:

$Query mysql_query("SELECT * FROM table WHERE (field='value')");


echo 
"<table><tr><td>Column 1</td><td>Column 2</td><td>Column 3</td></tr>";
while (
$Row mysql_fetch_array($Query)) {

echo 
"<tr><td>Column 1 Value</td><td>Column 2 Value</td><td>Column 3 Value</td></tr>";

}

echo 
"</table>"
I think that's what you were trying to do.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 01-24-04, 03:47 AM
MikeNL MikeNL is offline
Newbie Coder
 
Join Date: Jan 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
THX Volte, I will try it, Mike
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Classified Ads skipper23 Perl 3 11-22-05 03:22 AM
Classified Ads skipper23 Perl 2 12-30-03 04:43 AM
Declared Functions skipper23 PHP 4 12-17-03 11:06 AM
index page not showing up skipper23 PHP 3 12-15-03 02:10 PM


All times are GMT -5. The time now is 01:03 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.