Hi,
I have a web page that has a drop down list with multiple select. Based on the user's selections, mysql database has to be queried for each option selected by user.
The name of drop down list is EDUCATION. $lines counts the number of options selected. I am storing value of each option in $mystore[$i]
I am using loop as I need to query database for each option the user selects from the list. The code does not work. Any suggestions?
<?php
$lines = 0;
$i=0;
foreach ($_POST['EDUCATION'] as $EDUCATION => $value)
{
echo "Education: $EDUCATION; Value: $value<br>";
$store[$EDUCATION] = $value;
$mystore[$i] = $store[$EDUCATION];
$lines++;
}
$eduresult = SELECT * FROM profile;
for($i=0;$i<$lines;$i++)
{
$edu = "SELECT * FROM profile WHERE EDUCATION = '$mystore[$i]'";
$eduresult =mysql_query(".$eduresult.UNION.$edu.")or die(mysql_error());
}
while($row = mysql_fetch_array( $eduresult )) {
echo $row['NAME'];
echo $row['EMAIL'];
}
?>
php mysql problem
Moderator: General Moderators
Re: php mysql problem
What error are you getting?phplearner2008 wrote:Hi,
I have a web page that has a drop down list with multiple select. Based on the user's selections, mysql database has to be queried for each option selected by user.
The name of drop down list is EDUCATION. $lines counts the number of options selected. I am storing value of each option in $mystore[$i]
I am using loop as I need to query database for each option the user selects from the list. The code does not work. Any suggestions?
<?php
$lines = 0;
$i=0;
foreach ($_POST['EDUCATION'] as $EDUCATION => $value)
{
echo "Education: $EDUCATION; Value: $value<br>";
$store[$EDUCATION] = $value;
$mystore[$i] = $store[$EDUCATION];
$lines++;
}
$eduresult = SELECT * FROM profile;
for($i=0;$i<$lines;$i++)
{
$edu = "SELECT * FROM profile WHERE EDUCATION = '$mystore[$i]'";
$eduresult =mysql_query(".$eduresult.UNION.$edu.")or die(mysql_error());
}
while($row = mysql_fetch_array( $eduresult )) {
echo $row['NAME'];
echo $row['EMAIL'];
}
?>
At face value the only thing that seems weird is that lines only equals one but your using a loop for it.
Re: php mysql problem
You'll get more answers if you post your code correctly using the [code=php tags.