Results 1 to 4 of 4

Thread: php/mysql select problem

  1. #1
    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();
    ?>

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    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 />';}
    }
    ?>

  3. #3
    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.
    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.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    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.

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,021,058.74636 seconds with 16 queries