Jump to content

[SOLVED] Looping from an array?


Solarpitch

Recommended Posts

Hey guys,

 

I've wrote this script that will pull the last 6 uploaded results in the database and return them via the function recentlyuploaded()

 

When I call this function it will contain the data from 6 results but the way I have it coded I am only assigning the first value of that array returned. How can I loop through the array that i returned and assign the 6 results to their respective variables?

 


// Script to get the last 6 uploaded properties to the site

function recentlyuploaded()
{
$row2 = array();
dbconnect();

$sql = "SELECT * FROM property_info WHERE DATE_SUB(NOW(), INTERVAL 7 DAY) < uploaded ORDER BY uploaded           DESC LIMIT 6";

$result = mysql_query($sql) or die(mysql_error());
while(($row = mysql_fetch_row($result)) != false) {
	$row2[] = $row;
}
return $row2;

}


// This is the code on the other page to retrieve the results

$result = recentlyuploaded();

foreach($result as $e)
{
	$property_id = $e[0];
	$getarea = $e[3];
	$location2= $e[2]; 

}

Link to comment
https://forums.phpfreaks.com/topic/77513-solved-looping-from-an-array/
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.