Hello,
I really hope you can help me, I’m struggling a lot with this.
I have set up a MySQL database with three tables and foreign keys:
Merchants
Issues (FK MerchantID to Merchants > MerchantID)
Updates (FK IssueID to Issues > IssueID)
I want my users to search for a merchant - if their search term is close/matches the merchant’s name, the Merchant’s details are output first, then it automatically outputs all issues that the merchant has, and beneath each issue, automatically outputs all updates that issue has.
I have tried the below code which I found on another website, and tried modifying it but have inevitably broken it.
[php]<?php
$query = $_GET[‘query’];
$min_length = 3;
if(strlen($query) >= $min_length){
$query = htmlspecialchars($query);
$query = mysql_real_escape_string($query);
$raw_results = mysql_query("SELECT * FROM Merchants JOIN Issues using(MerchantID) JOIN Updates using(IssueID) WHERE Name LIKE '%$query%'") or die(mysql_error());
if(mysql_num_rows($raw_results) > 0){
while($results = mysql_fetch_array($raw_results)){
echo "Merchant Name: ".$results['Name']."<br />Phone: ".$results['Phone']."<br />Email: <i>".$results['Privacy']."</i> ".$results['Email'];
echo "<p></p><b>Issue ID:</b> ".$results['IssueID']."<br /><b>Date:</b> ".$results['IssueDate']."<br /><b>Deal ID:</b> ".$results['DealID']."<br /><b>Deal Date <i>(valid from)</i>:</b> ".$results['DealDate']."<br /><b>Deal Title:</b> ".$results['DealTitle']."<br /><b>Category:</b> ".$results['Category']."<br /><b>Issue:</b><p></p>".$results['Issue']."<p><hr /></p><b>Solution:</b><p></p>".$results['Solution'];
echo "<p></p><b>Update Date:</b> ".$results['UpdateDate']."<br />Update: ".$results['Update'];
// posts results gotten from database(title and text) you can also show id ($results['id'])
}
}
else{
echo "No results";
}
}
else{
echo "Minimum length is ".$min_length;
}
?>[/php]
Is it obvious where I’m going wrong here? I’m sorry, quite new to all this…
thank you