Hi:
Problem:
Whenever a record contain a mixed_artist_id, the record will not show in the search. Are there anyway to show the record that contain mixed_artist_id in a search???
table structure:
Table:artist
-artist_id
-artist_name
-english_name
-gender
-region
table:lyric
-lyric_id
-artist_id int(255)
-song_title
-lyric
-mixed_artist_id
my query to get database data
<?php
include ('connect.php');
if( isset( $_GET['search'] ) && !empty( $_GET['search'] ) )
{
$rowsPerPage = 10;
$pageNum = 1;
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
$keywords = explode(" ", $search);
$query = "SELECT * FROM artist LEFT OUTER JOIN lyric on (artist.artist_id = lyric.artist_id) WHERE artist_name LIKE '%".$keywords['0']."%' OR song_title LIKE '%".$keywords['0']."%' OR english_name LIKE '%".$keywords['0']."%' OR lyric LIKE '%".$keywords['0']."%' LIMIT $offset, $rowsPerPage ";
$result2 = mysql_query($query) or die(mysql_error());
?>
<?php
$query1 = "SELECT * FROM artist LEFT OUTER JOIN lyric on (artist.artist_id = lyric.artist_id) WHERE artist_name LIKE '%".$keywords['0']."%' OR song_title LIKE '%".$keywords['0']."%' OR english_name LIKE '%".$keywords['0']."%' OR lyric LIKE '%".$keywords['0']."%'";
$result = mysql_query($query1) or die('Error, query failed');
$numrows = mysql_num_rows($result);
Full Source of the search engine
<?php
include ('connect.php');
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
$keywords = explode(" ", $search);
$query = "SELECT * FROM artist LEFT OUTER JOIN lyric on (artist.artist_id = lyric.artist_id) WHERE artist_name LIKE '%".$keywords['0']."%' OR song_title LIKE '%".$keywords['0']."%' OR english_name LIKE '%".$keywords['0']."%' OR lyric LIKE '%".$keywords['0']."%' LIMIT $offset, $rowsPerPage ";
$result2 = mysql_query($query) or die(mysql_error());
?>
<?php
$query1 = "SELECT * FROM artist LEFT OUTER JOIN lyric on (artist.artist_id = lyric.artist_id) WHERE artist_name LIKE '%".$keywords['0']."%' OR song_title LIKE '%".$keywords['0']."%' OR english_name LIKE '%".$keywords['0']."%' OR lyric LIKE '%".$keywords['0']."%'";
$result = mysql_query($query1) or die('Error, query failed');
$numrows = mysql_num_rows($result);
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);
// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nav .= "<font color=\"00BFFF\"><b>$page</b></font>";
}
else
{
$nav .= " <a href=\"?search=$search&page=$page\">$page</a> ";
}
}
// creating previous and next link
// plus the link to go straight to
// the first and last page
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"?search=$search&page=$page\"> <b>[上一頁]</b> </a> ";
$first = " <a href=\"?search=$search&page=1\"> <b>[第一頁]</b> </a> ";
}
else
{
$prev = ' ';
$first = ' ';
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"?search=$search&page=$page\"> <b>[下一頁]</b> </a> ";
$last = " <a href=\"?search=$search&page=$maxPage\"> <b>[最後一頁]</b> </a> ";
}
else
{
$next = ' ';
$last = ' ';
}
$navigate = '搜索結果:' . $numrows . '個結果';
include ('template/header.php');
echo "<font color=\"00BFFF\"><b><u>搜索結果: ".$numrows."個結果 </u></b></font> <br \><br \>";
echo "<table width=\"75%\" height=\"100%\" border=\"0\" valign=\"top\"><tr><td valign=\"top\">";
while($row = mysql_fetch_array($result2))
{
$artist_id = $row['artist_id'];
$artist_name = $row['artist_name'];
$english_name = $row['english_name'];
$song_title = $row['song_title'];
$lyric_id = $row['lyric_id'];
$lyric = $row['lyric'];
$lyric_string = substr("$lyric", 0, 250);
echo stripslashes("<a href=\"show.php?artist_id=$artist_id\"><b>$artist_name $english_name</b></a> - <a href=\"lyric.php?action=lyric&lyric_id=$lyric_id\">$song_title</a><br>");
echo "<font color=\"6699FF\"><font size=\"-1\">";
echo stripslashes(wordwrap( $lyric_string. ".....<br /><br /> </font></font>"));
}
echo "</td></tr></table>";
echo "<br><center><font color=\"00BFFF\">Page $pageNum of $maxPage </font></center> <br \>";
echo "<center><font color=\"00BFFF\">".$first . $prev . $nav . $next . $last."</font></center>";
} else {
echo "<table weight=\"75%\" height=\"100%\" border=\"0\" valign=\"top\"><tr><td valign=\"top\">";
echo "<br><font color=\"00BFFF\"><b>沒有搜索結果</b></font>";
echo "</td></tr>";
echo "</table>";
}
?>
<?
include ('template/footer.php');
?>