selecting all from database where string contains price...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hairytea
Forum Commoner
Posts: 92
Joined: Mon Feb 04, 2008 8:31 am

selecting all from database where string contains price...

Post by hairytea »

I want to display results based on price being high to low or vice versa...

The string in the database field is always going to be something alog the lines of..."2 night price from £675 per person in a Superior River Wing Room. Flights and tranfsers available on request."!

I want to match the £price section of the string and return results between a given starting and ending number.

Code: Select all

 
$query=" SELECT * FROM  admin_holiday_destinations WHERE holiday_country = '".$show."' AND holiday_type = '".$holType."' AND price  LIKE %£_% BETWEEN ".$startNo." AND ".$endNo." ORDER BY $order  LIMIT $eu, $limit ";
$result=mysqli_query($mysqli, $query);
 
The above is one of my failed attempts.

Any ideas on what I need to do here?

Thank You

N.B.

If the price field holds only numbers such as 345 etc. the script works when using the following statement fine...

Code: Select all

 
$query=" SELECT * FROM  admin_holiday_destinations WHERE holiday_country = '".$show."' AND holiday_type = '".$holType."' AND price BETWEEN ".$startNo." AND ".$endNo." ORDER BY $order  LIMIT $eu, $limit ";
$result=mysqli_query($mysqli, $query);
 
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: selecting all from database where string contains price...

Post by social_experiment »

Code: Select all

<?php
$query=" SELECT * FROM  admin_holiday_destinations WHERE holiday_country = '".$show."' AND holiday_type = '".$holType."' AND price  LIKE %£_% BETWEEN ".$startNo." AND ".$endNo." ORDER BY $order  LIMIT $eu, $limit ";
$result=mysqli_query($mysqli, $query);
 
while ($resultArray = mysql_fetch_array($result)) {
 echo "£".$resultArray['price'];
}
?>
What if you used the values with the £ sign, and just added it into the query like above?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply