+ Reply to Thread
Results 1 to 3 of 3

Thread: First result doesn't show.

  1. #1
    sarvar's Avatar
    sarvar is offline x10Hosting Member sarvar is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    82

    First result doesn't show.

    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 Code:
    <?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.
    CLICK HERE to Thank Me.
    (You must be logged in into forums.)

  2. #2
    scopey is offline x10Hosting Member scopey is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    62

    Re: First result doesn't show.

    Well the problem lies in this part of the code:

    PHP Code:
    <?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 Code:
    $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;
             
             } 
    - When in doubt, refer to the PHP manual.

  3. #3
    sarvar's Avatar
    sarvar is offline x10Hosting Member sarvar is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    82

    Re: First result doesn't show.

    That fixed the problem. Thanks.
    CLICK HERE to Thank Me.
    (You must be logged in into forums.)

+ Reply to Thread

Similar Threads

  1. Replies: 14
    Last Post: 09-29-2008, 07:07 PM
  2. New Site-Suggestions?
    By mnoutside in forum Review My Site
    Replies: 9
    Last Post: 08-27-2008, 07:01 AM
  3. Need show script
    By disturbedart in forum Programming Help
    Replies: 2
    Last Post: 06-16-2008, 09:46 AM
  4. Ads won't show up
    By Grandcruiser in forum Free Hosting
    Replies: 2
    Last Post: 09-21-2007, 01:23 AM
  5. Have a problem with my forum
    By tikloos in forum Scripts & 3rd Party Apps
    Replies: 43
    Last Post: 01-19-2006, 01:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers