How get all values in a column using PHP?

前端 未结 6 1248
悲&欢浪女
悲&欢浪女 2020-11-28 09:10

I\'ve been searching for this everywhere, but still can\'t find a solution: How do I get all the values from a mySQL column and store them in an array?

For eg: Tab

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 09:54

    First things is this is only for advanced developers persons Who all are now beginner to php dont use this function if you are using the huge project in core php use this function

    function displayAllRecords($serverName, $userName, $password, $databaseName,$sqlQuery='')
    {
        $databaseConnectionQuery =  mysqli_connect($serverName, $userName, $password, $databaseName);
        if($databaseConnectionQuery === false)
        {
            die("ERROR: Could not connect. " . mysqli_connect_error());
            return false;
        }
    
        $resultQuery = mysqli_query($databaseConnectionQuery,$sqlQuery);
        $fetchFields = mysqli_fetch_fields($resultQuery);
        $fetchValues = mysqli_fetch_fields($resultQuery);
    
        if (mysqli_num_rows($resultQuery) > 0) 
        {           
    
            echo "";
            echo "";
            foreach ($fetchFields as $fetchedField)
             {          
                echo "";
            }       
            echo "";
            while($totalRows = mysqli_fetch_array($resultQuery)) 
            {           
                echo "";                                
                for($eachRecord = 0; $eachRecord < count($fetchValues);$eachRecord++)
                {           
                    echo "";               
                }
                echo "";
                echo "";
                echo "";           
            } 
            echo "
    "; echo "" . $fetchedField->name . ""; echo "
    "; echo $totalRows[$eachRecord]; echo "
    "; } else { echo "No Records Found in"; } }

    All set now Pass the arguments as For Example

    $queryStatment = "SELECT * From USERS "; $testing = displayAllRecords('localhost','root','root@123','email',$queryStatment); echo $testing;

    Here

    localhost indicates Name of the host,

    root indicates the username for database

    root@123 indicates the password for the database

    $queryStatment for generating Query

    hope it helps

提交回复
热议问题