0

I've done this :-

    $qry=mysql_query("SELECT client.resID, menu.name FROM client INNER JOIN menu ON   
    client.resID = menu.resID WHERE client.resID = $resID");

    $row=mysql_fetch_array($qry);

    echo $row['name'];

}

?>
<form action="client_admin_post.php" method="post" enctype="multipart/form-data" name="form1" id="form1">


<p>Services &nbsp;&nbsp;:
<label for="cat"></label>
<input type="text" name="name" id="name" value="<?php echo $row['name']; ?>" />
</p>


<p align="center">
<input type="submit" name="Submit" id="Submit" value="Submit" />
</p>
</form>

I'm building a php form that fetch data from MySQL table. It's for editing the data in MySQL table. The problem is now, let's say, there are many menus in a restaurant. So, in this case, there are many rows in 'menus' MysQL table with same restaurantID(pk). I need to fetch all the menus to 5 fields. With this code, I can only fetch a menu only. How could I do that?

Thank you :D Thank you

4

2 に答える 2

0

IDを削除したので、重複するIDはありません。名前の入力にIDが必要な場合は、ループごとに増分変数を追加するのが最適です。例:「name1」、「name2」など。

<form action="client_admin_post.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
    <?php
    $qry = mysql_query("SELECT client.resID, menu.name FROM client INNER JOIN menu ON client.resID = menu.resID WHERE client.resID = $resID");

    while($row = mysql_fetch_assoc($qry))
    {
        ?>
        <p>
            Services &nbsp;&nbsp;:
            <label for="cat"></label>
            <input type="text" name="name" value="<?php echo $row['name']; ?>" />
        </p>
        <?php
    }
    ?>
    <p align="center">
        <input type="submit" name="Submit" id="Submit" value="Submit" />
    </p>
</form>
于 2012-12-03T15:29:42.337 に答える
0

You simply need to loop over your result set. Something like this should work

$names = array(); //array to store all names

while ($row = mysql_fetch_array($qry)) { // loop as long as there are more results
    $names[] = $row['name'];  // push to the array
}

print_r($names);    // $names array now contains all names
于 2012-12-03T15:19:39.860 に答える