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
cjkeane
Forum Contributor
Posts: 217 Joined: Fri Jun 11, 2010 1:17 pm
Post
by cjkeane » Thu Dec 01, 2011 2:47 pm
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>';
}
?>
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Thu Dec 01, 2011 3:27 pm
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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
cjkeane
Forum Contributor
Posts: 217 Joined: Fri Jun 11, 2010 1:17 pm
Post
by cjkeane » Thu Dec 01, 2011 4:08 pm
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?
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Thu Dec 01, 2011 4:14 pm
Separate them with some character. A comma or dash perhaps?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
cjkeane
Forum Contributor
Posts: 217 Joined: Fri Jun 11, 2010 1:17 pm
Post
by cjkeane » Thu Dec 01, 2011 4:30 pm
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.
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Thu Dec 01, 2011 4:35 pm
Ah.
Then for each row, output 3 options - one for each address.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
cjkeane
Forum Contributor
Posts: 217 Joined: Fri Jun 11, 2010 1:17 pm
Post
by cjkeane » Thu Dec 01, 2011 4:44 pm
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>';
}
?>
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Thu Dec 01, 2011 4:48 pm
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?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
cjkeane
Forum Contributor
Posts: 217 Joined: Fri Jun 11, 2010 1:17 pm
Post
by cjkeane » Thu Dec 01, 2011 5:05 pm
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>
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Thu Dec 01, 2011 5:12 pm
That won't work either, as you're putting options within options. Inside your <select>, just echo $options3
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
cjkeane
Forum Contributor
Posts: 217 Joined: Fri Jun 11, 2010 1:17 pm
Post
by cjkeane » Thu Dec 01, 2011 5:53 pm
i did echo $options3, but without defining 3 different option values, they didn't show up.