arunpatal Posted March 31, 2014 Share Posted March 31, 2014 function display_sql_list($table_name){ $display = mysqli_query($this->connect,"SELECT * FROM $table_name") or die (header("location:error1")); while ($result = mysqli_fetch_assoc($display)){ $results[] = $result["name"]; } return $results; } The code above returns error Notice: Array to string conversion in pages\booking_list.php on line 5 Array What is wrong? Quote Link to comment https://forums.phpfreaks.com/topic/287420-while-loop-inside-function/ Share on other sites More sharing options...
Ch0cu3r Posted March 31, 2014 Share Posted March 31, 2014 (edited) The code for the function is fine, it returns an array of names. The error is produced line 5 of booking_list.php. What are you doing on that line? Post the first 5 lines of code from that file. Edited March 31, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/287420-while-loop-inside-function/#findComment-1474533 Share on other sites More sharing options...
arunpatal Posted March 31, 2014 Author Share Posted March 31, 2014 The code for the function is fine, it returns an array of names. The error is produced line 5 of booking_list.php. What are you doing on that line? Post the first 5 lines of code from that file. This is booking_list.php page <?php $mysql = new viks2007(); $design = new design(); echo $mysql->display_sql_list($bookpage_table_name); ?> Quote Link to comment https://forums.phpfreaks.com/topic/287420-while-loop-inside-function/#findComment-1474539 Share on other sites More sharing options...
arunpatal Posted March 31, 2014 Author Share Posted March 31, 2014 function display_sql_list($table_name){ $display = mysqli_query($this->connect,"SELECT * FROM $table_name") or die (header("location:error1")); while ($result = mysqli_fetch_assoc($display)){ echo $result["name"]; } } Using like this work fine Quote Link to comment https://forums.phpfreaks.com/topic/287420-while-loop-inside-function/#findComment-1474541 Share on other sites More sharing options...
Ch0cu3r Posted March 31, 2014 Share Posted March 31, 2014 You cannot echo an array. Maybe use $names = $mysql->display_sql_list($bookpage_table_name); echo implode(',', $names); // OR, echo names into a HTML list echo '<ul><li>' . implode('</li><li>', $names) . '</li></ul>'; Quote Link to comment https://forums.phpfreaks.com/topic/287420-while-loop-inside-function/#findComment-1474542 Share on other sites More sharing options...
Solution arunpatal Posted March 31, 2014 Author Solution Share Posted March 31, 2014 You cannot echo an array. Maybe use $names = $mysql->display_sql_list($bookpage_table_name); echo implode(',', $names); // OR, echo names into a HTML list echo '<ul><li>' . implode('</li><li>', $names) . '</li></ul>'; Worked Thanks Quote Link to comment https://forums.phpfreaks.com/topic/287420-while-loop-inside-function/#findComment-1474547 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.