Link to home
Start Free TrialLog in
Avatar of BrighteyesDesign
BrighteyesDesignFlag for Afghanistan

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_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $PPA) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
 if($totalRows_Recordset1 == '0') {
      header('Location: noresults.php');
}
Avatar of plshrk
plshrk

WHERE (type = %s OR type2 = %s)
Avatar of BrighteyesDesign

ASKER

Thanks for that.

I get an error:

Warning: sprintf() [function.sprintf]: Too few arguments in /home2/brightf7/public_html/personalproperty/type.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)"
SELECT * FROM table WHERE type1 LIKE ‘%$word%’ OR type2 LIKE ‘%$word%’
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.
ASKER CERTIFIED SOLUTION
Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes, that does the trick!

Thanks for that