PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
stanleycwb
Forum Newbie
Posts: 23 Joined: Fri Aug 15, 2008 11:33 am
Post
by stanleycwb » Fri Aug 29, 2008 9:21 pm
Code: Select all
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1-traditional.dtd">
<?php
$Stud_Name = $_POST['Stud_Name'];
$Stud_ID = $_POST['Stud_ID'];
$Gender = $_POST['Gender'];
$Course_Code = $_POST['Course_Code'];
$Occupation = $_POST['Occupation'];
$Year_of_Admission = $_POST['Year_of_Admission'];
$Year_of_Grad = $_POST['Year_of_Grad'];
$Gender = $_POST['Gender'];
$Course_Code = $_POST['Course_Code'];
$Occupation = $_POST['Occupation'];
$Year_of_Admission = $_POST['Year_of_Admission'];
$Year_of_Grad = $_POST['Year_of_Grad'];
$Stud_OContact = $_POST['Stud_OContact'];
$Stud_HContact = $_POST['Stud_HContact'];
$Stud_HPContact = $_POST['Stud_HPContact'];
$conn = mysqli_connect("localhost", "xx", "xxx", "xxxx") or die("Unable to connect!");
if (mysqli_connect_errno())
{
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$sql = "SELECT * FROM Student WHERE ";
foreach($_POST as $key => $value) {
if(isset($value)) {
$sql .= "`$key` LIKE '%$value%' AND ";
}
}
$sql = substr($sql,0,strripos($sql," AND "));
$query1 = mysqli_query($conn, $sql) or die("Query failed! " . mysql_error() . "<br>". $sql);
$num_results = @mysqli_num_rows($query1);
printf("<h1>%d student(s) found.\n</h1>", $num_results);
print "<table border=2>";
while ($result1 = mysqli_fetch_array($query1))
{
extract($result1); // assigns $ variables for all the elements in the array
print"<tr>";
print "<td><b> Student ID: </b></td> <td>$Stud_ID</td>";
print"<tr></tr>";
print "<td><b> Student Name: </b></td ><td>$Stud_Name</td>";
print "<tr></tr>";
print "<td><b>Date Of Birth</b> </td> <td>$DOB</td>";
print "<tr></tr>";
print "<td><b> Gender: </b></td> <td>$Gender</td>";
print"<tr></tr>";
print "<td><b> Address: </b></td ><td>$Address</td>";
print "<tr></tr>";
print "<td><b>Office Contact</b> </td> <td>$Stud_OContact</td>";
print "<tr></tr>";
print "<td><b> Handphone Contact: </b></td> <td>$Stud_HPContact</td>";
print"<tr></tr>";
print "<td><b> Home Contact: </b></td ><td>$Stud_HContact</td>";
print "<tr></tr>";
print "<td><b>Email Address</b> </td> <td>$Email</td>";
print "<tr></tr>";
print "<td><b>Occupation</b> </td> <td>$Occupation</td>";
print "<tr></tr>";
print "<td><b> Course Code: </b></td> <td>$Course_Code</td>";
print"<tr></tr>";
print "<td><b> Admission Year: </b></td ><td>$Year_of_Admission</td>";
print "<tr></tr>";
print "<td><b>Graduation Year</b> </td> <td>$Year_of_Grad</td>";
print "<tr></tr>";
print "<br>";
};
print "</table>";
mysqli_close($conn);
?>
Hi, above is my search php coding. It doesnt pose any problems however, i want to display the information of the result from another table as well. Example like i search joan, joan's id, name, address, contact information will appears. But i want to display the employment details of her which is another table of the database.
I need help!!!
Can anyone help me???
Last edited by
stanleycwb on Fri Aug 29, 2008 11:23 pm, edited 1 time in total.
califdon
Jack of Zircons
Posts: 4484 Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA
Post
by califdon » Fri Aug 29, 2008 11:06 pm
Before posting in this forum,
please read the rules at
viewtopic.php?t=8815 , especially the one that says:
Before Post Read - General Posting Guidelines wrote: Write a clear subject line, it'll help people deciding whether to look at your post or not - 'help, PHP noob' is probably going to be ignored by some.
It sounds like you want to use a Join Query. Look up how to do that in any tutorial. I'd recommend
http://w3schools.com .
stanleycwb
Forum Newbie
Posts: 23 Joined: Fri Aug 15, 2008 11:33 am
Post
by stanleycwb » Fri Aug 29, 2008 11:29 pm
Code: Select all
print "<table border=2>";
while ($result1 = mysqli_fetch_array($query1))
{
extract($result1); // assigns $ variables for all the elements in the array
print"<tr>";
print "<td><b> Student ID: </b></td> <td>$Stud_ID</td>";
print"<tr></tr>";
print "<td><b> Student Name: </b></td ><td>$Stud_Name</td>";
print "<tr></tr>";
print "<td><b>Date Of Birth</b> </td> <td>$DOB</td>";
print "<tr></tr>";
print "<td><b> Gender: </b></td> <td>$Gender</td>";
print"<tr></tr>";
print "<td><b> Address: </b></td ><td>$Address</td>";
print "<tr></tr>";
print "<td><b>Office Contact</b> </td> <td>$Stud_OContact</td>";
print "<tr></tr>";
print "<td><b> Handphone Contact: </b></td> <td>$Stud_HPContact</td>";
print"<tr></tr>";
print "<td><b> Home Contact: </b></td ><td>$Stud_HContact</td>";
print "<tr></tr>";
print "<td><b>Email Address</b> </td> <td>$Email</td>";
print "<tr></tr>";
print "<td><b>Occupation</b> </td> <td>$Occupation</td>";
print "<tr></tr>";
print "<td><b> Course Code: </b></td> <td>$Course_Code</td>";
print"<tr></tr>";
print "<td><b> Admission Year: </b></td ><td>$Year_of_Admission</td>";
print "<tr></tr>";
print "<td><b>Graduation Year</b> </td> <td>$Year_of_Grad</td>";
print "<tr></tr>";
print "<br>";
$sql2 = "SELECT * FROM jobs WHERE Stud_ID = $Stud_ID";
$query2 = mysqli_query($conn, $sql2) or die("Query2 failed! " . mysql_error() . "<br>". $sql);
print "<table border=2>";
while ($result2 = mysqli_fetch_array($query2))
{
extract($result2);
print "<td><b>Job Industry:</b> </td> <td>$Job_Industry</td>";
print "<tr></tr>";
print "<td><b>Job Position:</b> </td> <td>$Job_Position</td>";
print "<tr></tr>";
print "<td><b> Job Company: </b></td> <td>$Job_Company</td>";
print"<tr></tr>";
print "<td><b> Job Department: </b></td ><td>$Job_Department</td>";
print "<tr></tr>";
print "<td><b>Job Description:</b> </td> <td>$Job_Description</td>";
print "<tr></tr>";
print "<td><b> Job Start Date: </b></td> <td>$Job_Start_Date</td>";
print"<tr></tr>";
print "<td><b> Job End Date: </b></td ><td>$Job_End_Date</td>";
print "<tr></tr>";
print "</tr>";
};
print "</table>";
};
print "</table>";
I tried to use the above codes. But it couldnt work. I wanted it to display the first table 1st and then followed by second table. then next person will be first table then second table. And so on...
Why cant i do so?