Page 1 of 1

php mysql problem

Posted: Thu Jun 19, 2008 1:53 am
by phplearner2008
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'];

}

?>

Re: php mysql problem

Posted: Thu Jun 19, 2008 10:49 am
by noctorum
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'];

}

?>
What error are you getting?

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

Posted: Thu Jun 19, 2008 11:30 am
by Benjamin
You'll get more answers if you post your code correctly using the [code=php tags.