chemicaluser Posted April 11, 2011 Share Posted April 11, 2011 I have a database with two tables, they are designed like this Table1 has two fields (log_number, name) Table2 has two fields (log_number, city) I would like to do a search for a specific log number and display only one result for that matching log number (that we searched for) and display something like this Log Number: 59 Name: Mark City: Chicago this is my code so far my search form <form method="get" action="search.php" /> Log Number <input type="text" id="log_number" name="log_number" /> <input type="submit" name="submit" value="Search" /> the search.php file <?php require ('/sqlconnect.php'); $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $log_number = $_GET['log_number']; $name = $_GET['name']; $city = $_GET['city']; $query = "SELECT * FROM table1, table2 WHERE table1.log_number = table2.log_number"; $result = mysqli_query ($dbc, $query); while ($row = mysqli_fetch_array($result)) { echo '<b>Log Number:</b> '.$row['log_number'].'</td>'; echo '<br/>'; echo '<b>Name:</b> '.$row['name'].'</td>'; echo '<br/>'; echo '<b>City:</b> '.$row['city'].'</td>'; } mysqli_close($dbc); ?> the problem I am having with my current code is that it does not display the results of the log number i searched for, but instead returns information for all the entries (two in my case) that have matching log numbers in both table1 and table2 when i search for log number 59, i get the following result Log Number: 59 Name: Mark City: Chicago Log Number: 77 Transport Company: Doug Customer Number: San Francisco the result that I want is when i search for log number 59 ... i want it to only display that one record Log Number: 59 Name: Mark City: Chicago hope someone can help Quote Link to comment https://forums.phpfreaks.com/topic/233326-inner-join-search-help/ Share on other sites More sharing options...
chemicaluser Posted April 11, 2011 Author Share Posted April 11, 2011 So i have figured out what the problem was with my query ... i was not searching for the log number my original query code $query = "SELECT * FROM table1, table2 WHERE table1.log_number = table2.log_number"; should have been $query = "SELECT * FROM table1, table2 WHERE table1.log_number = table2.log_number and table1.log_number like '$search'"; Quote Link to comment https://forums.phpfreaks.com/topic/233326-inner-join-search-help/#findComment-1200178 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.