code help
Posted: Tue Jun 22, 2010 9:53 pm
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
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