garethhall Posted June 19, 2009 Share Posted June 19, 2009 Hello Can anyone see an error in my code? I have looked and I can see why it's not going I get an error when I try to call $rs_limit. <?php mysql_select_db($database_content, $content); //Get public albums include("includes/publicAlbums.php"); include("includes/getPageDetails.php"); $pageDetailsSQL = "SELECT * FROM pages WHERE pageId = 3"; $recordPageDetails = mysql_query($pageDetailsSQL, $content) or die(mysql_error()); $rowPageDetails = mysql_fetch_assoc($recordPageDetails); //check if page is ative if($rowPageDetails['pageStatus'] <> "on"){ header("Location: construction.php"); }else{ if(!$_GET['albumID']){// if album ID is not set redirect to indexpage header("Location: index.php"); } } // Protect Variables from SQL injection function checkVars($value){ // Stripslashes if (get_magic_quotes_gpc()){ $value = stripslashes($value); } // Quote if not a number if (!is_numeric($value)){ $value = "'" . mysql_real_escape_string($value) . "'"; } return $value; }; //Set Variables $albumID = checkVars(base64_decode($_GET[albumID])); $showNoPhotos = 25;// items per page $cPage = $_GET['page'];// current page // Sql select query $SQL_photos = "SELECT photos.photoID, photos.photoName, photos.originalName, photos.photoDate, albums.albumName, albums.albumDesc, albums.albumType FROM photos INNER JOIN albums ON photos.albumId = albums.albumID WHERE albums.albumID = $albumID;"; $rs_Photos = mysql_query($SQL_photos, $content); $totalNoPhoto = mysql_num_rows($rs_Photos);// get item count $tPages = ceil($totalNoPhoto/$showNoPhotos);// calculate no pages required $calNo = $_GET['page']-1;//calculate ofset for start at No in DB (!isset($_GET['page'])? $startPhotoNo = 0 : $startPhotoNo = $calNo*$showNoPhotos);// set start to show photo from Number (!isset($_GET['page'])? $cPage = 1 : $cPage = $_GET['page']); $SQL_limit = sprintf("%s LIMIT %d, %d", $SQL_photos, $startPhotoNo, $showNoPhotos); $rs_limit = mysql_query($SQL_limit, $content); //echo $SQL_limit; //echo ($rs_Photos? "ok": "bad"); //echo $totalNoPhoto; echo ($rs_limit? "ok": "bad");// HERE I GET BAD WHY????? ?> Link to comment https://forums.phpfreaks.com/topic/162852-solved-mysql-query-not-working/ Share on other sites More sharing options...
EchoFool Posted June 19, 2009 Share Posted June 19, 2009 What is the error, errors tell you where to look 90% of the time so it would help if we could see what it said ? Link to comment https://forums.phpfreaks.com/topic/162852-solved-mysql-query-not-working/#findComment-859333 Share on other sites More sharing options...
garethhall Posted June 19, 2009 Author Share Posted June 19, 2009 Ok I get "mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource" on line 117 which is <?php while($row_limit = mysql_fetch_assoc($rs_limit)){ $j++; ?> <li><a href="CMS/smartP/photos/<?php echo $row_limit['photoName']; ?>" rel="lightbox[photos]" title="<?php echo $row_limit['photoName']; ?>"><img src="CMS/smartP/thumb/<?php echo $row_limit['photoName']; ?>" alt="1" class="ImgBorder"/></a> <div class="photoDetail"> <div class="numbers"> <?php echo $j; ?> </div> </div> </li> <? } ?> Link to comment https://forums.phpfreaks.com/topic/162852-solved-mysql-query-not-working/#findComment-859335 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.