dee19802000 Posted December 21, 2009 Share Posted December 21, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/185900-help-with-code/ Share on other sites More sharing options...
ChemicalBliss Posted December 21, 2009 Share Posted December 21, 2009 Do it in 3's, dont have 7, have 9, but have the last two the same as the first two. Other than that, i believe you will need to change the javascript/css that handles the display. -CB- Quote Link to comment https://forums.phpfreaks.com/topic/185900-help-with-code/#findComment-981706 Share on other sites More sharing options...
dee19802000 Posted December 21, 2009 Author Share Posted December 21, 2009 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>'; } Quote Link to comment https://forums.phpfreaks.com/topic/185900-help-with-code/#findComment-981724 Share on other sites More sharing options...
rajivgonsalves Posted December 21, 2009 Share Posted December 21, 2009 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>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/185900-help-with-code/#findComment-981730 Share on other sites More sharing options...
dee19802000 Posted December 21, 2009 Author Share Posted December 21, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/185900-help-with-code/#findComment-981753 Share on other sites More sharing options...
rajivgonsalves Posted December 21, 2009 Share Posted December 21, 2009 what does your $row_pdf_downloads have it should be a array similar to the one you represented Quote Link to comment https://forums.phpfreaks.com/topic/185900-help-with-code/#findComment-981781 Share on other sites More sharing options...
dee19802000 Posted December 21, 2009 Author Share Posted December 21, 2009 what do u mean, i should make the $pdf_downloads in to an array? Quote Link to comment https://forums.phpfreaks.com/topic/185900-help-with-code/#findComment-981806 Share on other sites More sharing options...
rajivgonsalves Posted December 21, 2009 Share Posted December 21, 2009 Yes it should be an array containing the details of the rows, why is it showing only the first row its because your doing a mysql_fetch_assoc prior that will fetch the first row, you need to build an array out of the rows. Quote Link to comment https://forums.phpfreaks.com/topic/185900-help-with-code/#findComment-981811 Share on other sites More sharing options...
dee19802000 Posted December 21, 2009 Author Share Posted December 21, 2009 cheers, im pretty new at php so how would i go about creating the array from the database? is it mysql_fetch_array? Quote Link to comment https://forums.phpfreaks.com/topic/185900-help-with-code/#findComment-981831 Share on other sites More sharing options...
dee19802000 Posted December 21, 2009 Author Share Posted December 21, 2009 hey i got it, thanks so much for your help! $query = "SELECT * FROM pdf_downloads"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); echo '<img src="' . $row["image"] . '"></img>'; thanks again! dee Quote Link to comment https://forums.phpfreaks.com/topic/185900-help-with-code/#findComment-981835 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.