ok here is my question, I have 2 tables one containing the address of a person and the other containing the address of church that he started. now i want to make it so that the data from the 2 tables (pastors_info and church_info) shows up with the address for the pastor fist then a <hr> and then it shows the churche(s) he has started then 2<hr>'s then the next pastor and churches and so on. I have pastors_id currently in both tables thinking that i could link the tables so that if pastors_info.pastors_id==church_info.pastors_id then it would show the pastors name and address first and then all of the churches he started but i can't figure it out. What should i do?
this script currently shows all the pastors along with all the churches weather or not the pastors_id is the same.
<?php
// First connect to database
$host = "localhost";
$dbuser = "email";
$dbpass = "qwe";
$db = "bhi_info";
$con = mysql_connect($host, $dbuser, $dbpass);
if(!$con){
die(mysql_error());
}
$select = mysql_select_db($db, $con);
if(!$select){
die(mysql_error());
}
// This will take all info from database where row tutorial is $item and collects it into $data variable
$data = mysql_query("SELECT * FROM pastors_info, church_info"); // INNER JOIN church_info ON pastors_info.pastor_id=church_info.pastor_id");
print ("Here is a list of all the Pastors addresses and the Church(s) that they have started. <br><hr>");
// This creates a loop which will repeat itself until there are no more rows to select from the database. We getting the field names and storing them in the $row variable. This makes it easier to echo each field.
while($row = mysql_fetch_array($data)){
echo $row['lname']. " "; echo $row['fname']. " ";
if (isset($row['wname']) && $row['wname'] != NULL && $row['wname'] != '') {
echo "&"; echo " "; echo $row['wname']. "<br>";
}
else {
echo "<br>";
}
if (isset($row['address']) && $row['address'] != NULL && $row['address'] != '') {
echo "Address: ".$row['address']. "<br>";
}
if (isset($row['city']) && $row['city'] != NULL && $row['city'] != '') {
echo "City: ".$row['city']. "<br>";
}
if (isset($row['district']) && $row['district'] != NULL && $row['district'] != '') {
echo "District: ".$row['district']. " ";
}
if (isset($row['pc']) && $row['pc'] != NULL && $row['pc'] != '') {
echo "Postal Code: ".$row['pc']. "<br>";
}
if (isset($row['state']) && $row['state'] != NULL && $row['state'] != '') {
echo "State: ".$row['state']. "<br>" ;
}
if (isset($row['email']) && $row['email'] != NULL && $row['email'] != '') {
echo "Email Address: ".$row['email']. "<br>";
}
if (isset($row['landline']) && $row['landline'] != NULL && $row['landline'] != '') {
echo "Landline: ".$row['landline']. "<br>";
}
if (isset($row['mobile']) && $row['mobile'] != NULL && $row['mobile'] != '0' && $row['mobile'] != '') {
echo "Mobile: ".$row['mobile']. "<br>";
}
if (isset($row['notes']) && $row['notes'] != NULL && $row['notes'] != '') {
echo "Notes: ".$row['notes']. "<br>";
}
echo "<hr>"."Church Address: <br>";
echo "Church ID: ".$row['church_id']."<br>";
if (isset($row['c_address']) && $row['c_address'] != NULL && $row['c_address'] != '') {
echo "Address: ".$row['c_address']. "<br>";
}
if (isset($row['c_city']) && $row['c_city'] != NULL && $row['c_city'] != '') {
echo "City: ".$row['c_city']. "<br>";
}
if (isset($row['c_state']) && $row['c_state'] != NULL && $row['c_state'] != '') {
echo "State: ".$row['c_state']. "<br>" ;
}
if (isset($row['c_district']) && $row['c_district'] != NULL && $row['c_district'] != '') {
echo "District: ".$row['c_district']. "<br>";
}
if (isset($row['c_pc']) && $row['c_pc'] != NULL && $row['c_pc'] != '') {
echo "Postal Code: ".$row['c_pc']. "<br>";
}
if (isset($row['notes']) && $row['notes'] != NULL && $row['notes'] != '') {
echo "Notes: ".$row['notes']. "<br>";
}
echo "<hr>"."<hr>";
}
mysql_close($con);
?>