First result doesn't show.

sarvar

New Member
Messages
82
Reaction score
0
Points
0
Hey x10 members,

I'm working on a site that streams mp3 from different server (http://www.hotlinkfiles.com). My mp3 page lists all results from the search query. When I type a query which has 1 matching result, page doesn't list it. If I type query that has 2 or more matches it lists them but the first result. So like if I type 50 cent with 3 results:

I get in the list, 2 songs of him.
50 Cent - Candy Shop << doesn't show
50 Cent - 21 Questions
50 Cent - 50 Bars

If I type Akon which has one song, It doesn't error and doesn't list.

I used smarty function foreach to list results.

my mp3.php
PHP:
<?php

// Include main template system
include('default.php');

// Check if user is banned
is_banned();
         
// Site Name
$smarty->assign('site_page', 'Mp3');

$content = "<center><div id=\"search\">
            <form method=\"get\" action=\"mp3.php\">
            <input id=\"search-text\" type=\"text\" name=\"query\" size=\"15\" />
            <input type=\"submit\" id=\"search\" value=\"Search\" />
            </form>
            </div></center><br />
            <p><a href=\"mp3.php?query=Sarvar\">Sarvar</a></p>
            <p><a href=\"mp3.php?query=Shoxrux\">Shoxrux</a></p>
            <p><a href=\"mp3.php?query=Sogdiana\">Sog'diana</a></p>";            
            
// Is there a query in the URL?
if (isset($_GET['query'])) {

    // Notify if user did not entered a query
    if ($_GET['query'] == null) {

    $smarty->assign('error', 'You did not enter a search term.');

    } else {
 
     // Query must be equal to or more than 3 characters
     $num_query = strlen($_GET['query']);

     if ($num_query < 3) {
     
     $smarty->assign('error', 'Query must be at least 3 characters long.');
     $smarty->assign('content', $content);
     $smarty->display('sunparlor_mp3.tpl');
     exit;
     
     }
 
     // Clean up the query
     $query = mysql_real_escape_string($_GET['query']);
     
     $search_sql = mysql_query("SELECT * FROM `mp3` WHERE (`title` LIKE '%".$query."%' OR `song_author` LIKE '".$query."' OR `album` LIKE '".$query."') AND (`active` > '0') ORDER BY `song_author`, `title` ASC");
     $search_rst = mysql_fetch_array($search_sql);
     
     // If requested query is found, get the results
     if (!$search_rst) {

          $query_outcome = stripslashes($_GET['query']);
         
         $content = "No matches found for: <a href=\"mp3.php?query=".$query_outcome."\">".$query_outcome."</a>
                    <br /><br />Search Again!            
                    <form method=\"get\" action=\"mp3.php\">
                    <input id=\"search-text\" type=\"text\" name=\"query\" size=\"15\" />
                    <input type=\"submit\" id=\"search\" value=\"Search\" />
                    </form>";
         
        } else {
        
         while($row = mysql_fetch_array($search_sql)) {
         
              $values[] = $row;
         
         }
         
         $content = "<b>Search Results for: <a href=\"mp3.php?query=".$query."\">".$query."</a></b>";
         
         $smarty->assign('listing', $values);
               
         }
         }
}

// Smarty Template System
$smarty->assign("values_database", $values_smarty);
$smarty->assign("content", $content);
$smarty->display('sunparlor_mp3.tpl');
?>

My mp3 template (smarty)
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>{$site_name} - {$site_page}</title>
<meta name="keywords" content="{$site_name}, {$site_page}, uzbek, mp3, music, o'zbekcha, musiqa, ashula, song, free, tekin" />
<meta name="description" content="{$site_name} uzbek mp3 search engine." />
<link href="styles/sunparlor.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="content">
<div id="back">
<!-- header begins -->
<div id="header">   
  <div id="logo">
  </div>
    <div id="menu">
        {$top_menu}
    </div>
</div>
<!-- header ends -->
<!-- content begins -->
 <div id="main"> 
    <div id="error">{$error}</div><div id="notice">{$notice}</div><div id="success">{$success}</div>
    <div id="top">
        <div id="bottom">
    <div id="right"><p>{$content}</p> 
    {foreach item="item" from="$listing"}
         <table border="0" width="100%" align="center">
            <tr>
            <td width="85%">
            <b>{$item.song_author}</b> - {$item.title}</td>
            <td width="7%">
            <object type="application/x-shockwave-flash"
            data="http://sarvar.x10hosting.com/player/musicplayer_f6.swf?&song_url=play.php?id={$item.mp3_id}" 
            width="17" height="17">
            <param name="movie" 
            value="http://sarvar.x10hosting.com/player/musicplayer_f6.swf?&song_url=play.php?id={$item.mp3_id}" />
            <img src="noflash.gif" 
            width="17" height="17" alt="Play" />
            </object></td>
            <td width="4%"><a href="../download.php?id={$item.mp3_id}"><img src="../images/sunparlor/download.png" alt="Download" name="Download" border="0"></a></td>
            <td width="4%"><a href="../invalid.php?id={$item.mp3_id}"><img src="../images/sunparlor/error.png" alt="Broken Link" name="Broken Link" border="0"></a></td>
            </tr></table>
    {/foreach}<BR />
    </div>
    </div>
    </div>
    <div id="left">        
            <h3>Menu</h3>
            <ul>
                <li>
                {$menu}
                </li>
            </ul>
            <br />
            {$google_ads}
            <br />        
    </div>
<!--content ends -->

<!--footer begins -->
</div>
</div>
{include file="sunparlor_footer.tpl"} 

</div>
<!-- footer ends-->
</body>
</html>

Thanks in advance.
 

scopey

New Member
Messages
62
Reaction score
0
Points
0
Well the problem lies in this part of the code:

PHP:
<?php
$search_sql = mysql_query("SELECT * FROM `mp3` WHERE (`title` LIKE '%".$query."%' OR `song_author` LIKE '".$query."' OR `album` LIKE '".$query."') AND (`active` > '0') ORDER BY `song_author`, `title` ASC");
     $search_rst = mysql_fetch_array($search_sql);

You requested the first row here...

Instead of using mysql_fetch_array here... Use mysql_num_rows... If it returns 0, there are no rows... So it will look like this:

PHP:
$search_sql = mysql_query("SELECT * FROM `mp3` WHERE (`title` LIKE '%".$query."%' OR `song_author` LIKE '".$query."' OR `album` LIKE '".$query."') AND (`active` > '0') ORDER BY `song_author`, `title` ASC");
     $search_count = mysql_num_rows($search_sql);
     
     // If requested query is found, get the results
     if ($search_count === 0) { //'===' because mysql_num_rows can return false on error.

          $query_outcome = stripslashes($_GET['query']);
         
         $content = "No matches found for: <a href=\"mp3.php?query=".$query_outcome."\">".$query_outcome."</a>
                    <br /><br />Search Again!            
                    <form method=\"get\" action=\"mp3.php\">
                    <input id=\"search-text\" type=\"text\" name=\"query\" size=\"15\" />
                    <input type=\"submit\" id=\"search\" value=\"Search\" />
                    </form>";
         
        } else {
        
         while($row = mysql_fetch_array($search_sql)) {
         
              $values[] = $row;
         
         }
 
Top