Jump to content

help with code


dee19802000

Recommended Posts

i have a wee problem with my array here.  It is an image scroller that displays 3 images at a time and when I add more say 7 items to my array it displays the other two boxes too.  see it in actio here

 

http://www.addictivepixel.com/clients/safety-care/catalogue.php

 

 

this is my code that handles it.

 

$perPage = 3;

          //$row_pdf_downloads = mysql_fetch_assoc($pdf_downloads);
         $row_pdf_downloads = array("A","B","C","D","E","F","G");
          $tmpCount = $totalRows_pdf_downloads;
          //echo "Count of records: " . $tmpCount . "<br/>";
          $tmpPages = ceil($tmpCount/$perPage);
          //echo "Pages needed: " . $tmpPages . "<br/>";
          $tmpInc = 0;
          $lastUsed = 0;
          
          for ($g = 0; $g < $tmpPages; $g++) {
           $c = 0;
           echo '<div class="SlideBlockPDF">';
           for ($j = $lastUsed; $c < $perPage; $c++) {
             echo '<div class="pdfHolder">';
             echo $row_pdf_downloads[$j];
             $j++;
             echo '</div>';
             $lastUsed++;
           }
           echo '</div>';

          }

 

 

Any ideas on how to make it only display 7 boxes and not 9 as it does now?

Link to comment
Share on other sites

that would work if i was only doing it in multiples of 3 but in fact there could be only 7 records or more depending on how many pdf's the client uploads.  One way which i thought it could work is :

 

<?php $perPage = 3;

          $row_pdf_downloads = mysql_fetch_assoc($pdf_downloads);
         //$row_pdf_downloads = array("A","B","C","D","E","F","G");
          $tmpCount = $totalRows_pdf_downloads;
          //echo "Count of records: " . $tmpCount . "<br/>";
          $tmpPages = ceil($tmpCount/$perPage);
          //echo "Pages needed: " . $tmpPages . "<br/>";
          $tmpInc = 0;
          $lastUsed = 0;
          
          for ($g = 0; $g < $tmpPages; $g++) {
           $c = 0;
           echo '<div class="SlideBlockPDF">';
           for ($j = $lastUsed; $c < $perPage; $c++) {
if($j >= $tmpCount){
             echo '<div>';
             //echo $row_pdf_downloads[$j];

}else{
          echo '<div class="pdfHolder">';
            // echo $row_pdf_downloads[$j];

}
             $j++;
             echo '</div>';
             $lastUsed++;
           }
           echo '</div>';

          }

 

 

Link to comment
Share on other sites

I am not sure if this is what you want but you can try it out

 

<?php
$perPage = 3;

//$row_pdf_downloads = mysql_fetch_assoc($pdf_downloads);
$row_pdf_downloads = array("A","B","C","D","E","F","G");
$tmpCount = $totalRows_pdf_downloads;
//echo "Count of records: " . $tmpCount . "<br/>";
$tmpPages = ceil($tmpCount/$perPage);
//echo "Pages needed: " . $tmpPages . "<br/>";

for ($g = 0; $g < $tmpPages; $g++) {
echo '<div class="SlideBlockPDF">';
    for ($i=($g*$perPage); $i < ($g*$perPage)+$perPage; $i++) {
         if (isset($row_pdf_downloads[$i])) {
             echo '<div class="pdfHolder">';
             echo $row_pdf_downloads[$i];
             echo '</div>';
         }
    }
echo '</div>';
}
?>

Link to comment
Share on other sites

yeah it works with the array, but when i try my database it doesnt display anything.  I have this code working:

$perPage = 3;

          $row_pdf_downloads = mysql_fetch_assoc($pdf_downloads);
         //$row_pdf_downloads = array("A","B","C","D","E","F","G");
          $tmpCount = $totalRows_pdf_downloads;
          //echo "Count of records: " . $tmpCount . "<br/>";
          $tmpPages = ceil($tmpCount/$perPage);
          //echo "Pages needed: " . $tmpPages . "<br/>";
          $tmpInc = 0;
          $lastUsed = 0;
          
          for ($g = 0; $g < $tmpPages; $g++) {
           $c = 0;
           echo '<div class="SlideBlockPDF">';
           for ($j = $lastUsed; $c < $perPage; $c++) {
if($j >= $tmpCount){
             echo '<div>';
		 //echo '<img src="images/manufacturers/dr-martins.gif"></img>';
             //echo $row_pdf_downloads[$j];

}else{
          echo '<div class="pdfHolder">';
            // echo $row_pdf_downloads[$j];
		//echo $j;
		echo '<img src="' . $row_rsall['image'] . '"></img>';
             $j++;  
		} 
		while ($row_rsall = mysql_fetch_assoc($rsall));
             echo '</div>';
             $lastUsed++;
           }
           echo '</div>';
          }

 

only problem is its not looping through my database properly, it only displays the first image.  any ideas?

 

http://www.addictivepixel.com/clients/safety-care/catalogue.php

 

Dee

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.