Jump to content

while loop inside function


Go to solution Solved by 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

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.