Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Should I use for and a while loop?

    I have a script which displays 10,000 small images all on one page. If the image is available it should display one image. If the image is not available it should display another image. The problem is that I can't get it to work this way. Here's the cbulk of the code:
    PHP Code:
    <?php # PHP Script - display.php

        // Number of records to display per page:
        
    $display 10000;
        
        
    // Determine how many pages there are.
        
    if (isset($_GET['np'])) { //Already been determined.
            
    $num_pages $_GET['np'];
        } else { 
    // Need to determine.
    //get the data
    $query "SELECT id, entry_date, square_number, avail_image, alt, hyper_link, available, image FROM ads ORDER BY id ASC";
    $query_result mysql_query($query);
        
    $num_records = @mysql_num_rows ($query_result);
        
        if (
    $num_records $display) { // More than 1 page.
            
    $num_pages =ceil ($num_records/$display);
        } else {
            
    $num_pages 1;
        }
    }

    // Determine where in the database to start returning results.
    if (isset($_GET['s'])) { // Already been determined.
        
    $start $_GET['s'];
    } else {
        
    $start 0;
    }

    // Make the query.
    $query "SELECT id, entry_date, square_number, avail_image, alt, hyper_link, available, image FROM ads ORDER BY id ASC LIMIT $start, $display";
    $result = @mysql_query($query); // Run the query.
    $num mysql_num_rows ($result); // How many records are there?

    if ($num 0) { // If it ran ok, display the records.

          
        
        
          // Make the links to other pages, if necessary.
          
    if ($num_pages 1) {
                          
          
    // Determine what page the script is on.
          
    $current_page = ($start/$display) + 1;
                          
          
    // If it's not the first page, make a Previous button.
          
    if ($current_page != 1) {
              echo 
    '<div align="right" width="50%"><a href="index.php?s=' . ($start $display) . '&np=' $num_pages '"><font face="verdana" size="2" color="FFFFFF"><b>Previous</b></font></a> ';
        }
                          
          
    // Make all the numbered pages.
          
    for ($i 1$i <= $num_pages$i++) {
          if (
    $i != $current_page) {
            echo 
    '<a href="index.php?s=' . (($display * ($i 1))) . '&np=' $num_pages '"><font face="verdana" size="2" color="FFFFFF"><b>' $i '</b></font></a> ';
        } else {
            echo 
    $i ' ';
        }
    }
                        
          
    // If it's not the last page, make a next button.
          
    if ($current_page != $num_pages) {
            echo 
    '<a href="index.php?s=' . ($start $display) . '&np' $num_pages '"><font face="verdana" size="2" color="FFFFFF"><b>Next</b></font></a>';
        }
        
         echo 
    '</div>';
                        
                      
                    
    // End of links section.
    }

    //set variables and constants.
    DEFINE('NUM_COLUMNS'100);
    DEFINE('TABLE_WIDTH'1000);
    $record_number 0;
    $column_width floor(TABLE_WIDTH NUM_COLUMNS);


    echo 
    '<table align="left" width="'TABLE_WIDTH '" border="0" cellspacing="0" cellpadding="0">';
    while(
    $row mysql_fetch_array($resultMYSQL_NUM))
      {
      if(
    fmod($record_numberNUM_COLUMNS) == 0)
        echo 
    '<tr>';
      
    //--information for each individual cell in the row 
       
      
    if ($image = @filesize ("uploads/{$row[3]}|{$row[7]}")) {
          for (
    $row[6] <= 2$row[6] <= 2; ) {
              echo 
    "<td><a href=\"buy_pixels.php?id={$row['0']}\" target=\"_blank\"><img src=\"uploads/{$row[3]}\" width=\"10\" height=\"10\" border=\"0\" alt=\"{$row[2]}\" /></a></td>\n";
       } 
       } while (
    $row[6] == '2')  {
             echo 
    "<td><img src=\"uploads/{$row['7']}\" width=\"10\" height=\"10\" border=\"0\" alt=\"{$row[2]}\" /></td>\n";
       }
      
    //---
      
      
    $record_number++;    
      if(
    fmod($record_numberNUM_COLUMNS) == 0)
        echo 
    '</tr>';
      }
     echo 
    '</table>';

    ?>
    and the scetion of code that I'm dealing with:
    PHP Code:
    if ($image = @filesize ("uploads/{$row[3]}|{$row[7]}")) {
          for (
    $row[6] <= 2$row[6] <= 2; ) {
              echo 
    "<td><a href=\"buy_pixels.php?id={$row['0']}\" target=\"_blank\"><img src=\"uploads/{$row[3]}\" width=\"10\" height=\"10\" border=\"0\" alt=\"{$row[2]}\" /></a></td>\n";
       } 
       } while (
    $row[6] == '2')  {
             echo 
    "<td><img src=\"uploads/{$row['7']}\" width=\"10\" height=\"10\" border=\"0\" alt=\"{$row[2]}\" /></td>\n";
       } 
    I think I need to use a for and a while loop, but I can't figure out how to impliment that. Any ideas?

    Thanks!

  • #2
    New Coder
    Join Date
    Mar 2005
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's got to be a for and a while... I've tried if and else, and that doesnt display the way i need it to, but I still can't figure out how to construct the for... please help!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •