Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



php/mysql select problem

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 30-11-2009
Member
 
Join Date: Nov 2008
Posts: 240
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();
?>

Reply With Quote
  #2  
Old 30-11-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
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 />';}
}
?>
Reply With Quote
  #3  
Old 30-11-2009
Member
 
Join Date: Nov 2008
Posts: 240
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.
Reply With Quote
  #4  
Old 30-11-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "php/mysql select problem"
Thread Thread Starter Forum Replies Last Post
Select to cascade ajax + mysql Sahira Software Development 6 25-10-2010 02:24 PM
PHP mysql select unique records from one table Captain Carrot Software Development 6 13-05-2010 12:18 PM
How to select multiple table in MySql Doroteo Software Development 4 05-11-2009 09:28 PM
MySQL query select all columns but exclude specific. RSeven Software Development 3 29-07-2009 09:26 PM
Mysql select from multiple tables for php. afidelino Software Development 4 09-07-2009 06:13 PM


All times are GMT +5.5. The time now is 01:15 PM.