Jump to content

alternatives to 'return' method (so I don't print result)


maxdean10

Recommended Posts

I am trying to do the following. Except I know that 'return' is not the right method to use, as it stops the script, so what ends up happening is only one row is returned, instead of the three that are there. With return, the data is being passed without being immediately printed, and I end up with the data (but not all of it, because the script stops) in correct place in the page.

 

If I replace return () with echo(), it works fine, in terms of returning the correct data.

 

However, with the way things are setup, if I use echo, the results print at the head of my page. I am using function CreateSideMenu to establish the values for content, and then another function, later on the index.php page, actually creates the page. So what I need is to have something, similar to return (), that passes the information on, but does not immediately print it.

 

Do I make sense?

 

see code below:

 

function CreateSideMenu ()	{ // open CreateSideMenu function
	include ('/Users/max/Sites/rdbase-llc/hidden/defin/kinnect01.php');

	$query = "SELECT content_element_title, content_element_short_text FROM content_main";
	$result = mysql_query ($query, $dbc);



	while ($row = mysql_fetch_array ($result, MYSQL_ASSOC))	{

	return ("<p>" . $row[content_element_title] . "</h2>\n<p>" . $row[content_element_short_text] .  "</p>");

														}

 

Thanks ahead of time.

You need to collect all the responses and then return the result:

<?php
function CreateSideMenu ()	{ // open CreateSideMenu function
include ('/Users/max/Sites/rdbase-llc/hidden/defin/kinnect01.php');
$query = "SELECT content_element_title, content_element_short_text FROM content_main";
$result = mysql_query ($query, $dbc);
$tmp = array();
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC))	{
	$tmp[] = "<p>{$row['content_element_title']}</h2>\n<p>{$row['content_element_short_text']}</p>";
}
return (implode("\n",$tmp) . "\n");
}
?>

 

Ken

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.