Page 1 of 1

Couple of PHP - MYSQL Scripts, trying to pass thru variable

Posted: Sun Jun 27, 2010 10:42 am
by davidhopkins
Hello All.

I am using AMFPHP in conjunction with flex. It basically lets me return mysql queries for flex in an easier format. But i am having troubles using a variable to determine one of the query's.

My php code is -

Code: Select all

<?php
class jobs
{
var $db_host = 'localhost';
var $db_name = '';
var $db_user = '';
var $db_pwd = '';
var $ID_No = '7';

function jobs()
{
$this->methodTable = array(
"getJobs" => array(
"description" => "Info Database",
"access" => "remote"
)
);
}

function getAllJobs()
{
$mysql = mysql_connect($this->db_host, $this->db_user, $this->db_pwd);
mysql_select_db( $this->db_name);
$Query = "SELECT * from usernames WHERE level = 'clientuser'";
$Result = mysql_query( $Query );
return( $Result );
}

function getAllLinkedCompany()
{
$mysql = mysql_connect($this->db_host, $this->db_user, $this->db_pwd);
mysql_select_db( $this->db_name);
$Query ="SELECT * from usernames WHERE assignedrecruiter ='7'";
$Result = mysql_query( $Query );
return( $Result );
}

function getAllUsers()
{
$mysql = mysql_connect($this->db_host, $this->db_user, $this->db_pwd);
mysql_select_db( $this->db_name);
$Query ="SELECT * from usernames WHERE level ='clientuser'";
$Result = mysql_query( $Query );
return( $Result );
}

function getAllCustomers()
{
$mysql = mysql_connect($this->db_host, $this->db_user, $this->db_pwd);
mysql_select_db( $this->db_name);
$Query ="SELECT * from usernames WHERE level ='customer'";
$Result = mysql_query( $Query );
return( $Result );
}

function getYourJobs()
{
$mysql = mysql_connect($this->db_host, $this->db_user, $this->db_pwd);
mysql_select_db( $this->db_name);
$Query ="SELECT * from jobs WHERE assignedrecruiter  ='7'";
$Result = mysql_query( $Query );
return( $Result );
}

}


?>
Where i have the function "function getYourJobs() " i want to pass a variable into the query rather than "7", the variable i want to pass through is "$ID_No" that i defined at the top of the script. Can anyone help me with this ? I have tried a few differnt ways to do it but cant seem to.

Any help would be great !

Re: Couple of PHP - MYSQL Scripts, trying to pass thru varia

Posted: Sun Jun 27, 2010 3:18 pm
by davidhopkins
Nobody ? Im sure this is simple . . .

Re: Couple of PHP - MYSQL Scripts, trying to pass thru varia

Posted: Sun Jun 27, 2010 4:49 pm
by mikosiko
davidhopkins wrote:Nobody ? Im sure this is simple . . .
http://www.php-mysql-tutorial.com/wikis ... tions.aspx

Re: Couple of PHP - MYSQL Scripts, trying to pass thru varia

Posted: Mon Jun 28, 2010 7:06 am
by davidhopkins
Not very helpful . . .

Re: Couple of PHP - MYSQL Scripts, trying to pass thru varia

Posted: Mon Jun 28, 2010 9:24 am
by mikosiko
davidhopkins wrote:Not very helpful . . .
No?... then you need to read a little more and pay more attention to the examples... a possible answer is there... or here also is another solution:

http://www.phpro.org/tutorials/Object-O ... PHP.html#6

just look the examples and you will figure it out

Re: Couple of PHP - MYSQL Scripts, trying to pass thru varia

Posted: Mon Jun 28, 2010 9:37 am
by AbraCadaver
Well, you say that you want to "pass in" the variable, but you also have it defined as a class variable, so here are the two ways:

Code: Select all

function getYourJobs($id)
{
$mysql = mysql_connect($this->db_host, $this->db_user, $this->db_pwd);
mysql_select_db( $this->db_name);
$Query ="SELECT * from jobs WHERE assignedrecruiter  ='$id'";
$Result = mysql_query( $Query );
return( $Result );
}

Code: Select all

function getYourJobs()
{
$mysql = mysql_connect($this->db_host, $this->db_user, $this->db_pwd);
mysql_select_db( $this->db_name);
$Query ="SELECT * from jobs WHERE assignedrecruiter  ='" . $this->ID_No . "'";
$Result = mysql_query( $Query );
return( $Result );
}
I'm not sure what you're going for.