PHP variable

Pass PHP varaible as a condition to mysql

Page 1 of 1

2 Replies - 733 Views - Last Post: 08 February 2010 - 04:02 PM Rate Topic: -----

#1 sherbet  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 01-June 09

PHP variable

Post icon  Posted 01 February 2010 - 06:35 PM

Please help, I am trying to pass the following php variable into a mysql select. The select will work if I limit the variable to just a number, but will not read past the first number. Any ideas? Thanks


$option_group = '1 OR group_id = 7';
	

select option_id,option_name,option_description from  options_m where (group_id = '$option_group')



The actual mysql select should read as follows:
select option_id,option_name,option_description from  options_m where (group_id = 1 OR group_id = 7)



Is This A Good Question/Topic? 0
  • +

Replies To: PHP variable

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2891
  • View blog
  • Posts: 10,025
  • Joined: 08-August 08

Re: PHP variable

Posted 01 February 2010 - 08:31 PM

$option_group = '1 OR group_id = 7';
$query = "select option_id,option_name,option_description from  options_m where (group_id = '$option_group')";
echo "Query is: <br>".$query."<br>";
mysql_query($query) or die(mysql_error());


Was This Post Helpful? 0
  • +
  • -

#3 Guest_sherbet*


Reputation:

Re: PHP variable

Posted 08 February 2010 - 04:02 PM

Thanks worked a treat. In the end I used:

$query = "select option_id,option_name,option_description from  options_m where (group_id = ".$option_group.")"



Was This Post Helpful? 0

Page 1 of 1