Jump to content

I want to search with multiple table from by database


ankit.pandeyc012

Recommended Posts

<?php

if(isset($_POST['ActivityId']))

{

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 participation where EventId ='$Search'";

$result=mysqli_query($dbc,$query) or die('Not Connected');

while($row=mysqli_fetch_array($result)){

$LoginId= $row['LoginId'];

echo $LoginId;}

$query="select * from registration where LoginId='$LoginId'";

$result=mysqli_query($dbc,$query) or die('Not Connected to Reg');

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">

<input type="text" name="Search"><br>

<input type="submit" name="ActivityId" value="Submit Activity Id"><br>

<input type="submit" name="EventId" value="Submit Event Id"><br>

<input type="submit" name="Location" value="Submit Location"><br>

<input type="submit" name="BloodGroup" value="Submit Blood Group"><br>



</form>

</body></html>

 

 

 

 

Hi frds.............

I have two tables named "registration" and "participation". Registration table have some columns like "LoginId", "email","contact no.", "Name" etc.and participation table have 2 column named "LoginId" and "EventId".

Now if user enters EventId, I want to display the details like email,contact no. etc.

I have a code but it not works properly.......

If result have more than one row it only displays the email and contact no. of last one instead of all.

Plzzzzzzzzz help anyone...................

????????/

I have two tables named "registration" and "participation". Registration table have some columns like "LoginId", "email","contact no.", "Name" etc.and participation table have 2 column named "LoginId" and "EventId".

Now if user enters EventId, I want to display the details like email,contact no. etc.

I suggest you start learning SQL. The specific thing you want is called a "join".

SELECT fields FROM table1 JOIN table2 ON condition2 JOIN table3 ON condition3...

For example,

SELECT * FROM registration r JOIN participation p ON r.LoginId = p.LoginId WHERE r.Flag='A' AND r.Activity LIKE '%$Search%'

That will give you everything from both tables matching the flag/activity search criteria.

 

I have a code but it not works properly.......

If result have more than one row it only displays the email and contact no. of last one instead of all.

Plzzzzzzzzz help anyone...................

????????/

If you execute the exact same query in something like phpMyAdmin, do you get all the results you expect?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.