Current location: Hot Scripts Forums » Programming Languages » PHP » using a loop to display mysql results?


using a loop to display mysql results?

Reply
  #11 (permalink)  
Old 01-31-04, 01:10 AM
simone's Avatar
simone simone is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
oh got it working perfectly now, thanks a great deal blaw!
Reply With Quote
  #12 (permalink)  
Old 01-31-04, 01:24 AM
simone's Avatar
simone simone is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
uhh actually i have one more question. (sorry to bother you) but how would i make it show on the page ..using a variable ...like because im using templates, i dont want it to echo straight from the php page, id like it only to show if i place something like $showrows in the template file.
Reply With Quote
  #13 (permalink)  
Old 01-31-04, 03:58 AM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hi there,

Instead of echoing, you can assign (fetch) it into a variable and display it whenever you want to.

But the thing is, it really depends on what kind of template engine/algorithm you are using. For instance, would you like your $showrows to hold only one row at a time or all rows?

If all, then instead of echoing, you can fetch everything into $showrows with concatination operator (e.g. $output .= "whatever_you_are_fetching"; ):

PHP Code:

// Basically the same as before.

// Note that this time we don't have echo, but $output .=
// Also, I took out <table> tags.
for ($i 0$i 4$i++) {
    
    
// Fetch <tr>.
    
$output .= '<tr>';
    
    for (
$j 0$j 3$j++) {
        
        
// See if there is still a fetchable row in the result.
        
if ($row mysql_fetch_array($res)) {
            
$output .= '<td>'.$row[0].'</td>';
        }
        
// If not, fetch the dummy link.
        
else {
            
$output .= '<td><a href="submit.php">Submit Yours</a</td>';
        }
    
    }
    
    
// Fetch </tr>.
    
$output .= "</tr>\n";


In the end you'll get $output that holds all the rows. Then simply place(echo) this var between <table> and </table> to display the table. But again, it depends on what you really need to get out of this function.

Hope this gives you some idea.
__________________
Blavv =|
Reply With Quote
  #14 (permalink)  
Old 01-31-04, 08:02 AM
simone's Avatar
simone simone is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
yes, thankyou! that worked magically ..thanks for the major help! <3
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
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
results page to display prev/next php-learner PHP 11 01-12-04 09:40 AM
Paginating mysql results. simone PHP 6 12-26-03 02:25 PM
Which way to display results from mysql Peter_web PHP 2 09-13-03 05:39 PM


All times are GMT -5. The time now is 08:05 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.