Page 1 of 1
PHP/MYSQL - listing multiple column data in dropdown list
Posted: Thu Dec 01, 2011 2:47 pm
by cjkeane
Hi.
I'm having an issue retreiving multiple columns of data and listing them under eachother in a dropdown list.
currently, the result is that all email addresses are listed on one line in the dropdown list separated with a .
I'm wondering if anyone has any suggestions.
Code: Select all
<?php
$result3=mysql_query("SELECT EMail, EMail_1, Email_2 FROM principal where CompanyName = '".$CompanyName."' AND BranchName='".$CompanyBranch."'");
$options3="";
while ($row3=mysql_fetch_array($result3)) {
$categoryname3=$row3["EMail"] . '<br />' . $row3["EMail_1"] . '<br />' . $row3["EMail_2"];
$options3.="<OPTION VALUE=\"$categoryname3\">".$categoryname3.'</option>';
}
?>
Re: PHP/MYSQL - listing multiple column data in dropdown lis
Posted: Thu Dec 01, 2011 3:27 pm
by pickle
You can't put < br / > inside an option "value", nor in-between the opening & closing tags.
For cleanliness, you should just be retrieving the data here & letting your template format it for output.
Re: PHP/MYSQL - listing multiple column data in dropdown lis
Posted: Thu Dec 01, 2011 4:08 pm
by cjkeane
if that's the case, what's the best way to populate a dropdown list with the data from 3 columns? with a dropdown list displaying it as a list?
Re: PHP/MYSQL - listing multiple column data in dropdown lis
Posted: Thu Dec 01, 2011 4:14 pm
by pickle
Separate them with some character. A comma or dash perhaps?
Re: PHP/MYSQL - listing multiple column data in dropdown lis
Posted: Thu Dec 01, 2011 4:30 pm
by cjkeane
i could do that, but data would appear as follows:
if email 1 existed but not the others:
1@home.ca, ,
if 2 email addresses existed:
1@home.ca,
2@home.ca,
if all 3 emails exist:
1@home.ca,
2@home.ca,
3@home.ca
then when i pass the selected value to a textbox, it would appear as stated above.
what i need to do is list the emails like so:
1@home.ca
2@home.ca
3@home.ca
then when any of the emails are selected, only that email address is passed to the textbox.
Re: PHP/MYSQL - listing multiple column data in dropdown lis
Posted: Thu Dec 01, 2011 4:35 pm
by pickle
Ah.
Then for each row, output 3 options - one for each address.
Re: PHP/MYSQL - listing multiple column data in dropdown lis
Posted: Thu Dec 01, 2011 4:44 pm
by cjkeane
how could that be accomplished? i've tried the below, but nothing displays. i'm assuming because Email_2 is blank.
Code: Select all
<?php
$result3=mysql_query("SELECT EMail, EMail_1, Email_2 FROM principal where CompanyName = '".$CompanyName."' AND BranchName='".$CompanyBranch."'");
$options3="";
while ($row3=mysql_fetch_array($result3)) {
$categoryname3=$row3["EMail"];
$categoryname3=$row3["EMail_1"];
$categoryname3=$row3["EMail_2"];
$options3.="<OPTION VALUE=\"$categoryname3\">".$categoryname3.'</option>';
}
?>
Re: PHP/MYSQL - listing multiple column data in dropdown lis
Posted: Thu Dec 01, 2011 4:48 pm
by pickle
You're overwriting $categoryname3 twice. You need three separate variables to store the three separate addresses.
Also, you're not outputting anything - is that done elsewhere?
Re: PHP/MYSQL - listing multiple column data in dropdown lis
Posted: Thu Dec 01, 2011 5:05 pm
by cjkeane
OK. I'm now getting the 3 emails on 3 separate lines
i'm half way there. thanks for the help.
Code: Select all
<?php
$result3=mysql_query("SELECT EMail, EMail_1, EMail_2 FROM principal where CompanyName = '".$CompanyName."' AND BranchName='".$CompanyBranch."'");
$options3="";
while ($row3=mysql_fetch_array($result3)) {
$categoryname3a=$row3["EMail"];
$categoryname3b=$row3["EMail_1"];
$categoryname3c=$row3["EMail_2"];
$options3.="<OPTION VALUE=\"$categoryname3a\">".$categoryname3a.'</option>';
$options3.="<OPTION VALUE=\"$categoryname3b\">".$categoryname3b.'</option>';
$options3.="<OPTION VALUE=\"$categoryname3c\">".$categoryname3c.'</option>';
}
?>
<select name="users3" id="SelectEMailTo3" onchange="showUser3(this.value)">
<option value="">< select > <?php echo $options3 ?></option>
</select>
Re: PHP/MYSQL - listing multiple column data in dropdown lis
Posted: Thu Dec 01, 2011 5:12 pm
by pickle
That won't work either, as you're putting options within options. Inside your <select>, just echo $options3
Re: PHP/MYSQL - listing multiple column data in dropdown lis
Posted: Thu Dec 01, 2011 5:53 pm
by cjkeane
i did echo $options3, but without defining 3 different option values, they didn't show up.