|
-
Oct 1st, 2009, 10:43 AM
#1
Thread Starter
Hyperactive Member
Function fill dropdown
How can i make a function out of this code
where all colored red variable is dynamic...meaning i can change the variable
according to dept table, branch table
Code:
$query4="SELECT * FROM tblbranch";
$result4 = mysql_query ($query4);
echo "<select name=Branch id=textbox value=''>Branch</option>";
// printing the list box select command
while($nt=mysql_fetch_array($result4)){//Array or records stored in $nt
echo '<option '.($nt['branchcode'] == $bra ? ' selected ' : '').' value="'.$nt['branchcode'].'" >'.$nt['branchcode'].'-'.$nt['branchdesc'].'</option>';
}
echo "</select>";// Closing of list box */
?>
I want to learn more 
grace 
-
Oct 1st, 2009, 11:22 AM
#2
Re: Function fill dropdown
So you want this to be able to change dynamically or load once when the page loads?
Either way, assuming that you don't need to worry about people manually modifying the branch number, you could have a php page that serves this up and grabs the branch number from the querystring.
If you need to have it change dynamically, then you would want to look into AJAX. A good starter tutorial can be found here
-
Oct 1st, 2009, 08:51 PM
#3
Thread Starter
Hyperactive Member
Re: Function fill dropdown
 Originally Posted by kfcSmitty
So you want this to be able to change dynamically or load once when the page loads?
Either way, assuming that you don't need to worry about people manually modifying the branch number, you could have a php page that serves this up and grabs the branch number from the querystring.
If you need to have it change dynamically, then you would want to look into AJAX. A good starter tutorial can be found here
no what i mean i am making a function out of that code...i created somtthing like this
Code:
function filldropdown($tbname,$drpname,$rowid,$rowname,$rowsel){
$query4="SELECT * FROM $tbname";
$result4 = mysql_query ($query4);
echo "<select name=$drpname id=textbox value=''>$drpname";
// printing the list box select command
while($nt=mysql_fetch_array($result4)){//Array or records stored in $nt
echo '<option '.($nt['$rowid'] == $rowsel ? 'selected':'').' value="'.$nt['$rowid'].'" >'.$nt['$rowid'].'-'.$nt['$rowname'].'</option>';
}
if i do a function like the code above...it doesn't select a value, colored red is the code for selecting value
I want to learn more 
grace 
-
Oct 1st, 2009, 10:01 PM
#4
Re: Function fill dropdown
if you have any variables encased in single quotes, PHP will take those variables as a literal string rather than processing them. eg.
PHP Code:
$hello = "Greetings!"; echo '$hello'; //echos: $hello echo "$hello"; //echos: Greetings! echo $hello; //echos: Greetings!
so, every time you reference $nt['$rowid'], PHP is looking for the key (LITERAL STRING) $rowid, rather than the actual value of $rowid. reference $nt[$rowid] instead. likewise for $nt['$rowname']; use $nt[$rowname].
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|