Hi,
I was wondering if someone could help me out?
I am trying to display the 5 latest rows in my database.
Whenever I add a new entry it will replace one the divs.
The issue is I want slider$v variable to count down from 1-5 because it would be displayed 5 times. From what I understand that would be a for loop? But I am not sure.
If someone could help me it would be appreciated.
Thanks

Here is what I have so far.

//Slideshow Content
$e = mysql_query("SELECT * from table WHERE catid = 38  ORDER BY catid DESC LIMIT 5")or die (mysql_error());
while ($row = mysql_fetch_array($e)) {
$slider_pid = $row['catid'];
$slider_title = $row['title'];
$slider_desc = $row['metadesc'];
$slider_introtext = $row['introtext'];

echo ("<table><tr><td class=\"slider$v\">$slider_title<td></td></table>");

}
?>

Hi apollokid,

Below is some example code that should help you out. You need to choose a different column to order your data by. At the moment you are only selecting items which have a 'catid' of 38 - then you're trying to order the results by 'catid'. If all your results have a 'catid' of 38, you won't affect the order with your current 'order by' statement. Try adding a timestamp or datetime column in your database and use this to order your results.

/* Table name */
$tbl_name = "my_table";

/* Retreive slideshow items from database */
$sql = "SELECT * FROM $tbl_name 
WHERE catid = 38 
ORDER BY datetime DESC LIMIT 5";
$result = mysql_query($sql) or die ('Error, query failed');

/* Create associate array from results */
for( $i=1 $i <= mysql_num_rows($result); $i++ ) {
	/* Create an array for each row in the database, e.g. $arr['title'] */
	$arr = mysql_fetch_assoc($result);
	/* Echo your data ( td class will start 'slider1 -> slider5' ) */
	echo '<table><tr><td class="slider$i">'.$arr["title"].'<td></td></table>';
}

All the best

Jim :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.