0

stock.php

    <td>Produk  :</td><br>
            <td>
              <select name="batch" onchange="submit();">
                <option value="-1" >-- Select Address --</option>
                <?php

                $username='root';
                $password='';

                $con = mysql_connect('localhost', $username, $password);
                mysql_select_db('snack', $con);

                $result = mysql_query("SELECT * FROM po");

                while($row = mysql_fetch_array($result))
                {
                }


                $data = array(
                '1'=>array('po'=>'1','namn'=>'name 1'),
                '2'=>array('po'=>'2','namn'=>'name 2'),
                '3'=>array('po'=>'3','namn'=>'name 3'),
                '4'=>array('po'=>'4','namn'=>'name 4'),
                '5'=>array('po'=>'5','namn'=>'name 5')
                );
                foreach($data as $item){
                echo "<option value='{$item['po']}'>{$item['namn']}</option>\r\n";
                }
                ?>
            </select>
            </td>    

What should I replace this with?

while($row = mysql_fetch_array($result))
                {
                }

I basically need to see the combo box filled with items from sql_query.

If anyone can help me fix the code, would be great.

4
Contributors
7
Replies
11
Views
4 Years
Discussion Span
Last Post by radhakrishna.p
0

place the following code after line 16

echo "<option value='".$row['po']."'>".$row['name']."</option>";

as arti18 said i dont know what your are going to place into your combobox

if you go like that then your database values will be plcaed into the combox

let me know if this is your answer or not

happy coding

Edited by radhakrishna.p: clarity on the solution

0
      <?php
    $username='root';
    $password='';
    $con = mysql_connect('localhost', $username, $password);
    mysql_select_db('snack', $con);
    $result = mysql_query("SELECT * FROM po");
    ?>


     <td>Produk :</td><br>
    <td>
    <select name="batch" onchange="submit();">
    <option value="-1" >-- Select Address --</option>
  <?php 
    while($row = mysql_fetch_array($result))
    {
       ?>  
       <option value="<?php echo $row['field name'];?>">
        <?php echo $row['field name'];?></option>


    <?php } ?>

    </select>
    </td> 

try this put your field name in row index
warning:not tested

0

This error appears:

Notice: Undefined index: filed name in C:\xampp\htdocs\Innovation\script_shop\stock.php on line 51

line 51: <?php echo $row['field name'];?></option>

0

Notice: Undefined index: filed name in C:\xampp\htdocs\Innovation\script_shop\stock.php
are your prefering from arti18 code? did you just copied the error above cause i notice

filed name instead of field_name its either you mispelled it or the columns doesnt match

0

hai davy_yg

replace that 'field name' with column's name of the table what you are trying to place the values into combo box

Edited by radhakrishna.p: nothing

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.