Select option menu read from database and use it's values



PHP Snippet 1:

<?php
mysql_connect("localhost", "root","") or die(mysql_error());
mysql_select_db("tnews2") or die(mysql_error());

$query = "SELECT name,id,path FROM categories ORDER BY ID DESC LIMIT  0,6";
$result = mysql_query($query) or die(mysql_error()."[".$query."]");
?>

<select name="categories">
<?php 
while ($row = mysql_fetch_array($result))
{
    echo "<option value='".$row['path']."'>'".$row['name']."'</option>";
}
?>        
</select>

PHP Snippet 2:

<?php
/* Database connection settings */
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'tnews2';
$mysqli = new mysqli($host,$user,$pass,$db) or die($mysqli->error);

/* Your query */
$result = $mysqli->query("SELECT name,id,path FROM categories ORDER BY ID DESC LIMIT  0,6";) or die($mysqli->error);
?>

PHP Snippet 3:

<select name="categories">
    <option value="Select School">Select Shool</option>
    <?php
    while ($row = mysqli_fetch_array($result)) {
        echo "<option value='" . $row['path'] . "'>'" . $row['name'] . "'</option>";
    }
    ?>        
</select>

PHP Snippet 4:

<?php
  include("conect.php");
  if ($db) { 
     $res=mysql_query("select bolao_concurso,bolao_data from Bolao");
     if ($res) {
        $lin_inic=1;
        $lines=mysql_num_rows($res);
        echo "<select name='conc'>";
        echo "<p>YOUR CHOICE : ";
        while ($lin_inic<=$linesS) {
              $row=mysql_fetch_array($res);
              $concurso =$row['bolao_concurso'];
              $data_conc=$row['bolao_data'];
              echo "<option value='$concurso'>$concurso $data_conc</option>";
              $lin_inic=$lin_inic+1;
        }
        echo "</select>";
     }
   }
?>

PHP Snippet 5:

$query = "SELECT path, name, id FROM categories ORDER BY ID DESC LIMIT  0,6";

echo "<option value='".$row[0]."'>'".$row[1]."'</option>";