Jump to content

subcategory dropdown based on main category


srinivasa

Recommended Posts

thanks for your previous replies,

now am designing a page called add-product as a part of the project 'product management store'

my problem is how to design dropdown based on the previour dropdown selection (using php and mysql)

 

(i.e according to my database and table data

if i select electronic goods from category drop down i should be able to see only items pertained to electronic items in the second drop down menu

 

category - electonic goods

 

subcategory - laptops

computer

television

 

should be there...but in my design its showing all subcategories...i have attached my database file and add-product.php file for your review...plz reply soon.......................

 

AND also suggest me how to upload image and handling image

products.zip

add-product.php

Link to comment
Share on other sites

You don't have to use PHP. In fact, it may be better to use client-side processing as it's only applicable to the viewer who's looking at that page at the time.

 

This javascript chained select changes the options in the second box depending on what you selected in the first box, and similarly for the third.

http://www.dynamicdrive.com/dynamicindex16/chainedselects/index.htm

Link to comment
Share on other sites

i agree to you,please have a look at my code, i have to retrive data from mysql table to the form ,in my code i have successfully retrieved data from category table,am failing to retrieve data from subcategory table which should be based on the category selected item.....please help me

Link to comment
Share on other sites

i have uploaded add-product.php in my previous post and made some modificatiosns,also pasted part of the code with some modifications...for quick review

 

///category code part in add-product.php////

<!--product category-->

<tr>

<td style="font-family:verdana;color:gray;font-size:.8pc;font-weight:bold;"width = 50%>Product Category:</td>

<td width = 50%>

<?php

$ddone = @mysql_query("SELECT cat_id,cat_name FROM category");

echo "<select name = 'maincat'>";

while($row = mysql_fetch_assoc($ddone)){

$catid = $row['cat_id'];

$catname = $row['cat_name'];

echo "<option value = \"$catid\"> $catname </option>";

}

echo "</select>";

?>

</td>

</tr>

///ends here

 

 

 

///subcategory followed by above in php file

<!--product sub-category-->

<tr>

<td style="font-family:verdana;color:gray;font-size:.8pc;font-weight:bold;"width = 50%>Product Sub-category:</td>

<td>

<?php

$ddtwo = @mysql_query("SELECT cat_id,subcat_name FROM subcategory WHERE cat_id = $catid");

echo "<select name = 'subcat'>";

while($now = mysql_fetch_assoc($ddtwo)){

$subcatid = $now['subcat_id'];

$subcatname = $now['subcat_name'];

echo "<option value = \"$subcatid\">$subcatname</option>";

}

echo "</select>";

?>

</td>

</tr>

///subcategory ends here

 

 

 

now my problem is irrespective of main category selection it showing subcategory as tables and chairs but it shd change according to main category selection,plz have a look at my code and give me solution

(i have uploaded my database i.e products.sql in my previous post)

i think am failing in catching the first dropdown menu value or displaying in second dropdown ....

for my above result it must have always selecting cat_id as 4 it seems....

 

sir.............plz plz help me

Link to comment
Share on other sites

  • 1 year later...

How we use the sqlquery please tell me there was no error in this code but it does not fetch the data from database why ????

<?php

$myconnect=mysql_connect("localhost","root","")or die("does not connect to mysql");

$db=mysql_select_db('billsystem') or die('does not connect to database');

$result="select clientname from addclient";

$query=mysql_query($result,$myconnect);

?>

<form action="searchbyclientbillform11.php" method="post" style="margin-left:20px">

clientname:

<select name="clientname">

<?php

while($res=mysql_fetch_row($query))

{

foreach($res as $field)

{

//echo $field;

?>

<?php

//echo$field('month');?>

<option value="<?php echo $field; ?>"><?php echo $field; ?> </option>

<?php

}

echo"<br>";

 

//echo $res

}

?>

</select>

<input type="submit" name="sub" width="30%" value="show" />

</form>

<?php

$clientname=$_GET['clientname'];

$myconnect=mysql_connect("localhost","root","")or die("does not connect to mysql");

$db=mysql_select_db('billsystem')or die("does not connect to database");

$result="select addclient.userid,addclient.sno,addnewbill.userid,addnewbill.invoiceno,addnewbill.amount,

addnewbill.date,addnewbill.orderno,addnewbill.descripition,addnewbill.rate,

monthlystatement.userid,monthlystatement.totalamount,monthlystatement.servicetax

,monthlystatement.grandtotal from addclient,addnewbill,

monthlystatement WHERE addclient.clientname='clientname'";

$query=mysql_query($result,$myconnect);

echo "<table border='1'>";

echo"<tr><th>userid</th><th>Client Name</th><th>SNO</th><th>invoiceno</th><th>amount</th><th>Date</th><th>Orderno</th><th>Descripition</th><th>Rate</th><th>totalamount</th><th>servicetax</th><th>grandtotal </th></tr>";

while($row=mysql_fetch_row($query))

{

// Print out the contents of each row into a table

echo "<tr>";

echo "<td>" . $row->userid . "</td>";

echo "<td>" . $row->clientname . "</td>";

echo "<td>" . $row->sno . "</td>";

echo "<td>" . $row->invoiceno . "</td>";

echo "<td>" . $row->amount . "</td>";

echo "<td>" . $row->date . "</td>";

echo "<td>" . $row->orderno . "</td>";

echo "<td>" . $row->descripition. "</td>";

echo "<td>" . $row->rate . "</td>";

echo "<td>" . $row->totalamount . "</td>";

echo "<td>" . $row->servicetax . "</td>";

echo "<td>" . $row->grandtotal . "</td>";

echo "<td><a href='recordshiform.php?userid=" . $row->userid . "'>GO TO FORM</a></td>";

 

}

echo"</tr>";

 

echo "</table>";

 

?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...