Jump to content

PHP MySQL Help..


itsureboy

Recommended Posts

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

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.