BrighteyesDesign
asked on
Display results from two colums in PHP & MySQL
I have two columns in my database 'type' and 'type2'
I am send a url paramater over along the lines of <a href="type.php?id=Land Investments">
This works fine and 'Land Investments' is sent over in the URL.
I need to display results if 'Land Investments' appears in either the 'type' or 'type2' column. How would I code the query?
The code I currently use which only cjecks the 'type' column is:
$colname_Recordset1 = "-1";
if (isset($_GET['id'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_ PPA, $PPA);
$query_Recordset1 = sprintf("SELECT id, name, price, location, `currency`, `description`, type, type2, country, bedrooms, features, img1 FROM property WHERE type = %s", GetSQLValueString($colname _Recordset 1, "text"));
$Recordset1 = mysql_query($query_Records et1, $PPA) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Records et1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1 );
if($totalRows_Recordset1 == '0') {
header('Location: noresults.php');
}
I am send a url paramater over along the lines of <a href="type.php?id=Land Investments">
This works fine and 'Land Investments' is sent over in the URL.
I need to display results if 'Land Investments' appears in either the 'type' or 'type2' column. How would I code the query?
The code I currently use which only cjecks the 'type' column is:
$colname_Recordset1 = "-1";
if (isset($_GET['id'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_
$query_Recordset1 = sprintf("SELECT id, name, price, location, `currency`, `description`, type, type2, country, bedrooms, features, img1 FROM property WHERE type = %s", GetSQLValueString($colname
$Recordset1 = mysql_query($query_Records
$row_Recordset1 = mysql_fetch_assoc($Records
$totalRows_Recordset1 = mysql_num_rows($Recordset1
if($totalRows_Recordset1 == '0') {
header('Location: noresults.php');
}
WHERE (type = %s OR type2 = %s)
ASKER
Thanks for that.
I get an error:
Warning: sprintf() [function.sprintf]: Too few arguments in /home2/brightf7/public_htm l/personal property/t ype.php on line 89
Query was empty
When using that though?
$query_Recordset1 = sprintf("SELECT id, name, price, location, `currency`, `description`, type, type2, offer, country, bedrooms, features, img1 FROM property WHERE (type = %s OR type2 = %s)"
I get an error:
Warning: sprintf() [function.sprintf]: Too few arguments in /home2/brightf7/public_htm
Query was empty
When using that though?
$query_Recordset1 = sprintf("SELECT id, name, price, location, `currency`, `description`, type, type2, offer, country, bedrooms, features, img1 FROM property WHERE (type = %s OR type2 = %s)"
SELECT * FROM table WHERE type1 LIKE ‘%$word%’ OR type2 LIKE ‘%$word%’
ASKER
Thanks,
That code...
"SELECT id, name, price, location, `currency`, `description`, type, type2, offer, country, bedrooms, features, img1 FROM property WHERE type LIKE '%$word%' OR type2 LIKE '%$word%'"
...just shows all properties, it doesn't filter anyhting.
That code...
"SELECT id, name, price, location, `currency`, `description`, type, type2, offer, country, bedrooms, features, img1 FROM property WHERE type LIKE '%$word%' OR type2 LIKE '%$word%'"
...just shows all properties, it doesn't filter anyhting.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes, that does the trick!
Thanks for that
Thanks for that