Greetings All,
Im new to the forum and to PHP. The script i have written works just fine for now but i would like to try to "clean it up" a bit. Im sure since im new to this i will be writing bloated code for a while.
This script pulls information from a mysql DB and populates to a <select> dropdown menu.
Here is a snip of the code and some of the html.
<?php
$db = mysql_connect("");
mysql_select_db("admin", $db);
$StatusSql ="SELECT Status FROM ticket_status";
$StatusResult=mysql_query($StatusSql);
$options="";
while ($StatusRow=mysql_fetch_array($StatusResult)) {
$StatusThing=$StatusRow["Status"];
$StatusOptions.="<OPTION VALUE=\"$id\">".$StatusThing;
}
?>
<?php
mysql_select_db("admin", $db);
$CatSql ="SELECT Category FROM ticket_category";
$CatResult=mysql_query($CatSql);
$Catoptions="";
while ($CatRow=mysql_fetch_array($CatResult)) {
$CatThing=$CatRow["Category"];
$CatOptions.="<OPTION VALUE=\"$id\">".$CatThing;
}
?>
<?php
mysql_select_db("admin", $db);
$PriSql ="SELECT Priority FROM ticket_priority";
$PriResult=mysql_query($PriSql);
$Prioptions="";
while ($PriRow=mysql_fetch_array($PriResult)) {
$PriThing=$PriRow["Priority"];
$PriOptions.="<OPTION VALUE=\"$id\">".$PriThing;
}
?>
<?php
mysql_select_db("admin", $db);
$MethSql ="SELECT ContactMethod FROM ticket_contact";
$MethResult=mysql_query($MethSql);
$Methoptions="";
while ($MethRow=mysql_fetch_array($MethResult)) {
$MethThing=$MethRow["ContactMethod"];
$MethOptions.="<OPTION VALUE=\"$id\">".$MethThing;
}
?>
HTML
<SELECT NAME=Status>
<OPTION VALUE=0>Status
<?=$StatusOptions?>
</SELECT>
<SELECT NAME=Priority>
<OPTION VALUE=0>Priority
<?=$PriOptions?>
</SELECT>
<SELECT NAME=Method>
<OPTION VALUE=0>Method
<?=$MethOptions?>
</SELECT>
Im new to the forum and to PHP. The script i have written works just fine for now but i would like to try to "clean it up" a bit. Im sure since im new to this i will be writing bloated code for a while.
This script pulls information from a mysql DB and populates to a <select> dropdown menu.
Here is a snip of the code and some of the html.
<?php
$db = mysql_connect("");
mysql_select_db("admin", $db);
$StatusSql ="SELECT Status FROM ticket_status";
$StatusResult=mysql_query($StatusSql);
$options="";
while ($StatusRow=mysql_fetch_array($StatusResult)) {
$StatusThing=$StatusRow["Status"];
$StatusOptions.="<OPTION VALUE=\"$id\">".$StatusThing;
}
?>
<?php
mysql_select_db("admin", $db);
$CatSql ="SELECT Category FROM ticket_category";
$CatResult=mysql_query($CatSql);
$Catoptions="";
while ($CatRow=mysql_fetch_array($CatResult)) {
$CatThing=$CatRow["Category"];
$CatOptions.="<OPTION VALUE=\"$id\">".$CatThing;
}
?>
<?php
mysql_select_db("admin", $db);
$PriSql ="SELECT Priority FROM ticket_priority";
$PriResult=mysql_query($PriSql);
$Prioptions="";
while ($PriRow=mysql_fetch_array($PriResult)) {
$PriThing=$PriRow["Priority"];
$PriOptions.="<OPTION VALUE=\"$id\">".$PriThing;
}
?>
<?php
mysql_select_db("admin", $db);
$MethSql ="SELECT ContactMethod FROM ticket_contact";
$MethResult=mysql_query($MethSql);
$Methoptions="";
while ($MethRow=mysql_fetch_array($MethResult)) {
$MethThing=$MethRow["ContactMethod"];
$MethOptions.="<OPTION VALUE=\"$id\">".$MethThing;
}
?>
HTML
<SELECT NAME=Status>
<OPTION VALUE=0>Status
<?=$StatusOptions?>
</SELECT>
<SELECT NAME=Priority>
<OPTION VALUE=0>Priority
<?=$PriOptions?>
</SELECT>
<SELECT NAME=Method>
<OPTION VALUE=0>Method
<?=$MethOptions?>
</SELECT>
Comment