Jump to content

help with variable in query


joeros

Recommended Posts

Hi,

 

I am Very new to php but i have experience in other coding. I am trying to place a variable into some code that queries a database.

 

This code works

$x->setQuery("*", "people","gender","gender='m'");

 

This code also works

$qry = "gender='f'";

$x->setQuery("*", "people","gender",$qry);

 

And this code does not work nor does it throw any error it just does not return any records

 

$ qry = chr(34);

$ qry .= "gender=";

$ qry .= chr(39);

$ qry .= $PCode;

$ qry .= chr(39);

$ qry .= chr(34);

 

Can anyone explain how to achieve what I am trying to do and/or explain why the above does not work?

 

 

This is the actual query being referenced

/**

* Set the SELECT query

*

* @param string $fields Feilds to fetch from table. * for all columns

* @param string $table Table to select from

* @param string $primay Optional primary key column

* @param string $where Optional where condition

*/

public function setQuery($fields, $table, $primary = '', $where = '')

{

$this->primary = $primary;

$this->select_fields = $fields;

$this->select_table = $table;

$this->select_where = $where;

}

 

Link to comment
https://forums.phpfreaks.com/topic/204481-help-with-variable-in-query/
Share on other sites

Bugger me, as soon as i post i sit back and look at the code and the answer comes to me.

 

it's just a matter of dropping the quotes off the begining and the end of the string and then it returns the correct result.

 

oh well it is good to find the solution yourself

 

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.