Pikachu2000 Posted February 20, 2011 Share Posted February 20, 2011 They don't belong there; they'll cause only the last record retrieved to be echoed. Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/page/2/#findComment-1177274 Share on other sites More sharing options...
justlukeyou Posted February 20, 2011 Author Share Posted February 20, 2011 Thanks, Im trying everything I can think of but that isn't right. Is there anything I can do? I know "description" is the right field name. Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/page/2/#findComment-1177277 Share on other sites More sharing options...
Pikachu2000 Posted February 20, 2011 Share Posted February 20, 2011 I think you may have a very fundamental misunderstanding of how this works. WHERE description = '$description' What the above means is "where the value of the contents of the database field `description` is identical to the value of the variable $description". I.E. If the `description` field in a particular record is 'this is the best gadget of all time.', the only way it will match is if $description = 'this is the best gadget of all time.' Does that shed any light on this? Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/page/2/#findComment-1177281 Share on other sites More sharing options...
justlukeyou Posted February 20, 2011 Author Share Posted February 20, 2011 Hi, Yes but this isn't working. If I have "red widget" in my database under 'description' but then search for: ?description=redwidget ?description=red-widget ?description=red ?description=widget All I get at the moment all I get is a blank screen. However, I know that I have a 'red widget' in 'description' because I can display them using the ID number. However, I am trying to do by using the description but I am getting very stuck on this. However, if I search for: php?description=description I get everything displayed from my database. Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/page/2/#findComment-1177287 Share on other sites More sharing options...
Pikachu2000 Posted February 20, 2011 Share Posted February 20, 2011 No, it won't return any results because you're asking it for an exact match. 'red widget' is not the same as 'redwidget', red-widget', 'red' or 'widget'. However, if I search for: php?description=description I get everything displayed from my database. If that's the case, you've removed the quotes from around '$description' in the query string again, even though it's been pointed out several times that they are absolutely required when comparing string type data. Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/page/2/#findComment-1177298 Share on other sites More sharing options...
kenrbnsn Posted February 20, 2011 Share Posted February 20, 2011 If you want to search for something that is a partial match you need to use the mysql "like" operator with the wild character "%" <?php $query = "SELECT * FROM productfeed WHERE description like '%$description%' LIMIT 0, 10"; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/page/2/#findComment-1177307 Share on other sites More sharing options...
litebearer Posted February 20, 2011 Share Posted February 20, 2011 Building upon what Kenr said, as well as others, create a simple test php file per the below. then run it <?php /* database connection here */ $match = "red"; $query = "SELECT * FROM productfeed WHERE description LIKE '%$match%'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)){ echo $row['description'] . " " . strlen($row['description']) . "<br/>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/page/2/#findComment-1177313 Share on other sites More sharing options...
justlukeyou Posted February 21, 2011 Author Share Posted February 21, 2011 Hi, A big thank you everyone, as soon as popped this in it worked a treat: $query = "SELECT * FROM productfeed WHERE description like '%$description%' LIMIT 0, 10"; Six months ago I never thought PHP could be so powerful. Quote Link to comment https://forums.phpfreaks.com/topic/228024-only-shows-description-numbers/page/2/#findComment-1177849 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.