display details from multiple drop down

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
scenic
Forum Newbie
Posts: 7
Joined: Mon Dec 01, 2008 4:19 am

display details from multiple drop down

Post by scenic »

Hello...

i need some help from u guys....actually
i have two dynamic drop down list. one is "category" and other is "item"..drop down lists are working fine...but i want is...that when i am selecting value from second drop down...it should be display details of that particular item...

but it doen't...how can i do this....plz help me..
plz see the code below:

Code: Select all

 
<SCRIPT language="JavaScript">
function reload(form){
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='delete_item.php?cat=' + val;
}
function confirmDelete()
{
    return confirm("Are you sure you wish to delete this entry?");
} 
</script>
</head>
<?php
include('dbconnect.php');
$category=$_GET['cat'];
$item=$_GET['item'];
$item_id=$_POST['Item_id'];
$item_color=$_POST['Item_color'];
$image=$_FILES['file']['tmp_name'];
        $fp = fopen($image, 'r');
        $content= 'items/'. $file_name;
$query="select category_name from category_table";
$res=mysql_query($query);
?>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="get" enctype="multipart/form-data">
<label for="cat_name">Category Name : </label>&nbsp;
        <select name="cat" id="cat" onchange="reload(this.form);">
            <option value="selectcategory">Select Category</option>
            <?php
            while($arr=mysql_fetch_array($res))
                {               
                echo "<option value=\"$arr[0]\""; if ($arr[0]==$category) echo 'selected'; echo ">". $arr[0] ; echo "</option>";
                 } 
            ?>
        </select>
        
<label for="name">Name : </label>&nbsp;     
    <select name="item" id="item" >
         <option value="selectitem">Select Item</option>
    <?php 
    if(isset($category))
        {
        $sql="select distinct Item_code from item_table where Item_category='$category'"; 
        $res1=mysql_query($sql);
            while($arr1=mysql_fetch_array($res1))
            {
            echo "<option value=$arr1[0]> $arr1[0] </option>";
            } 
        }
    ?>
</select><br /><br />   
 
<?php
    if(isset($item))
        {
        $sql1="select * from item_table where Item_code='$item'";
        $res2=mysql_query($sql1);
        
            while($arr2=mysql_fetch_array($res2))
            {
            echo "Item ID : <input name='item_id' value='$arr2[0]' disabled='disabled' /><br /><br />";
            echo "Item Code : <input value= '$arr2[1]' /><br /><br />";
            echo "Item Color : <input name='item_color' value='$arr2[2]' /><br /><br />";
            echo "Item Image : <img value='$arr2[3]' src='$content' width='50px' height='50px' /><br /><br />";
            echo "Item Category : <input value='$arr2[4]'  /><br /><br />";
            }
        }
    ?>
<input type="submit" name="delete" value="Delete Item"  onclick="return confirmDelete();"/>
<input type="reset" name="Cancel" value="Cancel"  />
</form>
<?php
if(isset($_REQUEST['delete']))
    {
    $sql2="DELETE FROM item_table WHERE Item_code='$item'";
    $res3=mysql_query($sql2);
    echo "<br>";
    echo "Item Deleted"; 
    } 
    
?>
 
Last edited by scenic on Mon Dec 01, 2008 4:52 am, edited 1 time in total.
mintedjo
Forum Contributor
Posts: 153
Joined: Wed Nov 19, 2008 6:23 am

Re: display details from multiple drop down

Post by mintedjo »

quick! edit it and put it in tags!
scenic
Forum Newbie
Posts: 7
Joined: Mon Dec 01, 2008 4:19 am

Re: display details from multiple drop down

Post by scenic »

ok...
i have correct it....

now, can anyone help me in this...
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: display details from multiple drop down

Post by watson516 »

You want to change the content of the second drop down list depending on what is selected in the first? Thats javascript.
scenic
Forum Newbie
Posts: 7
Joined: Mon Dec 01, 2008 4:19 am

Re: display details from multiple drop down

Post by scenic »

no sir.... drop down lists are working perfectly.....

what i want is....
after selecting value from both drop down....the details should be display of that selected value..
for example ::....
i have two drop down list....one is for category and another is for items....
when we select value from category. changes affected in the second drop down....ok...
so both drop down are working perfect.....

now i want that...when i m selecting an item from second drop down.....the details of that items should be display...... after that....when the details open......i want to edit the details accordingly with update statement.....
please help me to do that.....and see my code given below

Code: Select all

 
<title>Update Item</title>
</head>
<SCRIPT language="JavaScript">
function reload(form){
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='modify_item.php?cat=' + val;
}
</script>
</head>
<?php
include('dbconnect.php');
$category=$_GET['cat'];
$item=$_GET['item'];
print_r($item);
$query="select category_name from category_table";
$res=mysql_query($query);
?>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="get" enctype="multipart/form-data">
<label for="cat_name">Category Name : </label>&nbsp;
        <select name="cat" id="cat" onchange="reload(this.form);">
            <option value="selectcategory">Select Category</option>
            <?php
            while($arr=mysql_fetch_array($res))
                {               
                echo "<option value=\"$arr[0]\""; if ($arr[0]==$category) echo 'selected'; echo ">". $arr[0] ; echo "</option>";
                 } 
            ?>
        </select>
        
<label for="name">Name : </label>&nbsp;     
    <select name="item" id="item" >
         <option value="selectitem">Select Item</option>
    <?php 
    if(isset($category))
        {
        $sql="select distinct Item_code from item_table where Item_category='$category'"; 
        $res1=mysql_query($sql);
            while($arr1=mysql_fetch_array($res1))
            {
            //echo "<option value=\"$arr1[0]\""; if ($arr1[0]==$item) echo 'selected'; echo ">" .$arr1[0] ; echo "</option>";
            echo "<option value=$arr1[0]> $arr1[0] </option>";
            } 
        }
    ?>
</select><br /><br />   
 
<?php
$item_id=$_POST['item_id'];
$item_color=$_POST['item_color'];
$image=$_FILES['file']['tmp_name'];
        $fp = fopen($image, 'r');
        $content= 'items/'. $file_name;
    
    if(isset($item))
        {
        $sql1="select * from item_table where Item_code='".$item."'";
        $res2=mysql_query($sql1);
        
            while($arr2=mysql_fetch_array($res2))
            {
            echo "Item ID : ";
            echo "<input name='item_id' value='".$arr2[0]."' disabled='disabled' /><br /><br />";
            echo "Item Code : ";
            echo "<input value= '".$arr2[1]."' /><br /><br />";
            echo "Item Color : ";
            echo "<input name='item_color' value='".$arr2[2]."' /><br /><br />";
            echo "Item Image : ";
            echo "<img value='".$arr2[3]."' src='$content' width='50px' height='50px' /><br /><br />";
            echo "Item Category : ";
            echo "<input value='".$arr2[4]."'  /><br /><br />";
            }
        }
 
if(isset($_REQUEST['update']))
    {
    $sql2="update item_table set Item_code='".$item."', Item_color='".$item_color."', Item_image='".$content."', 
    Item_category='".$category."' where Item_id='".$item_id."'";
    $res3=mysql_query($sql2);
    //echo "<br>";
    //echo "Item Updated"; 
    } 
    
?>
 
<input type="submit" name="update" value="Update Item" />
<input type="reset" name="Cancel" value="Cancel"  />
</form>
</body>
</html>
 
Attachments
New Folder.zip
(3.78 KiB) Downloaded 55 times
Post Reply