code help

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
Taneya
Forum Newbie
Posts: 1
Joined: Thu Jul 12, 2007 7:43 pm

code help

Post by Taneya »

hi all,

I'm a newbie to php, could someone help? where and how do i append this code to include the piece i need that relates to id fields from two databases together? the piece i need to add is "WHERE names.nameid = news.id"

$a = false;
$sql = "SELECT * FROM names,news WHERE ";

if ( $_REQUEST['fullname'] ) {
$sql .= "name LIKE '%" . $_REQUEST['fullname'] . "%' ";
$a = true;
}
if ( $_REQUEST['nametype'] ) {
if ($a) $sql .= "AND ";
$sql .= "nametype LIKE '%" . $_REQUEST['nametype'] . "%' ";
$a = true;
}
if ( $_REQUEST['county'] ) {
if ($a) $sql .= "AND ";
$sql .= "county LIKE '%" . $_REQUEST['county'] . "%' ";
$a = true;
}
if ( $_REQUEST['articletype'] ) {
if ($a) $sql .= "AND ";
$sql .= "type = '" . $_REQUEST['type'] . "' ";
$a = true;
}

if ( $_REQUEST['state'] ) {
if ($a) $sql .= "AND ";
$sql .= "state = '" . $_REQUEST['state'] . "' ";
$a = true;
}
if ( $_REQUEST['issue'] ) {
if ($a) $sql .= "AND ";
$sql .= "issue = '" . $_REQUEST['issue'] . "' ";
$a = true;
}

$sql .= "ORDER BY name";

thanks in advance
rahulzatakia
Forum Commoner
Posts: 59
Joined: Fri Feb 05, 2010 12:01 am
Location: Ahmedabad

Re: code help

Post by rahulzatakia »

Hi, you can try out the following code. And if you have any query let me know...

original code

Code: Select all

$sql = "SELECT * FROM names,news WHERE ";
Please replace the above code with below code

Code: Select all

$sql = "SELECT names.*, news.* FROM names inner join news on names.nameid = news.id where";
Post Reply