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
code help
Moderator: General Moderators
-
rahulzatakia
- Forum Commoner
- Posts: 59
- Joined: Fri Feb 05, 2010 12:01 am
- Location: Ahmedabad
Re: code help
Hi, you can try out the following code. And if you have any query let me know...
original code
Please replace the above code with below code
original code
Code: Select all
$sql = "SELECT * FROM names,news WHERE ";
Code: Select all
$sql = "SELECT names.*, news.* FROM names inner join news on names.nameid = news.id where";