Search
Left Quote    A clever person solves a problem. A wise person avoids it.
- Einstein    
Right Quote
 
[login] | [Register]
Forum Index » PHP and mySQL » Viewing Topic and Replies
Post Reply


        Viewing Topic: Search results returns 1 result everytime
  This user is offline  Genius
  Subject: "Search results returns 1 result eve..." Posted: @ 5:38 pm on Oct 25 2008   

Member #: 582
Rank: User - (77)
Since: 02/18/08
Posts: 76
From: kmmk

Hey, I'm having an issue with this search engine. When I search something that I have in my database, I get only 1 result even though I have 2 titles that match the query.

Here's my code:


Code:

<?php

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

// Site Name
$smarty->ass ign('site_page' , 'Mp3');

// Is there a query in the URL?
if (isset($_GET['q uery'])) {

if ($_GET['query'] == null) {

$content = "You did not search for anything." ;

}

// Clean up the query
$query = mysql_real_esca pe_string($_GET ['query']);

$search_sql = mysql_query(&qu ot;SELECT `mp3_id`, `title`, `song_author`, `genre`, `album` FROM `mp3` WHERE `title` LIKE '%".$query ."%' OR `song_author` LIKE '%".$query ."%' OR `genre` LIKE '%".$query ."%' OR `album` LIKE '%".$query ."%' LIMIT 0, 30";

$search_row = mysql_fetch_ass oc($search_sql) ;


if ($search_row > 1) {

$content = "<b> ".$search_ row['song_autho r']."</ b> - ".$search_ row['title'].&q uot;
<object type=\"app lication/x-shoc kwave-flash\&qu ot;
data=\"htt p://sarvar.x10h osting.com/play er/musicplayer_ f6.swf?&son g_url=file.php? id=".$sear ch_row['mp3_id' ]."\"
width=\"17 \" height=\"1 7\">
<param name=\"mov ie\"
value=\"ht tp://musicplaye r.sourceforge.n et/button/music player.swf?& ;playlist_url=? playlist_url=al lshows.xspf& ;\" />
<img src=\"nofl ash.gif\"
width=\"17 \" height=\"1 7\" alt=\"\&qu ot; />
</object> <BR />";

} else {

$query_outcome = stripslashes($_ GET['query']);

$content = "No matches found for: <a href=\"mp3 .php?query=&quo t;.$query_outco me."\" ;>".$qu ery_outcome.&qu ot;</a>&q uot;;

}
}

// Smarty Template System
$smarty->ass ign('body', $content);
$smarty->dis play('custom.tp l');
?>



I think you could do it with foreach() function, but I've never used foreach() before so I don't exactly know how it works.

P.S: I clicked Disable Smilies before edit, and I still have smilies in my code :(

Edited at 05:49:02 pm on 10/25/08


    Viewed: 4,530 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Search results returns 1 result..." Posted: @ 6:04 pm on Oct 25 2008    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

I really don't see where you're looping through your results.

Just try: while($x = mysql_fetch_obj ect($search_sql )) {

//display results
echo($x->tit le);

} //end while

*note: it appears as though disable smilies works in replies if you disable before edit. Hmmm...



Edited at 06:06:40 pm on 10/25/08


-bs0d | AllSyntax.com

    Viewed: 4,521 Times | Reply to This | To top
  This user is offline  Genius
  Subject: "re: Search results returns 1 result..." Posted: @ 11:55 pm on Oct 25 2008    

Member #: 582
Rank: User - (77)
Since: 02/18/08
Posts: 76
From: kmmk

FIXED:

PHP didn't help with smarty variable, smarty build in function helped.

This is what I used in template file:

{foreach item="val uesdb" from="$va lues_database& quot;}
{$valuesdb.song _author} {$valuesdb.titl e}
{/foreach}

the while loop also helped me, thanks bs0d.



Edited at 02:59:24 pm on 10/26/08


    Viewed: 4,511 Times | Reply to This | To top
Viewing Page: 1 of 1


1 |

You must be logged in to post on the forums. Login or Register








"AllSyntax.com" Copyright © 2002-2018; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank