Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] PHP & mySQL populating HTML table


[SOLVED] PHP & mySQL populating HTML table

Reply
  #1 (permalink)  
Old 04-24-08, 10:14 AM
88mph 88mph is offline
Newbie Coder
 
Join Date: Mar 2008
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] PHP & mySQL populating HTML table

using this code

PHP Code:

<?php

        $value_array 
= array(    'item_type',
                                
'title'
                                
'brand'
                                
'model'
                                
'serial_no',
                                
'replacement_cost',
                                
'quantity',
                                
'kit_content',
                                
'main_location',
                                
'current_location',
                                
'notes');
        
        
$inventory mysql_fetch_array(get_all_inventory());
        foreach (
$inventory as $row){
            
$output "<tr>";
            
            foreach(
$value_array as $cell){
                
$output .="<td>{$row[$cell]</td>";
            };
            
            
$output .= "</tr>";
        }
        echo 
$output;
        ?>
But all it seems to do is output the letter 'U' for one row of cells, rather than the content of my table

here is the code for the function get_all_inventory();

PHP Code:

function get_all_inventory() {

        global 
$connection;
        
$query "SELECT * 
                FROM main_inventory 
                ORDER BY item_type ASC"
;
        
$subject_set mysql_query($query$connection);
        
confirm_query($subject_set);
        return 
$subject_set;
    } 
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 04-24-08, 10:22 AM
de.monkeyz's Avatar
de.monkeyz de.monkeyz is offline
Wannabe Coder
 
Join Date: Apr 2008
Location: Leeds, UK
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

$output .="<td>{$row[$cell]</td>"; 


There needs to be a closing } not sure it wil fix it;

PHP Code:

$output .="<td>{$row[$cell]}</td>"
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 04-24-08, 10:28 AM
88mph 88mph is offline
Newbie Coder
 
Join Date: Mar 2008
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
oops

and no, didn't fix it!!

is it the method that is flawed?
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 04-24-08, 10:43 AM
de.monkeyz's Avatar
de.monkeyz de.monkeyz is offline
Wannabe Coder
 
Join Date: Apr 2008
Location: Leeds, UK
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
Just fetching the array once will just output one value so something like this usually:


PHP Code:

<?php
        $value_array 
= array(    'item_type',
                                
'title'
                                
'brand'
                                
'model'
                                
'serial_no',
                                
'replacement_cost',
                                
'quantity',
                                
'kit_content',
                                
'main_location',
                                
'current_location',
                                
'notes');
        
          
                
$result get_all_inventory();

       while( 
$inventory mysql_fetch_array($result));
        {
                   
                foreach(
$value_array as $cell)
                     
$output .="<td>{$inventory[$cell]}</td>";
       };
            
            
$output .= "</tr>";
        }
        echo 
$output;
        
?>

That should output all values. Although you will need to add the table header to output before the while loop


Edit:Changed the code since I think get_all_inventory() will reset the result all the time... causing an infinite loop!

Last edited by de.monkeyz; 04-24-08 at 10:50 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 04-24-08, 10:50 AM
88mph 88mph is offline
Newbie Coder
 
Join Date: Mar 2008
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

while( $inventory mysql_fetch_array(get_all_inventory())) {
        
$output "<tr>";
            
            foreach(
$value_array as $cell){
                     
$output .="<td>{$inventory[$cell]}</td>";
               };
            
            
$output .= "</tr>";
        }
        echo 
$output;
        
?> 
used this (just a little doctored version of yours) and it hangs Safari
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 04-24-08, 10:52 AM
de.monkeyz's Avatar
de.monkeyz de.monkeyz is offline
Wannabe Coder
 
Join Date: Apr 2008
Location: Leeds, UK
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
Yeah it's an infinite loop, I changed my code in the prev post coz I realised that
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 04-24-08, 10:54 AM
88mph 88mph is offline
Newbie Coder
 
Join Date: Mar 2008
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
where is the change? I can't see why its an infinite loop?!?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 04-24-08, 10:59 AM
88mph 88mph is offline
Newbie Coder
 
Join Date: Mar 2008
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
right, used this and it worked
PHP Code:

<?php
        $value_array 
= array(    'item_type',
                                
'title'
                                
'brand'
                                
'model'
                                
'serial_no',
                                
'replacement_cost',
                                
'quantity',
                                
'kit_content',
                                
'main_location',
                                
'current_location',
                                
'notes');
        
    
$result get_all_inventory();
      
    while( 
$inventory mysql_fetch_array($result)) {
        
$output "<tr>";
            
            foreach(
$value_array as $cell){
                     
$output .="<td>{$inventory[$cell]}</td>";
               };
            
            
$output .= "</tr>";
            echo 
$output;
        }
        
        
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 04-24-08, 11:09 AM
de.monkeyz's Avatar
de.monkeyz de.monkeyz is offline
Wannabe Coder
 
Join Date: Apr 2008
Location: Leeds, UK
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
So no problems then? The reason it would be an infinite loop is because you would keep called get_all_inventory each time, and restart the data from entry 1, so you just get the first item over and over
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 04-24-08, 11:12 AM
The_Demon The_Demon is offline
Newbie Coder
 
Join Date: Dec 2007
Location: The burning depths of hell
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
hehe, that's never wanted in a script, especially if it's got a massive max runtime
__________________
The Demon
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
For Hire (3 years exp.): Looking for Php, Mysql, AJAX, JavaScript, HTML, XML Barkat Job Offers & Assistance 1 09-25-07 05:15 PM
PHP not recognizing admin in MySQL gizelle Database 3 04-15-07 09:39 PM
Need help with some php mysql TheTinkeringToad PHP 9 02-01-06 11:56 AM
IIS MYSQL and PHP nommiiss PHP 6 01-31-06 05:30 PM
html in php from mysql jasondavis PHP 3 12-04-04 11:01 PM


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