mercredi 5 août 2015

Send ID instead Name in PHP and MYSQL


i want to send ID to database table instead of Name. but i want to show Name in a field instead of ID. it work's well while i send it through combo box. but i don,t know how it work with Search field. the php code is given below:

<font> <b>Name: </b></font>
<?php

include("database/db.php");

if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}

$sql = "SELECT *  FROM table";

$result = $link->query($sql); ?>
<select name="ID">
<?php
if ($result->num_rows > 0) {
     // output data of each row
     while($row = $result->fetch_assoc()) {
         $ad_id = $row["ID"];
          $name= $row['Name'];
           ?>
       <option  value="<?php echo $ad_id; ?>"><?php echo  $name; ?></option>


<?php
     }
} else {
     echo "0 results";
}

// close connection
mysqli_close($link);
?> 
</select>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire