maxdean10 Posted February 13, 2011 Share Posted February 13, 2011 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. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 13, 2011 Share Posted February 13, 2011 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 Quote Link to comment Share on other sites More sharing options...
maxdean10 Posted February 13, 2011 Author Share Posted February 13, 2011 Thank you kenrbnsn. I am so rusty with php that I had completely forgotten about several elements of your solution. It works great now! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.