The program below is just a simple test to see if I can get it to fetch the correct data from MariaDB and then display it on the screen but so far I'm not having any luck. I left the action attribute's value blank because I want the PHP form processing to be executed in the same page. I'm trying to get $name & $tdoc to display on the screen. $tdoc is the data I use to select the correct row and then I'd like to display that along with $name. Thanks for any and all replies.

<?php
     // open a DB connectiong
     $servername = "localhost";
     $username = "username";
     $password = "password";

     $connection = new mysqli($servername, $username, $password, "popcount");

     // check connection
     if($connection->connect_error)
    {
        die("Connection Failed!: " . $connection->connect_error);
    }
?> <html> <form name='tdoc' method='post'>
        Please Enter Inmate TDOC# <input type='text' /> <input type='submit' /> </form> </html> <?php
        $tdoc = $_POST["tdoc"];
        $name = $connection->query("SELECT full_name FROM inmate_board WHERE tdoc_number = $tdoc");
        echo "$name<br />";
        echo "$tdoc";
?> 

Hi,

you have to fetch the results, fetch_all() will return the entire result set:

$result = $name->fetch_all(MYSQLI_ASSOC);
print_r($result);

While fetch_array() will return one row, and in order to get the orders you have to loop:

while($row = $name->fetch_assoc()) {
    echo $row['full_name'];
}

Or move the internal pointer through field_seek() . Check the mysqli_result class for more methods:

I only want to get the row that matches the specific field. Woundn't it be easier to use fetch_assoc() for that? When using fetch_all() is it fetching the whole table? If so what format is that in and how do you get the data you want out of it? Thanks.

You can set the result type for fetch_all() which is defined by MYSQLI_ASSOC, MYSQLI_NUM, or MYSQLI_BOTH as explained here and as shown in my previous example:

In any of these cases it will return an array. If for example you would access only the first entry, then you would write:

$rows = $name->fetch_all(MYSQLI_ASSOC);
echo $rows[0]['full_name'];

When using fetch_all() is it fetching the whole table?

It returns only what you have defined in your query, but you get an array with the entire result set. The fetch_array() method instead returns only the first row of the result set, by looping as shown in the example you access all the other entries.

You can test it, do simply:

$row = $name->fetch_assoc();
echo $row['full_name'];

# move internal pointer to get another row
$name->data_seek(2);

$row = $name->fetch_assoc();
echo $row['full_name'];

The same is done, automatically, by the loop.

Now how do I mark as solved? Also when making a post where did all the sub groups go, PHP, HTML/CSS, etc... go?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.