0
<?php
require_once('upper.php');
if(isset($_COOKIE['AdminCookie'])){
if(isset($_POST['submit'])){
require_once('database.php');
$ActivityName =$_POST['ActivityName'];
$EventName =$_POST['EventName'];
$BloodGroup =$_POST['BloodGroup'];
$Location =$_POST['Location'];
$Age =$_POST['Age'];
//$Sex =$_POST['Sex'];
echo $ActivityName;
$query="select * from registration WHERE  Flag='A' AND BloodGroup= '$BloodGroup' AND Age ='$Age'";
//$query="select * from registration WHERE  Flag='A'  AND Address like '%$Location%'";

$result=mysqli_query($dbc,$query) or die('Not Connected');
while($row=mysqli_fetch_array($result))
{
echo $row['Name'];
}


/*if(isset($_POST['ActivityName']))
{
require_once('database.php');
$Search=$_POST['Search'];
$query="select * from registration where Flag='A' AND Activity like '%,$Search,%'";
$result=mysqli_query($dbc,$query) or die('Not Connected');
while($row=mysqli_fetch_array($result))
{
echo "<table border='2'><tr><td> Name--".$row['Name']."</td>
<td>Contact Number--".$row['ContactNumber']."</td>
<td>Email--".$row['Email']."</td>
<td>Address--".$row['Address']."</td></tr></table>";
}
}

elseif(isset($_POST['EventId'])){
require_once('database.php');
$Search=$_POST['Search'];
$query="SELECT * FROM registration r JOIN participation p ON r.LoginId = p.LoginId WHERE r.Flag='A' AND p.EventId ='$Search'";
$result=mysqli_query($dbc,$query) or die('Not Connected');
while($row=mysqli_fetch_array($result)){
echo "<table border='2'><tr><td> Name--".$row['Name']."</td>
<td>Contact Number--".$row['ContactNumber']."</td>
<td>Email--".$row['Email']."</td>
<td>Address--".$row['Address']."</td></tr></table>";
}}

elseif(isset($_POST['Location']))
{
require_once('database.php');
$Search=$_POST['Search'];
$query="select * from registration where Flag='A' AND Address like '%$Search%'";
$result=mysqli_query($dbc,$query) or die('Not Connected');
while($row=mysqli_fetch_array($result))
{
echo "<table border='2'><tr><td> Name--".$row['Name']."</td>
<td>Contact Number--".$row['ContactNumber']."</td>
<td>Email--".$row['Email']."</td>
<td>Address--".$row['Address']."</td></tr></table>";
}
}

elseif(isset($_POST['BloodGroup']))
{
require_once('database.php');
$Search=$_POST['Search'];
$query="select * from registration where Flag='A' AND BloodGroup ='$Search'";
$result=mysqli_query($dbc,$query) or die('Not Connected');
while($row=mysqli_fetch_array($result))
{
echo "<table border='2'><tr><td> Name--".$row['Name']."</td>
<td>Contact Number--".$row['ContactNumber']."</td>
<td>Email--".$row['Email']."</td>
<td>Address--".$row['Address']."</td></tr></table>";
}*/
}
?>
<html><body><form action='<?php echo $_SERVER['PHP_SELF']?>' method="post">
<?php 
require_once('database.php');
$result=mysqli_query($dbc,"select * from Activity");
echo "Select Activity &nbsp&nbsp
<select name='ActivityName'>
<option></option>";
while($row=mysqli_fetch_array($result)){
echo "
<option>".$row['Title']."</option>";
}
echo "</select><br>";



$result=mysqli_query($dbc,"select * from events");
echo "Select Events &nbsp&nbsp
<select name='EventName'>
<option></option>";
while($row=mysqli_fetch_array($result)){
echo "
<option>".$row[Title]."</option>";
}
echo "</select><br>";


$result=mysqli_query($dbc,"select * from registration");
echo "Select Blood Group &nbsp&nbsp
<select name='BloodGroup'>
<option></option>";
while($row=mysqli_fetch_array($result)){
echo "
<option>".$row[BloodGroup]."</option>";
}
echo "</select><br>";


echo" Enter Location &nbsp&nbsp 
<input type='text' name='Location'><br>";
echo"Enter Age &nbsp&nbsp
<input type='text' name='Age'><br>";


echo "Enter Sex &nbsp&nbsp 
<select>
<option></option>
<option>Male</option>
<option>Female</option>
</select><br>";

echo "<input type='submit' name='submit' value='Search'><br>";
echo"</form></body></html>";


echo "<a href='log_out.php'>Admin Log out</a><br>";
echo "<a href='AdminHome.php'>Back to Admin Home</a>";
}
else{echo 'Restricted Page'."<br><br>".'Access Denied';}

require_once('lower.php');?>

Hi frds..........
I want to search by "Age" and "Blood Group" first.On combobox when I select both Age and Blood Group it gives the rihgt result but when I select only one field and other remain blank it not works.............
I want when I select only one field, query executes for one condition only....
It means when I select only Blood Group and leave Age field blank it displays all Name have required Blood Group without any age condition.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by ankit.pandey3
0

Use the following...

Replace your select box like this..

echo "Select Blood Group &nbsp&nbsp<select name='BloodGroup'><option value='none'>Select</option>"; // This will user friendly, when displaying 'Select' text, rather leaving it as a blank...
while($row=mysqli_fetch_array($result)){echo "<option>".$row[BloodGroup]."</option>";}echo "</select><br>";

Now, Your query will be succeeded based on some conditions...

if(($Bloodgroup=='none')&&($Age==""))
{
echo "Sorry.. Please enter valid bloodgroup and Age..";
exit;
}
if(($Bloodgroup!='none') && ($Age==""))
{
$query="select * from registration WHERE  Flag='A' AND BloodGroup= '$BloodGroup';
// Then your code as usual to display all results...
}
if(($Bloodgroup=='none') && ($Age!=""))
{
$query="select * from registration WHERE  Flag='A' AND Age='$Age';
// Then your code as usual to display all results...
}

This will works as your wish... If still any probs, please let me know...

0
<?php
require_once('upper.php');
if(isset($_COOKIE['AdminCookie'])){
if(isset($_POST['submit'])){
require_once('database.php');
$ActivityName =$_POST['ActivityName'];
$EventName =$_POST['EventName'];
$BloodGroup =$_POST['BloodGroup'];
$Location =$_POST['Location'];
$Age =$_POST['Age'];
$Sex =$_POST['Sex'];
$where = array();
$where[] = "Flag='A'";
//$query="select * from registration WHERE  Flag='A' AND Activity like '%$ActivityName%' ";
if(!empty($ActivityName)){
    $where[] ="Activity like'%$ActivityName%'";
    }
if(!empty($BloodGroup)){
    $where[] = "BloodGroup='$BloodGroup'";
}
if(!empty($Location)){
    $where[]= "Address like '%$Location%'";
    }
if(!empty($Age)){
    $where[] = "Age='$Age'";
}
if(!empty($Sex)){
    $where[] ="Sex ='$Sex'";
    }
    
if(!empty($EventName)){
    $where[] ="# ='$EventName'";
    }
$where = count($where) ? ' WHERE ' . implode(' AND ', $where) : '';
echo $query = "select * from registration $where"; 
$result=mysqli_query($dbc,$query) or die('Not Connected');
while($row=mysqli_fetch_array($result))
{
echo "<b>".$row['Name']."<br>";
}
}
?>




<html><body><form action='<?php echo $_SERVER['PHP_SELF']?>' method="post">
<?php 
require_once('database.php');
$result=mysqli_query($dbc,"select * from Activity");
echo "Select Activity &nbsp&nbsp
<select name='ActivityName'>
<option></option>";
while($row=mysqli_fetch_array($result)){
echo "
<option>".$row['Title']."</option>";
}
echo "</select><br>";



$result=mysqli_query($dbc,"select * from events");
echo "Select Events &nbsp&nbsp
<select name='EventName'>
<option></option>";
while($row=mysqli_fetch_array($result)){
echo "
<option>".$row[Title]."</option>";
}
echo "</select><br>";


$result=mysqli_query($dbc,"select * from registration");
echo "Select Blood Group &nbsp&nbsp
<select name='BloodGroup'>
<option></option>";
while($row=mysqli_fetch_array($result)){
echo "
<option>".$row[BloodGroup]."</option>";
}
echo "</select><br>";


echo" Enter Location &nbsp&nbsp 
<input type='text' name='Location'><br>";
echo"Enter Age &nbsp&nbsp
<input type='text' name='Age'><br>";

$result=mysqli_query($dbc,"select * from registration");
echo "Enter Sex &nbsp&nbsp 
<select name='Sex'>
<option></option>
<option>Male</option>
<option>Female</option>
</select><br>";

echo "<input type='submit' name='submit' value='Search'><br>";
echo"</form></body></html>";


echo "<a href='log_out.php'>Admin Log out</a><br>";
echo "<a href='AdminHome.php'>Back to Admin Home</a>";
}
else{echo 'Restricted Page'."<br><br>".'Access Denied';}

require_once('lower.php');?>

I have one more problem that I have 3 tables named "events","participation","registration"....
All above values are retrieved by registration table such as Activity, Age, Blood Group.
Events table has 2 columns "EventId" and "Title".
Participation table has 2 columns "LoginId" and "EventId".
Registraion table contains many columns such as Name,LoginId,Activity, Age, Blood Group etc.

Now I want when user select Events Titles (displayed from table events). If selected title exists in table participation (by joining EventId condition) then it displays the corresponding Name which exist in registration table.


How I can do it...........
Plzzzz help me.........
Thx in advance..............

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.