php mysql problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
phplearner2008
Forum Newbie
Posts: 1
Joined: Thu Jun 19, 2008 1:50 am

php mysql problem

Post 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'];

}

?>
noctorum
Forum Commoner
Posts: 31
Joined: Fri Jun 13, 2008 10:46 am

Re: php mysql problem

Post 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.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: php mysql problem

Post by Benjamin »

You'll get more answers if you post your code correctly using the [code=php tags.
Post Reply