Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you search two MySQL Table/Rows at the same time and return two separate results?
    text
    copied!<p><strong>FUNCTION OF SCRIPT</strong> : To allow users to search for artist name or song title</p> <p><strong>Benefit to other users</strong> : script can be easily modified for other stackoverflow users to work and search their sites - just change the query to your database structure.</p> <pre><code>$query_Recordset1 = sprintf("SELECT * FROM lyrics WHERE title LIKE '%%%s%%' ORDER BY title ASC", $colname_Recordset1); </code></pre> <p><strong>ISSUE with script</strong> : It works for song title, but I do not understand how to make it search for Artist name and Song title at the same time without using a dropdown that changes the search. Also returns error upon no result(s)</p> <p>An example of artist (Rihanna - id : 16689) (title : Unfaithful - id : 228106) <a href="http://www.thelyricsfinder.com/song.php?sid=228106&amp;aid=16689" rel="nofollow">http://www.thelyricsfinder.com/song.php?sid=228106&amp;aid=16689</a></p> <p><a href="http://thelyricsfinder.com/search.php" rel="nofollow">Live/Working Example of Search.php</a></p> <ul> <li>Received error output upon no results (below)</li> </ul> <p>..</p> <blockquote> <p>ERROR :<br/> You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1</p> </blockquote> <pre><code>$maxRows_Recordset1 = 100; $pageNum_Recordset1 = 0; if (isset($_GET['pageNum_Recordset1'])) { $pageNum_Recordset1 = $_GET['pageNum_Recordset1']; } $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1; $colname_Recordset1 = "-1"; if (isset($_POST['term'])) { $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_POST['term'] : addslashes($_POST['term']); } mysql_select_db($database_main, $main); $query_Recordset1 = sprintf("SELECT * FROM lyrics WHERE title LIKE '%%%s%%' ORDER BY title ASC", $colname_Recordset1); $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1); $Recordset1 = mysql_query($query_limit_Recordset1, $main) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); if (isset($_GET['totalRows_Recordset1'])) { $totalRows_Recordset1 = $_GET['totalRows_Recordset1']; } else { $all_Recordset1 = mysql_query($query_Recordset1); $totalRows_Recordset1 = mysql_num_rows($all_Recordset1); } $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1; </code></pre> <p><strong>OBJECTIVE</strong> : To make the script search two table/rows from the single search being passed to $_POST['term'] BUT THE KICKER return the results into two separate variables for separate display.</p> <ol> <li>ARTIST/artist</li> <li>LYRICS/title</li> </ol> <p>thanks for helping me find how to do this. back to the books to try to get the answer.</p> <p>ADDED 11/2/2012 (I know I can help fix part of the issue by adding no results found handling below thanks for the help below guys, now I need to learn how to do the two queries at once)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload