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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.