smc Posted February 4, 2007 Share Posted February 4, 2007 Hello, For some reason my code isn't returning anything to the page. After this code I've required my HTML template, and in the HTML template it has <?php echo_results(); ?> to call the function. function echo_results() { global $display; $display = ' <img border=\"0\" src=\"../images/block.jpg\" width=\"9\" height=\"10\"><font size=\"2\"><b><br>" . [TITLE] . "</b></font><br /> '; $fido_rest = mysql_query("SELECT * FROM stories WHERE id != '$top_id' AND id != '$h1_id' AND id != '$h2_id' AND status = 'approved' AND section = '$section' ORDER BY date DESC") or die ( mysql_error() ); while ( $call = mysql_fetch_array($fido_rest) ) { $title = $call['title']; } $temp = $display; $temp = str_replace("[TITLE]", $title, $temp); $results .= $temp; return $results; } I replaced the sql function with ("SELECT * FROM stories WHERE status = 'approved'"); and that didn't work/return anything eithier. I'm not getting any errors so I'm completly clueless. Help! Link to comment https://forums.phpfreaks.com/topic/36972-solved-mysql-function-isnt-returning-anything/ Share on other sites More sharing options...
smc Posted February 4, 2007 Author Share Posted February 4, 2007 I narrowed it down to not being able to call variables from outside of a function in a function, any way I can get around this problem? Link to comment https://forums.phpfreaks.com/topic/36972-solved-mysql-function-isnt-returning-anything/#findComment-176465 Share on other sites More sharing options...
Jessica Posted February 4, 2007 Share Posted February 4, 2007 In order to do that, inside the function you must use global $foo; This is called variable scope: http://us2.php.net/manual/en/language.variables.scope.php Link to comment https://forums.phpfreaks.com/topic/36972-solved-mysql-function-isnt-returning-anything/#findComment-176466 Share on other sites More sharing options...
smc Posted February 4, 2007 Author Share Posted February 4, 2007 Yup that's it exactly. Thanks!! Link to comment https://forums.phpfreaks.com/topic/36972-solved-mysql-function-isnt-returning-anything/#findComment-176499 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.