ferdia Posted October 31, 2010 Share Posted October 31, 2010 Hi guys, PHP advanced amateur and PHPFreaks newbie here. I have a problem with some code I've written. What the code is supposed to do, is take in 15 records in a single MySQL table column, and then print them out in a format like this: 1 2 3 4 5 6 7 8 9 so on so on. Here is the page in question: http://robbieduggan.com/strawberry-interactive/portfolio-web-design.php Now the problem is, you can see 14 images there, but it seems to be negating the first one. Its always whatever row 0 is, because if I change the SORT BY attrabute in the code below, it's a different one that is missing. Here is my code to get the data: mysql_select_db($database_strawberry, $strawberry); $query_rsProjects = "SELECT page_unique_identity, clean_title, thumbnail FROM tblprojects ORDER BY `timestamp` DESC"; $rsProjects = mysql_query($query_rsProjects, $strawberry) or die(mysql_error()); $row_rsProjects = mysql_fetch_assoc($rsProjects); $totalRows_rsProjects = mysql_num_rows($rsProjects); And here is the code to create the table: echo "<table width='100%' border='0' cellspacing='5' cellpadding='5'>"; for($i = 0; $i < $totalRows_rsProjects; $i++) { $row = mysql_fetch_array($rsProjects); if($i % $columns == 0) { echo "<tr>"; } echo "<td>"; if($row['page_unique_identity'] != NULL){ echo "<a href='website-details.php?project=".$row['page_unique_identity']."'><img src='portfolio/".$row['thumbnail']."' alt=".$row['clean_title']." width='267' height='162' /></a>"; } echo "</td>"; if(($i % $columns) == ($columns - 1) || ($i + 1) == $totalRows_rsProjects) { echo "</tr>"; } } Thanks in advance for any help Link to comment https://forums.phpfreaks.com/topic/217327-a-column-based-problem/ Share on other sites More sharing options...
Pikachu2000 Posted October 31, 2010 Share Posted October 31, 2010 You're calling mysql_fetch_assoc() in the first code chunk, so when the second one executes, the pointer is already on the second record. mysql_select_db($database_strawberry, $strawberry); $query_rsProjects = "SELECT page_unique_identity, clean_title, thumbnail FROM tblprojects ORDER BY `timestamp` DESC"; $rsProjects = mysql_query($query_rsProjects, $strawberry) or die(mysql_error()); $row_rsProjects = mysql_fetch_assoc($rsProjects); // < --- Here's your problem . . . $totalRows_rsProjects = mysql_num_rows($rsProjects); Link to comment https://forums.phpfreaks.com/topic/217327-a-column-based-problem/#findComment-1128516 Share on other sites More sharing options...
ferdia Posted October 31, 2010 Author Share Posted October 31, 2010 ¬¬ I knew it would be that simple. Thanks loads Pikachu2000. I wish I'd come and asked an hour ago. Lol. Link to comment https://forums.phpfreaks.com/topic/217327-a-column-based-problem/#findComment-1128519 Share on other sites More sharing options...
Pikachu2000 Posted October 31, 2010 Share Posted October 31, 2010 You're welcome. Come back any time! Link to comment https://forums.phpfreaks.com/topic/217327-a-column-based-problem/#findComment-1128522 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.