php - How do I echo items from a mysql into a html table? -


hello trying echo items mysql table html table code:

    <?php         $host="localhost";         $username="root";         $password="";         $db_name="content_management";          $tbl_name="houses";          mysql_connect("$host", "$username", "$password")or die("cannot connect");          mysql_select_db("$db_name")or die("cannot select db");          $sql = "select * $tbl_name";         $result=mysql_query($sql);          while ( $row = mysql_fetch_assoc($result) ) {             echo "<img src='" . $row['picture'] . "'>";                 echo $row['price'];                 echo $row['type'];             echo $row['location'];             echo $row['description'];         }     ?> 

i want echo picture, price, type, location , description of house.

i have tried using various ways (which of them didn't work unless screwed somewhere) can give me recommendations should use?

<?php   echo item();      function item()  {     $html='';     $host="localhost";     $username="root";     $password="";     $db_name="content_management";      $tbl_name="houses";      mysql_connect("$host", "$username", "$password")or die("cannot connect");      mysql_select_db("$db_name")or die("cannot select db");      $sql = "select * $tbl_name";     $result=mysql_query($sql);      $html .="<table>";     while ( $row = mysql_fetch_assoc($result) )    {         $html .="<tr><td><img src='" . $row['picture'] . "'></td>";        $html .="<td>".$row['price']."</td>";        $html .="<td>".$row['type']."</td>";        $html .="<td>".$row['location']."</td>";        $html .="<td>".$row['description']."</td></tr>";      }  $html .="</table>";  return $html; } ?> 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -