Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I echo the contents of a MySQL table field?
    primarykey
    data
    text
    <p>I seem to be having trouble understanding the concept of how to properly use the information in a MySQL database using PHP/MySQLi. As I understand it, you generate a variable representing the connection object:</p> <pre><code>$connectionObject = mysqli_connect('serverString', 'userString', 'passString', 'databaseString'); </code></pre> <p>then, generate a variable representing the query string you want to use:</p> <pre><code>$queryString = "SELECT rowName FROM tableName"; </code></pre> <p>then, generate a variable representing the result object returned from a successful query:</p> <pre><code>$resultObject = mysqli_query($connectionObject, $queryString); </code></pre> <p>then, you use the fetch_assoc() function to generate an array from the result object and assign it to a variable:</p> <pre><code>$resultArray = myqli_fetch_assoc($resultObject); </code></pre> <p>then, you can use a while loop to (I have trouble with this one) to sort through the array and use the content of the row somehow:</p> <pre><code>while ($resultArray) { echo $resultArray["rowName"]; } </code></pre> <p>Do I have this concept the wrong way, somehow, because its just not working for me, even to output the text content of a text-based CHAR(10) field with the contents of no more than: "BLAH".</p> <p>The need to loop through the array to pick out the array item by name in the end anyway seems moot to me to begin with, but no matter where I look, I find the same concept.</p> <p>My script code, minus a few key details, is:</p> <pre><code>if ($connectionObject=mysqli_connect("host0", "username0", "password0", "mysqldatabase0")) { echo "Con"; } if ($queryString="SELECT 'testdata' FROM 'testtable'") { echo "Query"; } if ($resultObject=mysqli_query($connectionObject, $queryString)) { echo "Result"; } if ($resultArray=mysqli_fetch_assoc($resultObject)) { echo "Array"; } while ($row=$resultArray) { echo $row["testdata"]; print_r ($row); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload