PHP echoing MySQL data into HTML table -


so i'm trying make html table gets data mysql database , outputs user. i'm doing php, i'm extremely new to, please excuse messy code!

the code i'm using is: braces storm of "your code awful!"

<table class="table table-striped table-hover ">     <thead>     <tr>         <th>#</th>         <th>name</th>         <th>description</th>         <th>reward</th>         <th>column heading</th>     </tr>     </thead>     <tbody>     <?php         $con = mysql_connect("localhost", "notarealuser", 'notmypassword');         ($i = 1; $i <= 20; $i++) {             $items = ($mysqli->query("select id `items` id = $i"));             echo ("<tr>");             echo ("                 <td>                 while ($db_field = mysqli_fetch_assoc($items)) {                     print $db_field['id'];                 }</td>");             $items = ($mysqli->query("select name `items` id = $i"));             echo ("                 <td>                 while ($db_field = mysqli_fetch_assoc($items)) {                     print $db_field['name'];                 }</td>");             $items = ($mysqli->query("select descrip `items` id = $i"));             echo ("                 <td>                 while ($db_field = mysqli_fetch_assoc($items)) {                     print $db_field['descrip'];                 }</td>");             $items = ($mysqli->query("select reward `items` id = $i"));             echo ("                 <td>                 while ($db_field = mysqli_fetch_assoc($items)) {                     print $db_field['reward'];                 }</td>");             $items = ($mysqli->query("select img `items` id = $i"));             echo ("                 <td>                 while ($db_field = mysqli_fetch_assoc($items)) {                     print $db_field['img'];                 }</td>");             echo ("</tr>");         }     ?>     </tbody> </table> 

however, code not working - causes page output immediate 500 internal server error. iis logs show 500:0 - generic ise. ideas?

you mixing mysql , mysqli, not closing php code block , not selecting database. plus don't have run query each field

try this:

<table class="table table-striped table-hover ">     <thead>         <tr>             <th>#</th>             <th>name</th>             <th>description</th>             <th>reward</th>             <th>column heading</th>         </tr>     </thead>      <tbody>         <?php             $con = new mysqli("host","user", "password", "database");              $execitems = $con->query("select id, name, descrip, reward, img `items` id between 1 , 20 ");              while($infoitems = $execitems->fetch_array()){                 echo    "                             <tr>                                 <td>".$infoitems['id']."</td>                                 <td>".$infoitems['name']."</td>                                 <td>".$infoitems['descrip']."</td>                                 <td>".$infoitems['reward']."</td>                                 <td>".$infoitems['img']."</td>                             </tr>                         ";              }         ?>     </tbody> </table> 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -