PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

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 Dev Shed Forums Sponsor:
  #1  
Old July 11th, 2000, 06:48 AM
zcrar70's Avatar
zcrar70 zcrar70 is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 49 zcrar70 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
i'm trying to write a script that dynamically generates HTML tables depending on the results from an SQL query. So far, I have managed to set the HTML table headers to be the same as those in the MySQL table. [thanks to rod k -cheers !]

Now i'm trying to put the results in the table. Basically, I need a MySQL function to retrieve data and put it into the table until there is no data left....

(At the moment I am using "mysql_fetch_array()", but with this it is necessary to know the names of the columns to retrieve the information for each result set. Since my table is dynamic and should be able to build itself from different MySQL tables, the column names aren't fixed and so i can't use this to put the data in the tables...)

any ideas ?

-nick

Reply With Quote
  #2  
Old July 11th, 2000, 06:59 AM
Shiju Rajan's Avatar
Shiju Rajan Shiju Rajan is offline
.Net Developer
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: London
Posts: 987 Shiju Rajan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
Send a message via MSN to Shiju Rajan Send a message via Yahoo to Shiju Rajan

At the moment I am using "mysql_fetch_array()", but with this it is necessary to know the names of the columns to retrieve the information for each result set. Since my table is dynamic and should be able to build itself from different MySQL tables, the column names aren't fixed and so i can't use this to put the data in the tables...)


You don't have to remember the column names.Instead of that you can use coulmn index numbers..

let us say you have the columns sno,name,address in a table..

the coulmn index will start from 0.so you can retrive the coulmn values using index 0,1 and 2.

eg:

<?
$row=mysql_fetch_array($result);

$sno=$row[0];
$name=$row[1];
$address=$row[2];
?>





------------------
SR -
webshiju.com

"The fear of the LORD is the beginning of knowledge..."

Reply With Quote
  #3  
Old July 11th, 2000, 07:23 AM
Sepodati's Avatar
Sepodati Sepodati is offline
Banned (not really)
Dev Shed God 20th Plane (14500 - 14999 posts)
 
Join Date: Dec 1999
Location: Brussels, Belgium
Posts: 14,628 Sepodati User rank is General 51st Grade (Above 100000 Reputation Level)Sepodati User rank is General 51st Grade (Above 100000 Reputation Level)Sepodati User rank is General 51st Grade (Above 100000 Reputation Level)Sepodati User rank is General 51st Grade (Above 100000 Reputation Level)Sepodati User rank is General 51st Grade (Above 100000 Reputation Level)Sepodati User rank is General 51st Grade (Above 100000 Reputation Level)Sepodati User rank is General 51st Grade (Above 100000 Reputation Level)Sepodati User rank is General 51st Grade (Above 100000 Reputation Level)Sepodati User rank is General 51st Grade (Above 100000 Reputation Level)Sepodati User rank is General 51st Grade (Above 100000 Reputation Level)Sepodati User rank is General 51st Grade (Above 100000 Reputation Level)Sepodati User rank is General 51st Grade (Above 100000 Reputation Level)Sepodati User rank is General 51st Grade (Above 100000 Reputation Level)Sepodati User rank is General 51st Grade (Above 100000 Reputation Level)Sepodati User rank is General 51st Grade (Above 100000 Reputation Level)Sepodati User rank is General 51st Grade (Above 100000 Reputation Level)  Folding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced Folder
Time spent in forums: 3 Months 6 Days 2 h 39 m 6 sec
Reputation Power: 4375
Send a message via ICQ to Sepodati Send a message via Yahoo to Sepodati
There is also a function that will fetch the names of the columns also, if you want to display them since they are dynamic. check the manual under Mysql functions...

---John Holmes...

Reply With Quote
  #4  
Old July 11th, 2000, 07:27 AM
zcrar70's Avatar
zcrar70 zcrar70 is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 49 zcrar70 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
thanks Shiju... I had in fact came quite close to using a similar system using mysql_fetch_row instead of mysql_fetch_array....

however, in terms of my table, I still have the same problem: I do not have a way of putting the data into the table unless i know how many elements to put in before creating a new <tr>[html table row].

at the moment i have:

while(mysql_fetch_row ($this->Query_ID)):
$i = 0;
echo "<tr><td>$db->Rowdata[$i]</td>
<td>",
$i++;


This is far from working. Is there a way of findin the amount of elements in an array ?

Then I could do something like:

while($array=mysql_fetch_row ($this->Query_ID)):
$i = 0;
$j = [amount of elements in $array];
echo "<tr>";
while ($i < $j):
echo "<tr><td>$db->Rowdata[$i]</td>
<td>"; $i++;
endwhile;
echo "</tr>";

it's all a bit stream-of-thought so apologies if i'm not clear.... thanks a lot though for all help from everyone so far

-nick


[This message has been edited by zcrar70 (edited July 11, 2000).]

[This message has been edited by zcrar70 (edited July 11, 2000).]

Reply With Quote
  #5  
Old July 11th, 2000, 09:32 AM
ledjon
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
In perl the # of times in an array can be found by just saying "$var = @array;"... I'd assume there's something similar in PHP... though I'm not sure that will solver your problem.

Reply With Quote
  #6  
Old July 11th, 2000, 09:59 AM
simpson simpson is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 32 simpson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
since the result set is in array form

can't you just do

echo count($result);

or am i missing the point

Reply With Quote
  #7  
Old July 11th, 2000, 10:26 AM
zcrar70's Avatar
zcrar70 zcrar70 is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 49 zcrar70 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
hi all,

thanks a lot for your responses... i finally managed to do it ! this is how


$db = new DBconnect; //this class is v similar to the one in the "accessing db with classes article

$query = "SELECT * FROM table WHERE column like '%'";
$db->dbquery($query);

#first build table

echo "<table><table border=1 bgcolor='#eeeeee'>";

#build table headlines;
echo "<tr>";
while ($column3= $db->fetch_fields()): //this is just a mysql_fetch_fields function in the class

echo "<th>$column3[name]</th>";
endwhile;

#enter results into database

while($db->next_record()): //same func as in tutorial

$i = 0;
$j = sizeof($db->Record); //this is the magic function !! finds the amount of elements in an array... pretty much exactly the same as count (cheers Simpson...)
echo "<tr>";

while ($i < $j) {
echo "<td>", $db->Record[$i], "</td>";
$i++;}

echo "<td>";
endwhile;


et voila ! it's all easy when you know what you're doing, it's just that that's the hard bit !
thanks a lot for all your help....

-nick

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > dynamically generated results table

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap