Solved

Display results from two colums in PHP & MySQL

Posted on 2011-02-26
6
296 Views
Last Modified: 2012-05-11
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');
}
0
Comment
Question by:BrighteyesDesign
6 Comments
 

Expert Comment

by:plshrk
ID: 34987853
WHERE (type = %s OR type2 = %s)
0
 

Author Comment

by:BrighteyesDesign
ID: 34987990
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)"
0
 

Expert Comment

by:manhdn
ID: 34988191
SELECT * FROM table WHERE type1 LIKE ‘%$word%’ OR type2 LIKE ‘%$word%’
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

Author Comment

by:BrighteyesDesign
ID: 35002396
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.
0
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 500 total points
ID: 35004408
Try this, there are two arguments required after the query

$query_Recordset1 = sprintf("SELECT id, name, price, location, `currency`, `description`, type, type2, country, bedrooms, features, img1 FROM property WHERE type = %s OR type2 = %s", GetSQLValueString($colname_Recordset1, "text"), GetSQLValueString($colname_Recordset1, "text"));

Open in new window

0
 

Author Closing Comment

by:BrighteyesDesign
ID: 35004905
Yes, that does the trick!

Thanks for that
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question