Jump to content

duplicate select

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
15 replies to this topic

#1
techker

techker

    Programmer

  • Members
  • PipPipPipPip
  • 136 posts
ok so i fanaly got my first step done is making my select box refresh and work!lol

now i need to duplicat it on the same page?even 8 times..

but when i duplicat it it refresh the original to..

<?

$dbservertype='mysql';
$servername='localhost';
// username and password to log onto db server
$dbusername='openshar_iii;
$dbpassword='techker';
// name of database
$dbname='openshar_iiii;

////////////////////////////////////////
////// DONOT EDIT BELOW  /////////
///////////////////////////////////////
connecttodb($servername,$dbname,$dbusername,$dbpassword);
function connecttodb($servername,$dbname,$dbuser,$dbpassword)
{
global $link;
$link=mysql_connect ("$servername","$dbuser","$dbpassword");
if(!$link){die("Could not connect to MySQL");}
mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
}
//////// End of connecting to database ////////
?>

<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>
<title>Multiple drop down list box from plus2net</title>
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='dd.php?cat=' + val ;
}

</script>
</head>

<body>
<?




//@$cat=$HTTP_GET_VARS['cat']; // Use this line or above line if register_global is off
$cat=$HTTP_GET_VARS['cat']; 
///////// Getting the data from Mysql table for first list box//////////
$quer2=mysql_query("SELECT *  FROM category "); 
///////////// End of query for first list box////////////

/////// for second drop down list we will check if category is selected else we will display all the subcategory///// 
if(isset($cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT * FROM $cat  "); 
}else{$quer=mysql_query("SELECT * FROM $cat "); } 
////////// end of query for second subcategory drop down list box ///////////////////////////

echo "<form method=post name=f1 action='dd-check.php'>";
/// Add your form processing page address to action in above line. Example  action=dd-check.php////
//////////        Starting of first drop downlist /////////
echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
while($noticia2 = mysql_fetch_array($quer2)) { 
if($noticia2['cat_id']==@$cat){echo "<option selected value='$noticia2[cat_id]'>$noticia2[category]</option>"."<BR>";}
else{echo  "<option value='$noticia2[category]'>$noticia2[category]</option>";}
}
echo "</select>";
//////////////////  This will end the first drop down list ///////////

//////////        Starting of second drop downlist /////////
echo "<select name='subcat'><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer)) { 
echo  "<option value='$noticia[pic]'>$noticia[pic]</option>";
}
echo "</select>";
//////////////////  This will end the second drop down list ///////////
//// Add your other form fields as needed here/////
echo "<input type=submit value=Submit>";
echo "</form>";
?>
</body>

</html>

Edited by WingedPanther, 17 February 2009 - 01:22 PM.
close php tag


#2
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
What is the problem? Is there an error message? What is the program doing at the moment?
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#3
techker

techker

    Programmer

  • Members
  • PipPipPipPip
  • 136 posts
the problem is if i copy and past it the first one works but the second does not.even if i change the info to like 2 instead of 1

i have a fealing it is in the function.

the forms all have

reload(this.form)

#4
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
For a start, you do not need to connect to the database more than once in the page.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#5
techker

techker

    Programmer

  • Members
  • PipPipPipPip
  • 136 posts
thats part is ok.i got that

#6
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
Are you copying the entire form or just the select input?
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation

Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!


#7
Affix

Affix

    Learning Programmer

  • Members
  • PipPipPip
  • 47 posts
if(isset($cat) and strlen($cat) > 0)
{
         $quer=mysql_query("SELECT * FROM $cat  "); 
}
else
{
         $quer=mysql_query("SELECT * FROM $cat "); 
} 

That code will produce an error. basically you are using $cat when it is not declared so Esentually you're code os going to do

SELECT * FROM ``;

so you will not be selecting from an existing table

Also I don't recommend posting your SQL Password Publically like that

add the following code to you mysql_query();

or die(mysql_error());

E.G

if(isset($cat) and strlen($cat) > 0)
{
         $quer=mysql_query("SELECT * FROM $cat  ")or die(mysql_error()); 
}
else
{
         $quer=mysql_query("SELECT * FROM $cat ")or die(mysql_error()); 
} 


#8
ReekenX

ReekenX

    Programmer

  • Members
  • PipPipPipPip
  • 134 posts
I think, you should also consider about conding standards. I suggest you to read PHP Coding Standard, because later you will see, how difficult is to read lines like:

////////////////// This will end the second drop down list ///////////
www.jarmalavicius.lt | www.github.com/reekenx | www.twitter.com/reekenx

#9
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
Yer, I must agree with the above post. Your code is really messy, it should really be fixed up and neater. Also, why are you using HTML 3.2?
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation

Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!


#10
techker

techker

    Programmer

  • Members
  • PipPipPipPip
  • 136 posts

Affix said:

if(isset($cat) and strlen($cat) > 0)

{

         $quer=mysql_query("SELECT * FROM $cat  "); 

}

else

{

         $quer=mysql_query("SELECT * FROM $cat "); 

} 

That code will produce an error. basically you are using $cat when it is not declared so Esentually you're code os going to do

SELECT * FROM ``;

so you will not be selecting from an existing table

Also I don't recommend posting your SQL Password Publically like that

add the following code to you mysql_query();

or die(mysql_error());

E.G

if(isset($cat) and strlen($cat) > 0)

{

         $quer=mysql_query("SELECT * FROM $cat  ")or die(mysql_error()); 

}

else

{

         $quer=mysql_query("SELECT * FROM $cat ")or die(mysql_error()); 

} 


ok thx!i did not realize that..the html is older cause i used an older script and modified it to use php and mysql.so that is why the code is messt up..so yes for the question of duplicating .all of the script not only the form

#11
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
What do you mean. What are you copying? The select part of the form or the entire form?
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation

Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!


#12
techker

techker

    Programmer

  • Members
  • PipPipPipPip
  • 136 posts
well i copy the select part in the same form cause i want to insert all the selections at the same time in a database.