Link to home
Start Free TrialLog in
Avatar of mrmut
mrmutFlag for Croatia

asked on

"Multiple" PHP return function?

Hello, please note I am beginner at PHP.

I have a function that I would like to return, instead of echo it (echo breaks code at certain point). However, I don't have a clue hot to build and output that as I have a foreach there. Pls. see an example, you will understand it easily.


function list_articles($condition, $number = 3, $indentation = 3)
	{
	if ($condition == "home")
		{
		$sql = "SELECT Date,Time,Article FROM Articles WHERE PUBLISHED = 1 ORDER BY Date DESC, Time DESC LIMIT " . $number;
		}
		//
	else if ($condition == "archive")
		{
		$sql = "SELECT Date,Time,Article FROM Articles WHERE PUBLISHED = 1 ORDER BY Date DESC, Time DESC";
		}
		//
	else if ($condition == "admin")
		{
		$sql = "SELECT Date,Time,Article FROM Articles ORDER BY Date DESC, Time DESC";
		}
		//
	else
		{
		return FALSE;
		}
	//
	//DB fetch, returns $result
	//
	$result = retrieve_from_database($sql); //Add another control here
	//
	// Print list
	//
	
	echo str_repeat("\t", $indentation) . "<ul>\n";
	foreach($result as $value)
		{
		echo str_repeat("\t", $indentation) . "\t<li>" . datetime_converter($value["Date"]) . " - " . $value["Article"] . "</li>\n";
		}
	echo str_repeat("\t", $indentation) . "</ul>";
	}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mrmut

ASKER

Yeah... The worst part of questions like these is that I know it is simple, but don't have a clue how to do it. Thanks a lot.