Jump to content

while loop inside function


arunpatal

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/287420-while-loop-inside-function/
Share on other sites

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);

?>
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

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.