[UPHPU] Table Relationships

Webot Graphics graphics at westernbotanicals.com
Fri Apr 6 12:27:05 MDT 2007


I am having a problem retrieving the foreign key data. I could be  
doing this all wrong, but the first search is working and no errors  
pop up, I just don't get the customer name or the product name  
showing up.

if (isset($_GET['search'])) {
     echo ('<h5>Search Results:</h5>');
	// select query
	$searchstring = ($_GET['search']);
	$sql = "SELECT *, MATCH (Customer_Product_Name) AGAINST  
('$searchstring') AS score FROM Customer_Product_Names WHERE MATCH  
(Customer_Product_Name) AGAINST ('$searchstring')";
	//$sql = "SELECT * FROM Customer_Product_Names WHERE  
Customer_Product_Name = ('$searchstring') ";
	$result = @mysql_query($sql);
	if (!$result) {
		 exit('<p>Error performing query: ' . mysql_error() . '</p>');
	}
	
	echo('<table>');
	
	while ($row = mysql_fetch_array($result)) {
		$Product_ID=$row['Product_ID'];
		$Customer_ID=$row['Customer_ID'];
		$Customer_Product_Name=$row['Customer_Product_Name'];
		$sql1 = "SELECT Product_Name FROM Products WHERE Product_ID =  
('$Product_ID')";
		$result1 = @mysql_query($sql1);
		if (!$result1) {
			exit('<p>Error performing query 1: ' . mysql_error() . '</p>');
		}
		while ($row1 = mysql_fetch_array($result1)) {
			echo('<tr><td>' . $row['Product_Name'] . '</td>');
		}
		$sql2 = "SELECT Customer_Name FROM Customer_Names WHERE Customer_ID  
= ('$Customer_ID')";
		$result2 = @mysql_query($sql1);
		if (!$result2) {
			exit('<p>Error performing query 2: ' . mysql_error() . '</p>');
		}
		while ($row2 = mysql_fetch_array($result2)) {
			echo('<td>' . $row['Customer_Name'] . '</td>');
		}
		echo ('<td>' . $Customer_Product_Name . '</td></tr>');
	}
	
	echo('</table>');
}


thanks

Justin Giboney
Graphic Design
Western Botanicals
Ph:800.651.4372, Fax:866.366.4372




More information about the UPHPU mailing list