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.

Link to comment
Share on other sites

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

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.