dee19802000 Posted December 18, 2009 Share Posted December 18, 2009 Hey I am having trouble trying to loop through a few records and I dont know where I am going wrong. What I want to do is be able to create a scolling image menu that loops through my db and display 3 elements at a time. I have managed to get how many pages there should be depending on total records etc but i cant seem to get my for loop right. There are a total of 7 records in my db but only 4 show See my code: <?php require_once('Connections/safety_connection.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $currentPage = $_SERVER["PHP_SELF"]; $maxRows_pdf_downloads = 3; $pageNum_pdf_downloads = 0; if (isset($_GET['pageNum_pdf_downloads'])) { $pageNum_pdf_downloads = $_GET['pageNum_pdf_downloads']; } $startRow_pdf_downloads = $pageNum_pdf_downloads * $maxRows_pdf_downloads; mysql_select_db($database_safety_connection, $safety_connection); $query_pdf_downloads = "SELECT * FROM pdf_downloads"; $query_limit_pdf_downloads = sprintf("%s LIMIT %d, %d", $query_pdf_downloads, $startRow_pdf_downloads, $maxRows_pdf_downloads); $pdf_downloads = mysql_query($query_limit_pdf_downloads, $safety_connection) or die(mysql_error()); $row_pdf_downloads = mysql_fetch_assoc($pdf_downloads); if (isset($_GET['totalRows_pdf_downloads'])) { $totalRows_pdf_downloads = $_GET['totalRows_pdf_downloads']; } else { $all_pdf_downloads = mysql_query($query_pdf_downloads); $totalRows_pdf_downloads = mysql_num_rows($all_pdf_downloads); } $totalPages_pdf_downloads = ceil($totalRows_pdf_downloads/$maxRows_pdf_downloads)-1; $queryString_pdf_downloads = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_pdf_downloads") == false && stristr($param, "totalRows_pdf_downloads") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_pdf_downloads = "&" . htmlentities(implode("&", $newParams)); } } $queryString_pdf_downloads = sprintf("&totalRows_pdf_downloads=%d%s", $totalRows_pdf_downloads, $queryString_pdf_downloads); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Safety Care - Catalogue</title> <link href="css/style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript" src="js/jquery.autofill.js"></script> <script type="text/javascript" src="js/jquery.flow.1.2.min.js"></script> <script> $(document).ready(function(){ $('#searchBox').autofill({ value: 'Start your search here...', defaultTextColor: '#666666', activeTextColor: '#004b8d' }); }); </script> <!-- Pull in and set up the JFLOW functionality --> <script type="text/javascript"> $(document).ready(function(){ $("#myController").jFlow({ slides: "#mySlides", controller: ".jFlowControl", // must be class, use . sign slideWrapper : "#jFlowSlide", // must be id, use # sign selectedWrapper: "jFlowSelected", // just pure text, no sign width: "960px", height: "110px", duration: 500, prev: ".jFlowPrev", // must be class, use . sign next: ".jFlowNext" // must be class, use . sign }); }); </script> <!-- Pull in and set up the JFLOW functionality for PDF Downloader --> <script type="text/javascript"> $(document).ready(function(){ $("#myControllerPDF").jFlow({ slides: "#mySlidesPDF", controller: ".jFlowControlPDF", // must be class, use . sign slideWrapper : "#jFlowSlidePDF", // must be id, use # sign selectedWrapper: "jFlowSelectedPDF", // just pure text, no sign width: "606px", height: "311px", duration: 500, prev: ".jFlowPrevPDF", // must be class, use . sign next: ".jFlowNextPDF" // must be class, use . sign }); }); </script> </head> <body> <div class="masterContainer"> <div class="masterSubContainer"> <div class="masterHeader"> <div class="masterHeaderLogo"><img src="images/logo.gif" alt="Safety Care Logo" border="0" /></div> <div class="masterHeaderNavigation"> <!-- search box start --> <div class="masterHeaderSearch"> <form id="searchForm" name="searchForm" method="post" action=""> <label> <input class="masterHeaderInput" type="text" id="searchBox" name="search"/> <input class="masterHeaderSubmit" name="submit" value="Submit" type="submit"/> </label> </form> </div> <!-- search box end --> <!-- navigation buttons start --> <div id="masterHeaderNavigationBox"> <ul> <li><a href="index.php">Home</a></li> <li><a href="services.php">Services</a></li> <li id="current"><a href="catalogue.php">Catalogue</a></li> <li><a href="quotations.php">Quotations</a></li> <li><a href="news.php">News</a></li> <li><a href="contact.php">Contact</a></li> </ul> </div> <!-- navigation buttons end --> </div> </div> <!-- banner code --> <div class="masterBanner"> <div class="masterBannerText"> <table width="100%" cellspacing="0" cellpadding="0"> <tr> <td width="21" align="left" valign="middle"><img src="images/banner-bullet.jpg" width="20" height="19" /></td> <td align="left" valign="top" class="bannerText">Catalogue</td> </tr> </table> </div> </div> <!-- slider code --> <div class="masterSliderBanner"> <div class="sliderBannerIntroText">We are stockists of <strong>leading brands</strong> such as:- </div> <div id="sliderBannerContent"> <div id="myController"> <!-- This area is hidden, but you need to add more of these if you add more slider DIVs The next one would be: ... <span class="jFlowControl">4</span> ... and so on --> <span class="jFlowControl">1</span> <span class="jFlowControl">2</span> </div> <div id="mySlides"> <!-- Each DIV is a separate slider, just add more DIVs if you want more, but be sure to add more "jFlowControl" SPANs as described above, or it will not work. --> <div><!-- Slider 1 --> <div class="SlideBlock"> <div class="subBlockHolder"><img src="images/manufacturers/dr-martins.gif" alt="Dr Martins" border="0" align="middle" /></div> <div class="subBlockHolder"><img src="images/manufacturers/cat.gif" /></div> <div class="subBlockHolder"><img src="images/manufacturers/uvex.gif" /></div> <div class="subBlockHolder"><img src="images/manufacturers/lavord.gif" /></div> <div class="subBlockHolder"><img src="images/manufacturers/dunlop.gif" /></div> </div> </div> <div><!-- Slider 2 --> <div class="SlideBlock"> <div class="subBlockHolder"> <span class="scrollerTitle"><a href="services.php">Specialist Technical Services</a></span><br /> <span class="scrollerText">Thermal Modelling</span> </div> </div> </div> </div> <!-- END mySlides --> <!-- Previous and Next Arrow Buttons (The text is hidden using CSS) --> <span class="jFlowPrev">Previous</span> <span class="jFlowNext">Next</span> </div> </div> <!-- Content Area --> <div class="masterContent"> <table width="890" cellspacing="10" cellpadding="0"> <tr> <td valign="top" align="left" class="masterLeftBlock" width="645"> <div class="masterTitle">This is the title</div> <div class="masterText">this is the text that you can use to add content</div> <div class="masterText"> <div class="pdfDownoadHold"> <!-- PDF Slider --> <div id="myControllerPDF"> <!-- This area is hidden, but you need to add more of these if you add more slider DIVs The next one would be: ... <span class="jFlowControl">4</span> ... and so on --> <?php for ($i=0; $i <= $totalPages_pdf_downloads; $i++) { $TFM_PagesEndCount = $i + 1; if($i != $pageNum_pdf_downloads) { echo '<span class="jFlowControlPDF">'. $TFM_PagesEndCount .'</span>'; }else{ echo '<span class="jFlowControlPDF">'. $TFM_PagesEndCount .'</span>'; } } ?> </div> <div id="mySlidesPDF"> <!-- Each DIV is a separate slider, just add more DIVs if you want more, but be sure to add more "jFlowControl" SPANs as described above, or it will not work. --> <div><!-- Slider start --> <?php for ($j = 0; $j <= 1; $j++) { ?> <div class="SlideBlockPDF"> <?php do { ?> <div class="pdfHolder"><img src="images/manufacturers/dr-martins.gif" alt="Dr Martins" border="0" align="middle" /></div> <?php } while ($row_pdf_downloads = mysql_fetch_assoc($pdf_downloads)); ?></div> </div><!-- Slider end --> <?php } ?> </div> <!-- END mySlides --> <!-- Previous and Next Arrow Buttons (The text is hidden using CSS) --> <span class="jFlowPrevPDF">Previous</span> <span class="jFlowNextPDF">Next</span> </div> <!-- pdf slider end --> </div> </td> <td valign="top" align="left" width="245"> <?php require_once('includes/sales-form-col.php'); ?> </td> </tr> </table> </div> <!-- footer area --> <div class="masterFooter"> <div class="leftFooter"></div> <div class="centreFooter"> <div class="copyrightNotice">© Safety Care 2009. All Rights Reserved.</div> <div class="footerNav">Home | Services | Catalogue | Quotations | News | Contact</div> </div> <div class="rightFooter"></div> </div> </div> </div> </body> </html> <?php mysql_free_result($pdf_downloads); ?> [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/185605-for-loop/ Share on other sites More sharing options...
dee19802000 Posted December 18, 2009 Author Share Posted December 18, 2009 this is the code i am having the problem with <?php for ($j = 0; $j <= 1; $j++) { ?> <div class="SlideBlockPDF"> <?php do { ?> <div class="pdfHolder"><img src="images/manufacturers/dr-martins.gif" alt="Dr Martins" border="0" align="middle" /></div> <?php } while ($row_pdf_downloads = mysql_fetch_assoc($pdf_downloads)); ?></div> </div><!-- Slider end --> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/185605-for-loop/#findComment-979952 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.