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

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
davidhopkins
Forum Commoner
Posts: 41
Joined: Thu Jun 10, 2010 7:52 am

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

Post 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 !
davidhopkins
Forum Commoner
Posts: 41
Joined: Thu Jun 10, 2010 7:52 am

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

Post by davidhopkins »

Nobody ? Im sure this is simple . . .
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

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

Post by mikosiko »

davidhopkins wrote:Nobody ? Im sure this is simple . . .
http://www.php-mysql-tutorial.com/wikis ... tions.aspx
davidhopkins
Forum Commoner
Posts: 41
Joined: Thu Jun 10, 2010 7:52 am

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

Post by davidhopkins »

Not very helpful . . .
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

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

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

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

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply