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
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

 

Link to comment
Share on other sites

For future reference, if your question is answered it's appreciated if you mark it as solved so people don't waste their time looking at it. There's a button at the bottom of the page to do so.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.