Note that there are some explanatory texts on larger screens.

plurals
  1. POmysql empty rows
    primarykey
    data
    text
    <p>I have created a simple MYSQL database to store user information (id, FirstName, LastName) and filled it with 3 names:</p> <pre><code>id | FirstName | LastName 1 | Sam | Heyman 2 | Ben | Eliott 3 | Al | Readman </code></pre> <p>When I try and display the contents of the database in a table on my page, I get the correct number of rows but the cells are void.</p> <pre><code>User id | First Name | Last Name | | | | | | </code></pre> <p>If I do </p> <pre><code>var_dump($rows) </code></pre> <p>I get the following:</p> <pre><code>array(6) { [0]=&gt; string(1) "1" ["id"]=&gt; string(1) "1" [1]=&gt; string(3) "Sam" ["FirstName"]=&gt; string(3) "Sam" [2]=&gt; string(6) "Heyman" ["LastName"]=&gt; string(6) "Heyman" } array(6) { [0]=&gt; string(1) "2" ["id"]=&gt; string(1) "2" [1]=&gt; string(3) "Ben" ["FirstName"]=&gt; string(3) "Ben" [2]=&gt; string(6) "Eliott" ["LastName"]=&gt; string(6) "Eliott" } array(6) { [0]=&gt; string(1) "3" ["id"]=&gt; string(1) "3" [1]=&gt; string(8) "Alastair" ["FirstName"]=&gt; string(8) "Alastair" [2]=&gt; string(7) "Readman" ["LastName"]=&gt; string(7) "Readman" } </code></pre> <p>So why are my cells empty? I have done many databases before and have never had this problem before. Having spent 3 hrs looking on google, I've given up.</p> <p>This is the code:</p> <pre><code>&lt;?php // Connect to server and select database. $dbcnx = @mysql_connect('server','user','pw'); mysql_query('SET NAMES utf8;'); mysql_select_db('db', $dbcnx); // Fetch all the users from the database $users = @mysql_query('SELECT * FROM registered_users'); ?&gt; &lt;table width="400" border="1" cellspacing="0" cellpadding="3" style="color:red;"&gt; &lt;tr&gt; &lt;th&gt;User ID&lt;/th&gt; &lt;th&gt;First name&lt;/th&gt; &lt;th&gt;Last name&lt;/th&gt; &lt;/tr&gt; &lt;?php // Start looping through the rows in mysql database. while($rows=mysql_fetch_array($users)){ var_dump($rows); echo"&lt;br /&gt;"; ?&gt; &lt;tr&gt; &lt;td&gt;&lt;? echo $rows['id']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;? echo $rows['FirstName']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;? echo $rows['LastName']; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php // close while loop } ?&gt; &lt;/table&gt; &lt;?php // close MySQL connection mysql_close(); ?&gt; </code></pre>
    singulars
    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