Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Display results from two colums in PHP & MySQL

Posted on 2011-02-26
6
303 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Google Maps API and PHP 25 49
PHP Query return divisible by 3 3 26
Output in PHP throwing alignment of data off issue 12 42
Inserting data into database 10 34
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

839 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