DropDownBox Problem

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

alexmaster_2004
Forum Commoner
Posts: 35
Joined: Wed Sep 14, 2005 8:44 am

Post by alexmaster_2004 »

Hi
I have changed the code so i generate them one by one.
I tried to do all what you tell me but i don't know it still not work as i want.
so if you don't mind there is the complete code that i use.
Please review it and tell me how to make it work as i want.
I know that this is too much code but it is very easy.
Thanks in advance

Code: Select all

<?php
session_start();
include("includes/inc.php");
?>
<HTML>
<HEAD>
<link rel=stylesheet href=style.css type=text/css>
</HEAD>
<BODY>
<?
if($_SESSION["session_admin"] != "Yes")
{
print "You need to login before you can view this page";
}
else
{
print "<table align='center'><tr><td width='100%' class='lsep' height='218' valign='top'>";
print "<table border='0' cellpadding='0' cellspacing='0' width='100%' height='28'><tr>";
print "<td class='headcell' height='20'>Add a new software</td></tr>";

if(isset($_POST['cat_main']) && $_POST['cat_main']!='')
{
  if(isset($_POST['cat_sub1']))
  {
   if(isset($_POST['cat_sub2']))
   {
     if(isset($_POST['cat_sub3']))
  {
    if(isset($_POST['cat_sub4']))
  {
       $action='add_main1.php';
  }
  else
  {
    $action='add_main.php';
  }
  }
  else
  {
    $action='add_main.php';
  }
   }
   else
   {
    $action='add_main.php';
   }
  }
  else
  {
    $action='add_main.php';
  }
}
else
{
  $action='add_main.php';
}

print "<tr><td height='13' class='textcell'><table>";
print "<form name='add_main' action=$action method='post'>";

print "<tr>";
print "<td width='30%'><p align='left'><font face='Verdana' color='#670808'>Software Name(*):</font></p></td>";
print "<td width='70%'><p align='left'><input type='text' name='name' size='20'></p></td>";
print "</tr>";

$sql=mysql_query("select * from cat_main ORDER BY cat_main_name ASC");
print "<tr>";
print "<td width='30%'><p align='left'><font face='Verdana' color='#670808'>Main Category(*):</font></p></td>";
print "<td width='70%'><p align='left'>";
print  "<select name='cat_main' onchange='document.add_main.submit()'>";
print "<option value='' ></option>";
while ($recs=mysql_fetch_array($sql))
 {
$id=$recs['cat_main_id'];
$name=$recs['cat_main_name'];
print "<option value=\"".$id."\"".(isset($_POST['cat_main']) && $_POST['cat_main'] == $id ? " selected=\"selected\"" : "").">".$name."</option>";
  }
print "</select>";
print "</tr>";

if(isset($_POST['cat_main']) && $_POST['cat_main']!='')
{
$sql1=mysql_query("select * from cat_sub1 where cat_main_id=".$_POST['cat_main']." ORDER BY cat_sub_name ASC");
$rows1=mysql_num_rows($sql1);
if($rows1!=0)
{
print "<tr>";
print "<td width='30%'><p align='left'><font face='Verdana' color='#670808'>First Category(*):</font></p></td>";
print "<td width='70%'><p align='left'>";
print  "<select name = 'cat_sub1' onchange='document.add_main.submit()'>";
print "<option value=''></option>";

//$sql1=mysql_query("select * from cat_sub1 where cat_main_id=".$_POST['cat_main']." ORDER BY cat_sub_name ASC");
while ($recs1=mysql_fetch_array($sql1))
 {
$id1=$recs1['cat_sub1_id'];
$name1=$recs1['cat_sub_name'];
print "<option value=\"".$id1."\"".(isset($_POST['cat_sub1']) && $_POST['cat_sub1'] == $id1 ? " selected=\"selected\"" : "").">".$name1."</option>";
  }
print "</select>";
print "</tr>";
}
}

if(isset($_POST['cat_sub1']) && isset($_POST['cat_main']) && $_POST['cat_main']!='' && $_POST['cat_sub1']!='')
{
$sql2=mysql_query("select * from cat_sub2 where cat_sub1_id=".$_POST['cat_sub1']." ORDER BY cat_sub_name ASC");
$rows2=mysql_num_rows($sql2);
if($rows2!=0)
{
print "<tr>";
print "<td width='30%'><p align='left'><font face='Verdana' color='#670808'>Second Category(*):</font></p></td>";
print "<td width='70%'><p align='left'>";
print  "<select name = 'cat_sub2' onchange='document.add_main.submit()'>";
print "<option value=''></option>";
//$sql2=mysql_query("select * from cat_sub2 where cat_sub1_id=".$_POST['cat_sub1']." ORDER BY cat_sub_name ASC");
while ($recs2=mysql_fetch_array($sql2))
 {
$id2=$recs2['cat_sub2_id'];
$name2=$recs2['cat_sub_name'];
print "<option value=\"".$id2."\"".(isset($_POST['cat_sub2']) && $_POST['cat_sub2'] == $id2 ? " selected=\"selected\"" : "").">".$name2."</option>";
  }
print "</select>";
print "</tr>";
}
}

if(isset($_POST['cat_sub2']) && isset($_POST['cat_sub1']) && isset($_POST['cat_main']) && $_POST['cat_main']!='' && $_POST['cat_sub1']!='' && $_POST['cat_sub2']!='')
{
$sql3=mysql_query("select * from cat_sub3 where cat_sub2_id=".$_POST['cat_sub2']." ORDER BY cat_sub_name ASC");
$rows3=mysql_num_rows($sql3);
if($rows3!=0)
{
print "<tr>";
print "<td width='30%'><p align='left'><font face='Verdana' color='#670808'>Third Category(*):</font></p></td>";
print "<td width='70%'><p align='left'>";
print  "<select name = 'cat_sub3' onchange='document.add_main.submit()'>";
print "<option value=''></option>";
//$sql3=mysql_query("select * from cat_sub3 where cat_sub2_id=".$_POST['cat_sub2']." ORDER BY cat_sub_name ASC");
while ($recs3=mysql_fetch_array($sql3))
 {
$id3=$recs3['cat_sub3_id'];
$name3=$recs3['cat_sub_name'];
print "<option value=\"".$id3."\"".(isset($_POST['cat_sub3']) && $_POST['cat_sub3'] == $id3 ? " selected=\"selected\"" : "").">".$name3."</option>";
  }
print "</select>";
print "</tr>";
}
}

if(isset($_POST['cat_sub3']) && isset($_POST['cat_sub2']) && isset($_POST['cat_sub1']) && isset($_POST['cat_main']) && $_POST['cat_main']!='' && $_POST['cat_sub1']!='' && $_POST['cat_sub2']!='' && $_POST['cat_sub3']!='')
{
$sql4=mysql_query("select * from cat_sub4 where cat_sub3_id=".$_POST['cat_sub3']." ORDER BY cat_sub_name ASC");
$rows4=mysql_num_rows($sql4);
if($rows4!=0)
{
print "<tr>";
print "<td width='30%'><p align='left'><font face='Verdana' color='#670808'>Fourth Category(*):</font></p></td>";
print "<td width='70%'><p align='left'>";
print  "<select name = 'cat_sub4' onchange='document.add_main.submit()'>";
print "<option value=''></option>";
//$sql4=mysql_query("select * from cat_sub4 where cat_sub3_id=".$_POST['cat_sub3']." ORDER BY cat_sub_name ASC");
while ($recs4=mysql_fetch_array($sql4))
 {
$id4=$recs4['cat_sub4_id'];
$name4=$recs4['cat_sub_name'];
print "<option value=\"".$id4."\"".(isset($_POST['cat_sub4']) && $_POST['cat_sub4'] == $id4 ? " selected=\"selected\"" : "").">".$name4."</option>";
  }
print "</select>";
print "</tr>";
}
}

if(isset($_POST['cat_sub4']) && isset($_POST['cat_sub3']) && isset($_POST['cat_sub2']) && isset($_POST['cat_sub1']) && isset($_POST['cat_main']) && $_POST['cat_main']!='' && $_POST['cat_sub1']!='' && $_POST['cat_sub2']!='' && $_POST['cat_sub3']!='' && $_POST['cat_sub4']!='')
{
$sql5=mysql_query("select * from cat_sub5 where cat_sub4_id=".$_POST['cat_sub4']." ORDER BY cat_sub_name ASC");
$rows5=mysql_num_rows($sql5);
if($rows5!=0)
{
print "<tr>";
print "<td width='30%'><p align='left'><font face='Verdana' color='#670808'>Fifth Category(*):</font></p></td>";
print "<td width='70%'><p align='left'>";
print  "<select name = 'cat_sub5'>";
print "<option value=''></option>";
//$sql5=mysql_query("select * from cat_sub5 where cat_sub4_id=".$_POST['cat_sub4']." ORDER BY cat_sub_name ASC");
while ($recs5=mysql_fetch_array($sql5))
 {
$id5=$recs5['cat_sub5_id'];
$name5=$recs5['cat_sub_name'];
print "<option value=$id5 >$name5</option>";
 }
print "</select>";
print "</tr>";
}
}
print "<tr>";
print "<td width='30%' valign='top'><p align='left'><font face='Verdana' color='#670808'>Main Image(*):</font></p></td>";
print "<td width='70%'><p align='left'><input type='file' name='image' size='20'></p></td>";
print "</tr>";

print "<tr>";
print "<td width='32%' valign='top'><p align='left'><font face='Verdana' color='#670808'>Software download path(*):</font></p></td>";
print "<td width='70%'><p align='left'><input type='text' name='down' size='20'></p></td>";
print "</tr>";

print "<tr>";
print "<td width='30%' valign='top'><p align='left'><font face='Verdana' color='#670808'>Short Description(*):</font></p></td>";
print "<td width='70%'><p align='left'><textarea  name='short_desc' rows='5' cols='40'></textarea></p></td>";
print "</tr>";


print "<tr>";
print "<td width='30%' valign='top'><p align='left'><font face='Verdana' color='#670808'>Software Description(*):</font></p></td>";
print "<td width='70%'><p align='left'><textarea  name='desc' rows='5' cols='40'></textarea></p></td>";
print "</tr>";

print "<tr>";
print "<td width='30%' valign='top'><p align='left'><font face='Verdana' color='#670808'>CD Key(*):</font></p></td>";
print "<td width='70%'><p align='left'><input type='text' name='cd_key' size='20'></p></td>";
print "</tr>";

print "<tr>";
print "<td width='30%' valign='top'><p align='left'><font face='Verdana' color='#670808'>Allow download (*):</font></p></td>";
print "<td width='70%'><p align='left'><input type='checkbox' name='allow' value='on'></p></td>";
print "</tr>";

print "<tr>";
print "<td width='30%' valign='top'><p align='left'><font face='Verdana' color='#670808'>Full download path(*):</font></p></td>";
print "<td width='70%'><p align='left'><input type='text' name='full' size='20'></p></td>";
print "</tr>";

print "<tr>";
print "<td width='30%' valign='top'><p align='left'><font face='Verdana' color='#670808'>New Software:</font></p></td>";
print "<td width='70%'><p align='left'>";
print "<input type='checkbox' name='new' value='on'></p></td>";
print "</tr>";

print "<tr>";
print "<td width='30%' valign='top'><p align='left'><font face='Verdana' color='#670808'>No Available(*):</font></p></td>";
print "<td width='70%'><p align='left'><input type='text' name='no' size='20'></p></td>";
print "</tr>";

print "<tr>";
print "<td width='30%' valign='top'><p align='left'><font face='Verdana' color='#670808'>Price(*):</font></p></td>";
print "<td width='70%'><p align='left'><input type='text' name='price' size='20'></p></td>";
print "</tr>";

print "<tr>";
print "<td width='30%' valign='top'><p align='left'><font face='Verdana' color='#670808'>Affiliate Commission(*):</font></p></td>";
print "<td width='70%'><p align='left'><input type='text' name='comm_rate' size='20'></p></td>";
print "</tr>";

print "<tr>";
print "<td width='30%' valign='top'><p align='left'><font face='Verdana' color='#670808'>Featured(*):</font></p></td>";
print "<td width='70%'><p align='left'><input type='checkbox' name='featured' value='on'></p></td>";
print "</tr>";

print "<tr bgColor='#ffffff'>";
print "<td class='smalltext' vAlign='top'>&nbsp;</td>";
print "<td class='text'><input type='submit' value='Add New software'></td>";
print "</tr></table></table>";
print "</form>";
}
?>


</BODY>
</HTML>
ryanlwh
Forum Commoner
Posts: 84
Joined: Wed Sep 14, 2005 1:29 pm

Post by ryanlwh »

at a first glance it seems ok to me. i'll take a closer look later. it would be better for you to maintain it if you make the part to output a drop down box a function, so you don't need to have to change something five times, but that's later when it works.

i'll check back when i'm home.
alexmaster_2004
Forum Commoner
Posts: 35
Joined: Wed Sep 14, 2005 8:44 am

Post by alexmaster_2004 »

Hi
i hoppe you have get a solution fro this problem.
If so pkease tellme soon.
Thanks
Post Reply