close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Select from multiple tables for search filter from single text field

Thread began 1/18/2016 7:16 am by stephen287384 | Last modified 1/18/2016 9:39 pm by Ray Borduin | 2137 views | 11 replies |

stephen287384

Select from multiple tables for search filter from single text field

I need a text field "keywords" to deliver results from multiple tables. Here is the Query so far which is throwing errors:

SELECT UserArtistName,UserBandName, UserBusinessName, UserInfluences AS 'who' FROM users UNION SELECT AlbumTitle, AlbumTrack1, AlbumTrack2, AlbumTrack3, AlbumTrack4, AlbumTrack5, AlbumTrack6, AlbumTrack7, AlbumTrack8, AlbumTrack9, AlbumTrack10, AlbumTrack11, AlbumTrack12, AlbumTrack13, AlbumTrack14, AlbumTrack15, AlbumTrack16, AlbumTrack17, AlbumTrack18, AlbumTrack19, AlbumTrack20 AS 'what' FROM discography WHERE ('who' LIKE ? OR 'what' LIKE ?) OR UserGenreID = ? OR UserState = ?
$rsResults->bindParam("cl", "".(isset($_POST['keyword'])?$_POST['keyword']:"") ."", "-1"); //paramKeywords
$rsResults->bindParam("i", "".(isset($_POST['genre'])?$_POST['genre']:"") ."", "-1"); //paramGenre
$rsResults->bindParam("s", "".(isset($_POST['state'])?$_POST['state']:"") ."", "-1"); //paramState

Sign in to reply to this post

Ray BorduinWebAssist

You would have to pass the parameter twice like:

SELECT UserArtistName,UserBandName, UserBusinessName, UserInfluences AS 'who' FROM users UNION SELECT AlbumTitle, AlbumTrack1, AlbumTrack2, AlbumTrack3, AlbumTrack4, AlbumTrack5, AlbumTrack6, AlbumTrack7, AlbumTrack8, AlbumTrack9, AlbumTrack10, AlbumTrack11, AlbumTrack12, AlbumTrack13, AlbumTrack14, AlbumTrack15, AlbumTrack16, AlbumTrack17, AlbumTrack18, AlbumTrack19, AlbumTrack20 AS 'what' FROM discography WHERE ('who' LIKE ? OR 'what' LIKE ?) OR UserGenreID = ? OR UserState = ?
$rsResults->bindParam("c", "".(isset($_POST['keyword'])?$_POST['keyword']:"") ."", "-1"); //paramKeywords
$rsResults->bindParam("c", "".(isset($_POST['keyword'])?$_POST['keyword']:"") ."", "-1"); //paramSecondKeywords
$rsResults->bindParam("i", "".(isset($_POST['genre'])?$_POST['genre']:"") ."", "-1"); //paramGenre
$rsResults->bindParam("s", "".(isset($_POST['state'])?$_POST['state']:"") ."", "-1"); //paramState

Sign in to reply to this post
Did this help? Tips are appreciated...

stephen287384

Error in SQL syntax

Sign in to reply to this post

Ray BorduinWebAssist

You should be able to turn on debugging in your rsobj.php file to see the full error. It could be a typo in a column name or something of that nature.

Sign in to reply to this post
Did this help? Tips are appreciated...

stephen287384

How do I do that? Do the AS statements look correct to you? I read somewhere that if the columns contain spaces you should use [ ] or " "

I'll run the query directly in phpMyAdmin but would be good to be able to turn on debugging in rsobj

Sign in to reply to this post

Ray BorduinWebAssist

I don't know what you are trying to do... a UNION SELECT should have the same columns as the initial select... so the entire query seems odd to me.

I'm pretty sure you don't want a UNION SELECT at all. In some cases it makes more sense to use two Recordsets.

Sign in to reply to this post
Did this help? Tips are appreciated...

stephen287384

Basically I am trying to use 1 text field on the search page to filter the results from 2 tables and 11 different columns

Sign in to reply to this post

Ray BorduinWebAssist

Are the two tables related? I'd probably use two different recordsets. Then each recordset can filter with the same text field.

The here clause would have the column and parameter repeated for each column you were searching against.

Sign in to reply to this post
Did this help? Tips are appreciated...

stephen287384

What about an INNER JOIN?
SELECT UserArtistName, UserBandName, UserBusinessName, UserState, UserGenreID, UserInfluences AlbumTitle, AlbumTrack1, AlbumTrack2, AlbumTrack3, AlbumTrack4, AlbumTrack5, AlbumTrack6, AlbumTrack7, AlbumTrack8, AlbumTrack9, AlbumTrack10, AlbumTrack11, AlbumTrack12, AlbumTrack13, AlbumTrack14, AlbumTrack15, AlbumTrack16, AlbumTrack17, AlbumTrack18, AlbumTrack19, AlbumTrack20 AS 'what' FROM users INNER JOIN discography ON AlbumUserID = UserID WHERE ('what' LIKE ?) OR UserGenreID = ? OR UserState = ? OR UserBusinessName LIKE ?");
$rsResults->bindParam("c", "".(isset($_POST['keyword'])?$_POST['keyword']:"") ."", "-1"); //paramKeywords
$rsResults->bindParam("i", "".(isset($_POST['genre'])?$_POST['genre']:"") ."", "-1"); //paramGenre
$rsResults->bindParam("s", "".(isset($_POST['state'])?$_POST['state']:"") ."", "-1"); //paramState
$rsResults->bindParam("cl", "".(isset($_POST['business'])?$_POST['business']:"") ."", "-1"); //paramBusinessName



How do you turn on debugging in rsobj?

Sign in to reply to this post

Ray BorduinWebAssist

If you have the latest version just look in the file for where it has Debug=false and change it to true;

Yes an INNER JOIN makes more sense.

SELECT UserArtistName, UserBandName, UserBusinessName, UserState, UserGenreID, UserInfluences AlbumTitle, AlbumTrack1, AlbumTrack2, AlbumTrack3, AlbumTrack4, AlbumTrack5, AlbumTrack6, AlbumTrack7, AlbumTrack8, AlbumTrack9, AlbumTrack10, AlbumTrack11, AlbumTrack12, AlbumTrack13, AlbumTrack14, AlbumTrack15, AlbumTrack16, AlbumTrack17, AlbumTrack18, AlbumTrack19, AlbumTrack20 AS 'what' FROM users INNER JOIN discography ON AlbumUserID = UserID WHERE AlbumTrack1 LIKE ? OR AlbumTrack2 LIKE ? OR AlbumTrack3 LIKE ? OR AlbumTrack4 LIKE ? OR AlbumTrack5 LIKE ? OR AlbumTrack6 LIKE ? OR AlbumTrack7 LIKE ? OR AlbumTrack8 LIKE ? OR AlbumTrack9 LIKE ? OR UserGenreID = ? OR UserState = ? OR UserBusinessName LIKE ?");
$rsResults->bindParam("c", "".(isset($_POST['keyword'])?$_POST['keyword']:"") ."", "-1"); //paramAlbumTrack1
$rsResults->bindParam("c", "".(isset($_POST['keyword'])?$_POST['keyword']:"") ."", "-1"); //paramAlbumTrack2
$rsResults->bindParam("c", "".(isset($_POST['keyword'])?$_POST['keyword']:"") ."", "-1"); //paramAlbumTrack3
$rsResults->bindParam("c", "".(isset($_POST['keyword'])?$_POST['keyword']:"") ."", "-1"); //paramAlbumTrack4
$rsResults->bindParam("c", "".(isset($_POST['keyword'])?$_POST['keyword']:"") ."", "-1"); //paramAlbumTrack5
$rsResults->bindParam("c", "".(isset($_POST['keyword'])?$_POST['keyword']:"") ."", "-1"); //paramAlbumTrack6
$rsResults->bindParam("c", "".(isset($_POST['keyword'])?$_POST['keyword']:"") ."", "-1"); //paramAlbumTrack7
$rsResults->bindParam("c", "".(isset($_POST['keyword'])?$_POST['keyword']:"") ."", "-1"); //paramAlbumTrack8
$rsResults->bindParam("c", "".(isset($_POST['keyword'])?$_POST['keyword']:"") ."", "-1"); //paramAlbumTrack9
$rsResults->bindParam("i", "".(isset($_POST['genre'])?$_POST['genre']:"") ."", "-1"); //paramGenre
$rsResults->bindParam("s", "".(isset($_POST['state'])?$_POST['state']:"") ."", "-1"); //paramState
$rsResults->bindParam("cl", "".(isset($_POST['business'])?$_POST['business']:"") ."", "-1"); //paramBusinessName

Sign in to reply to this post
Did this help? Tips are appreciated...
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...