TechArena Community

TechArena Community (http://forums.techarena.in/)
-   Software Development (http://forums.techarena.in/software-development/)
-   -   php/mysql select problem (http://forums.techarena.in/software-development/1276827.htm)

Fragman 30-11-2009 02:43 PM

php/mysql select problem
 
Hi
I am new to php and I have query. I want the database to store the available amount of a product and list it in the select list. The number should be stored in the database so that I can retrieve it later. I have posted my code below check it out.
Code:

<?php
mysql_connect("localhost");
mysql_select_db("db");
$sql = "SELECT * FROM store";
$rs = mysql_query($sql);
while($row = mysql_fetch_array($rs))
{
$p = $row[p];
$av = $row[av];
$price = $row[price];
echo "<tr>
<td>$p</td>
<td><select name=".$choice.">";
for($i=0; $i<=$avilable; $i++)
{
echo "<option value=".$i." name=".$i.">$i</option>";
}
echo "<td >$price</td>
</tr>";
}
mysql_close();
?>


kelfro 30-11-2009 02:45 PM

Re: php/mysql select problem
 
Hi
Take a look at this example
Following is the HTML code
Code:

<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<select name="test[]" multiple="multiple">
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
<option value="four">four</option>
<option value="five">five</option>
</select>
<input type="submit" value="Send" />
</form>

Following is the PHP code
Code:

<?php
$test=$_POST['test'];
if ($test){
foreach ($test as $t){echo 'You select ',$t,'<br />';}
}
?>


Fragman 30-11-2009 02:50 PM

Re: php/mysql select problem
 
Hi
Thanks for the help. I am using multiple select statements, all information is stored in the database and then I retrieve them from the database.
Quote:

product1: <select>(select from 0 untill the quantity stored in DB): price
product2: <select>: price
product3: <select>: price
...
product n: <select>: price
Any help or suggestion.

kelfro 30-11-2009 02:52 PM

Re: php/mysql select problem
 
Hi
Is this what you want. Check the following code.
Code:

<?php
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("db") or die(mysql_error());

if(isset($_POST['submit'])) {
$choice = $_POST['choice'];
mysql_query("INSERT INTO tablename
(choice) VALUES('$choice') ")
or die(mysql_error());
}
$query = "SELECT * FROM store";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))  {
$p = $row[p];
$av = $row[av];
$price = $row[price];
?>
<form action="" method="post">
<?php
echo "<tr>
<td>$p</td>
<td><select name='$choice'>";
for($i=0; $i<=$avilable; $i++)
{
echo "<option value='$i' >$i</option>";
}
echo "<td >$price</td>
</tr>";
}
?>

This may help you. If any more queries then do post back.


All times are GMT +5.5. The time now is 03:13 AM.