SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Location
    Monmouth Junction, NJ
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got an array that has 123 fields in it and I go through the array and print into a file that has 5 listed per row. This file is html. Now i need it so that i can print 5 into one row into page1.html and than it will print the second 5 rows onto page2.html and so on. So basiaclly 25 array items per file. I tried making a script to do this but it didnt work out that well. Wondering if someone could help. Here is the script without my attempt

    PHP Code:
    <?php
        
    if ($HTTP_POST_VARS["submit"] == "Submit") {
            
    $c 0;
            
    $dh dir($category);
            while (
    $entry $dh->read()) {
                
    $images[$c] = $entry;
                
    $c++;
            }
            
    $dh->close();
            
    $cnt count($images);
            
    $count 2;
            
    $x 0;
            
    $file fopen("$category/index.html","w");
            
    fputs ($file"<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr>");
            while (
    $count<=$cnt) {
                if (
    $x == 5) {
                    
    fputs ($file"</tr><tr>");
                    
    $x 0;
                }
                
    fputs ($file"<td><a href=\"$count.html\">$images[$count]</a><br></td>");
                
    $file2 fopen("$category/$count.html","w");
                
    fputs ($file2"<center><img src=\"$images[$count]\"><br><br><a href=\"javascript:history.back(1)\">Back</a></center>");
                
    fclose($file2);
                
    $count++;
                
    $x++;
            }
            
    fputs ($file"</tr></table>");
            
    fclose($file);
            echo 
    "Successfully file written <a href=\"$category/index.html\">Menu</a>";
            echo 
    $cnt;

            
    /*
            ************************Coding for the thumbnail creation************************
            $im = ImageCreateFromJpeg("memberscontent/01.jpg");
            $im1 = ImageCreateFromJpeg("memberscontent/bla.jpg");
            ImageCopyResized($im, $im1, 50, 100, 50, 100, 70, 70, 35, 35);
            ImageJpeg($im1);
            ImageDestroy($im);
            ImageDestroy($im2);
            */
        
    } else {
    ?>
            <html>
                <head>
                    <title>Input Category</title>
                </head>

                <body>
                    <form action="<?php echo $HTTP_SERVER_VARS["PHP_SELF"]; ?>" method="POST">
                        <input type="text" name="category" size="20">
                        <input type="submit" name="submit" value="Submit">
                    </form>
                </body>
            </html>
    <?php
        
    }
    ?>

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I would try to use two for loops where
    the inner loop prints out the images to the
    current page, and the outer loop changes $file to refer to another page:
    Code:
    for($count=0; $count<$cnt; $count++)
    {
      
      for($i=0; $i<5; $i++)
      {
         write image to $file
      }
      
      fclose($file);
      $page_number=$count + 1;
      $filename=$category . "/page" . $page_number . "html";
      $file=fopen($filename,"w");
    }
    Last edited by 7stud; Apr 16, 2001 at 01:29.

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Location
    Monmouth Junction, NJ
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    not to sound rude but that helped me in no way...

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Location
    Monmouth Junction, NJ
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    because how will the script know how many pages to create if there are 283 fields in the array?

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol....Gee, I don't know, maybe stop writing images to the file when you hit the end of the array?

    Code:
    
    $page_number=1;
    $images_this_page=0;
    for($count=0; $count<count($images); $count++)
    {
      
      (write image to $file)
      $images_this_page++;
      
      if ($images_this_page==5)
      {
        fclose($file);
        $filename=$category . "/page" . $page_number . "html";
        $file=fopen($filename,"w");
        $page_number++;
        $images_this_page=0;
      }
    }
    Last edited by 7stud; Apr 16, 2001 at 12:55.

  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Location
    Monmouth Junction, NJ
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    alright thats cool. It worked thanks a lot.

  7. #7
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Your welcome. I probably learned more from your script than you learned from me. Thanks.

  8. #8
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Location
    Monmouth Junction, NJ
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    heh want to see the whole script i did heck of a lot of modifications

    PHP Code:
    <?php
        
    if ($HTTP_POST_VARS["submit"] == "Submit") {
            
    $c 0;
            
    $dh dir($category);
            while (
    $entry $dh->read()) {
                
    $images[$c] = $entry;
                
    $c++;
            }
            
    $dh->close();
            
    $x 0;
            
    $file=fopen("$category/page1.html","w");
            
    fputs ($file"<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr>");
            
    $page_number 2;
            
    $pagenumb 2;
            
    $images_this_page 0;
            for(
    $count=2$count<count($images); $count++) {
                if (
    $x == 5) {
                    
    fputs ($file"</tr><tr>");
                    
    $x 0;
                }
                
    fputs ($file"<td><a href=\"$count.html\">$images[$count]</a><br></td>");
                
    $images_this_page++;
                  if (
    $images_this_page == 25) {
                    
    $pagenum $page_number 2;
                    if (
    $pagenum == 0) {
                        
    fputs ($file"</tr></table><br><br><center><a href=\"page$pagenumb.html\">Next Page</a></center>");
                    } else {
                        
    fputs ($file"</tr></table><br><br><center><a href=\"page$pagenum.html\">Previous Page</a>&nbsp;&nbsp;&nbsp;<a href=\"page$pagenumb.html\">Next Page</a></center>");
                    }
                    
    $pagenumb $page_number 1;
                    
    fclose($file);
                    
    $filename $category "/page" $page_number ".html";
                    
    $file=fopen($filename,"w");
                    
    fputs ($file"<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr>");
                    
    $page_number++;
                    
    $images_this_page=0;
                  }
                
    $file2 fopen("$category/$count.html","w");
                
    fputs ($file2"<center><img src=\"$images[$count]\"><br><br><a href=\"javascript:history.back(1)\">Back</a></center>");
                
    fclose($file2);
                
    $x++;
            }
            
    $pagenum $page_number-2;
            
    fputs ($file"</tr></table><br><br><center><a href=\"page$pagenum.html\">Previous Page</a></center>");
            
    fclose($file);
            echo 
    "Successfully file written <a href=\"$category/index.html\">Menu</a>";

            
    /*
            ************************Coding for the thumbnail creation************************
            $im = ImageCreateFromJpeg("content/01.jpg");
            $im1 = ImageCreateFromJpeg("content/bla.jpg");
            ImageCopyResized($im, $im1, 50, 100, 50, 100, 70, 70, 35, 35);
            ImageJpeg($im1);
            ImageDestroy($im);
            ImageDestroy($im2);
            */

        
    } else {
    ?>
            <html>
                <head>
                    <title>Input Category</title>
                </head>

                <body>
                    <form action="<?php echo $HTTP_SERVER_VARS["PHP_SELF"]; ?>" method="POST">
                        <input type="text" name="category" size="20">
                        <input type="submit" name="submit" value="Submit">
                    </form>
                </body>
            </html>
    <?php
        
    }
    ?>


Bookmarks

Posting Permissions

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