Jump to content

$ in mysql field


imperium2335

Recommended Posts

I have tried that, the php is comparing what the user selected from a drop down box e.g. Under £500 or $750

 

Then in the database i have afew test records, some have Under £500 or $750 as a varchar. But if i try to search for records with Under £500 or $750 i get a white page (doesnt work, dont know how to get php error handling to work on my localhost im using apache).

 

Cheers.

Link to comment
https://forums.phpfreaks.com/topic/149207-in-mysql-field/#findComment-783579
Share on other sites

in that case, the query would only return the cells that contain exactly the value of $price.

 

for instance

if you have

$price = "cheap";

 

if you don't put any % in the query

$q = "price LIKE '$price'";

 

it would return only

cheap

 

if you put a % in front of it in your query

$q = "price LIKE '%$price'";

 

it would return the cells containing

cheap

very cheap

 

if you put a % behind it

$q = "price LIKE '$price%'";

 

it would return

cheap

cheap a hell

 

and if you use both

$q = "price LIKE '%$price%'";

 

you'd get

cheap

very cheap

very cheap indeed

cheap as hell

Link to comment
https://forums.phpfreaks.com/topic/149207-in-mysql-field/#findComment-783596
Share on other sites

Hi

 

Php is not going to do a variable substitution for a string which has had a variable concatenated into it whcih just happens to contain a $. It is did then potentially it would create an infinate loop.

 

If you had a variable assignment that was $burt = "hello there ".$fred; while $fred contained '$bill' and you had a variable called $bill containing 100 then you could manage to get $burt to contain "hello there 100" with:-

 

$burt = "hello there ".$fred;

$burt = eval($burt);

 

All the best

 

Keith

Link to comment
https://forums.phpfreaks.com/topic/149207-in-mysql-field/#findComment-783604
Share on other sites

Hey guys thanks for your help. I will try your ideas when i get home.

 

dgoosens you answered a question i didn't think of yet :D

 

I was going to ask how to check fields that had many keywords in them and return the result if the user entered just one of them. I guess using your explanations I can do that quite easily, thanks!

Link to comment
https://forums.phpfreaks.com/topic/149207-in-mysql-field/#findComment-783625
Share on other sites

Here is my code:

 

<?PHP

if (!file_exists("dbconnect.php"))

{

die("Database settings not found, administrator intervention required.") ;

}

else

{

require("dbconnect.php") ; //Must connect to the database.

}

 

$word = $_REQUEST['word'] ; //Variables from the form.

$type = $_REQUEST['type'] ;

$flavor = $_REQUEST['flavor'] ;

$tiers = $_REQUEST['tiers'] ;

$serves = $_REQUEST['serves'] ;

$price = $_REQUEST['price'] ;

 

$def = "Dont Specify" ;

 

if(!isset($word) || $word == "Enter Search Term" || $word == "")

{

unset($word) ;

}

if($type == $def)

{

unset($type) ;

}

if($flavor == $def)

{

unset($flavor) ;

}

if($tiers == $def)

{

unset($tiers) ;

}

if($serves == $def)

{

unset($serves) ;

}

if($price == $def)

{

unset($price) ;

}

 

if(!isset($word) && !isset($type) && !isset($flavor) && !isset($tiers) && !isset($serves) && !isset($price))

{

echo "You did not specify any search parameters" ;

die ;

}

 

if(isset($word))

{

$wordx =  "tags LIKE '%$word%'" ;

}

 

if(isset($type))

{

if(isset($word))

{

$typex = "&& type LIKE '%$type%'" ;

}

else

$typex = "type LIKE '%$type%'" ;

}

 

if(isset($flavor))

{

if(isset($word) || isset($type))

{

$flavorx = "&& flavor LIKE '%$flavor%'" ;

}

else

$flavorx = "flavor LIKE '%$flavor%'" ;

}

 

if(isset($tiers))

{

if(isset($word) || isset($type) || isset($flavor))

{

$tiersx = "&& tiers LIKE '%$tiers%'" ;

}

else

$tiersx = "tiers LIKE '%$tiers%'" ;

}

 

if(isset($serves))

{

if(isset($word) || isset($type) || isset($flavor) || isset($tiers))

{

$servesx = "&& serves LIKE '%$serves%'" ;

}

else

$servesx = "serves LIKE '%$serves%'" ;

}

 

if(isset($price))

{

if(isset($word) || isset($type) || isset($flavor) || isset($tiers) || isset($serves))

{

$pricex = "&& price LIKE '%$price%'" ;

}

else

$pricex = "price LIKE '%$price%'" ;

}

 

$query = "SELECT * FROM image_bank WHERE $wordx $typex $flavorx $tiersx $servesx $pricex" ;

 

$result = mysql_query($query) ;

 

while($row = mysql_fetch_array($result, MYSQL_ASSOC))

{

$dbtags = $row['tags'] ;

$dbtiers = $row['tiers'] ;

$dbtype = $row['type'] ;

$dbflavor = $row['flavor'] ;

$dbserves = $row['serves'] ;

$dbprice = $row['price'] ;

$imgurl = $row['url'];

$thumburl = $row['thumb_url'] ;

 

echo "$dbtags" . "<br />" ;

echo "$dbtiers" . "<br />" ;

echo "$dbtype" . "<br />" ;

echo "$dbflavor" . "<br />" ;

echo "$dbserves" . "<br />" ;

echo "$dbprice" . "<br />" ;

echo '<a href="' . "$imgurl" . '">' . "$imgurl" . "</a>" . "<br />" ;

echo '<img src="' . "$thumburl" . '" height="100" width="50" />' ;

 

 

}

 

include("dbdisconnect.php") ;

 

?>

Link to comment
https://forums.phpfreaks.com/topic/149207-in-mysql-field/#findComment-783681
Share on other sites

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.