Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Display results from two colums in PHP & MySQL

Posted on 2011-02-26
6
Medium Priority
?
334 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
[X]
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
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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 

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 2000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…
Suggested Courses

636 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