Solved

Display results from two colums in PHP & MySQL

Posted on 2011-02-26
6
276 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now