473,388 Members | 1,198 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

String as a URL variable - split to query recordset

I'd like to pass a multi-word string as a variable to a page which then splits the string into seperate words. After this I want to create a recordset using each of the words in the query on the same field eg:

the url would look like this:

mypage1.php?search=apple banana

where fruit LIKE apple OR fruit LIKE banana (in this example)

I've been bothering this for a while now and can't seem to get it to work. I'm using Dreamweaver 8

Any help would be greatly appreciated.
Nov 14 '07 #1
3 2156
ak1dnar
1,584 Expert 1GB
Nothing to do with dreamweaver here, You have to use a script like this. Check this out please:

split_url_string.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $OriginalQuery = "SELECT col_names FROM table";
  3. $string = array();
  4. $where = "";
  5. if (isset($_GET['search']) AND !empty($_GET['search'])) {
  6.   $URLString=explode(" ",$_GET['search']);
  7.   foreach($URLString as $key){
  8.   $string[] = " fruit LIKE $key "; // Hope You Know the Logic use to "LIKE"  :D
  9.   }
  10.   }
  11. if(!empty($string)){
  12. $where = " WHERE ".implode("OR", $string);
  13. }
  14. echo $OriginalQuery.$where; 
  15. ?>
  16.  
Once you called to the page like in way of this format:
http://localhost/tut/split_url_string.php?search=banana apple
outputs:
SELECT col_names FROM table WHERE fruit LIKE banana OR fruit LIKE apple
Nov 14 '07 #2
Many thanks. Had to tinker around with it a bit but got it working in the end. Most importantly, I've learned a few things.

Again, thank.
Nov 14 '07 #3
ak1dnar
1,584 Expert 1GB
Many thanks. Had to tinker around with it a bit but got it working in the end. Most importantly, I've learned a few things.

Again, thank.
Glad I could help ! post back to the forum any time.
Good luck! :)
Nov 14 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Jim Adamson | last post by:
I have created a web page that receives names and values from a URL string of another page e.g. http://hostname/resolve?sublibrary=JMLibrary&collection=Elton&shelfmark=LM 36TY ... and decodes the...
3
by: Dr. Oz | last post by:
Hi, I am trying to read in a query string from one page and build a link to another page based on the query string. Here's the code I am using to read in the query string: <script...
3
by: ethoemmes | last post by:
I have used the import class module from http://www.mvps.org/access/modules/mdl0057.htm. This reads my text file into a string called myString. I am trying to append this string into table...
9
by: Mark | last post by:
I've run a few simple tests looking at how query string encoding/decoding gets handled in asp.net, and it seems like the situation is even messier than it was in asp... Can't say I think much of the...
1
by: johnpremi | last post by:
Hi there, I have to pass a query string parameter in my Web Config for loading a URL. We have two environments (production and devlopment) and MonitorURL needs to be changed when the deployment is...
1
by: sadiewms | last post by:
Hi! I'm trying to loop through records in a table, split the contents and insert each subsequent string in the array into a new table. I need to determine how to cast the current record in the...
5
by: Henrik | last post by:
The problem is (using MS Access 2003) I am unable to retrieve long strings (255 chars) from calculated fields through a recordset. The data takes the trip in three phases: 1. A custom public...
3
by: Skip | last post by:
OK, I'm a novice in JS but have lots of coding experience. I am trying to accomplish something that would seem somewhat simple - BUT IT'S NOT. I have a basic window that calls another window...
2
by: I Hate My Computer | last post by:
I am using frames on a website. The title link on the title page adds a query string. The link goes to a page with two rows the second has two columns. I want the right column to be changed depending...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.