itsureboy Posted July 14, 2007 Share Posted July 14, 2007 What I want to use $row['image'] again in that same loop but with the value of the next row in the database (same query) (look at the code to understand what i mean): <?php include 'exampleconnect.php'; if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } $max_results = 12; $cat = $cat; $from = (($page * $max_results) - $max_results); $sql = mysql_query("SELECT title, image FROM rap WHERE category = '$cat' ORDER BY id DESC LIMIT $from, $max_results"); while($row = mysql_fetch_array($sql)){ echo $row['title']; echo $row['image']; ##I want to use $row['image'] again in this loop but with the value of the next row in the database (same query) } include 'exampleclose.php'; ?> Link to comment https://forums.phpfreaks.com/topic/59986-php-mysql-help/ Share on other sites More sharing options...
per1os Posted July 14, 2007 Share Posted July 14, 2007 <?php include 'exampleconnect.php'; if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } $max_results = 12; $cat = $cat; $from = (($page * $max_results) - $max_results); $sql = mysql_query("SELECT title, image FROM rap WHERE category = '$cat' ORDER BY id DESC LIMIT $from, $max_results"); while($row = mysql_fetch_array($sql)){ $rows[] = $row; } for ($i=0; $i<(count($rows)-1);$i++) { echo $rows[$i]['title']; echo $rows[$i]['image']; echo isset($rows[($i+1)])?$rows[($i+1)]['image']:''; // incase there is no next image } include 'exampleclose.php'; ?> Link to comment https://forums.phpfreaks.com/topic/59986-php-mysql-help/#findComment-298352 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.