Jump to content

Only Shows 'Description' (Numbers?)


justlukeyou

Recommended Posts

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?

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. 

 

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.

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

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/>";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.