473,386 Members | 1,860 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,386 software developers and data experts.

Search & replace

Ike
I'm absolutely stuck, hoping someone can illuminate my sitatuation. I have a
string (a query) where I need to dynamically be able to change one part of
the the string (the part where .username LIKE\'%\' ), changing the text I am
looking for .username to be LIKE, to something else that will sent over via
an HTTP Get as $_GET['username']. THat is, the quey can be ANY query,
however, if there is a .username LIKE in the query, I need to change the
value for the LIKE (which is % in this case) to be $_GET['username'].

Can someone please help me out with this? A typical query would be something
like:
$qid = mysql_query(stripslashes("SELECT t0.username AS \"Username\"
,COUNT(t1.closed) AS \"Ups Handled\" , AVG(ABS(t1.closed)) AS \"Closing
Ratio\" FROM associates t0,leads t1 WHERE (t0.branch LIKE \'%\') AND
(t1.associatekey=t0.id) AND t0.username LIKE\'%\' AND t1.date
>=\'2006-01-01%\' AND t1.date <=\'2006-12-31%\' GROUP BY
t0.username ORDER BY t0.username ASC "));

thanks, Ike
Sep 18 '06 #1
1 1205
Ike wrote:
I'm absolutely stuck, hoping someone can illuminate my sitatuation. I have a
string (a query) where I need to dynamically be able to change one part of
the the string (the part where .username LIKE\'%\' ), changing the text I am
looking for .username to be LIKE, to something else that will sent over via
an HTTP Get as $_GET['username']. THat is, the quey can be ANY query,
however, if there is a .username LIKE in the query, I need to change the
value for the LIKE (which is % in this case) to be $_GET['username'].

Can someone please help me out with this? A typical query would be something
like:
$qid = mysql_query(stripslashes("SELECT t0.username AS \"Username\"
,COUNT(t1.closed) AS \"Ups Handled\" , AVG(ABS(t1.closed)) AS \"Closing
Ratio\" FROM associates t0,leads t1 WHERE (t0.branch LIKE \'%\') AND
(t1.associatekey=t0.id) AND t0.username LIKE\'%\' AND t1.date
>=\'2006-01-01%\' AND t1.date <=\'2006-12-31%\' GROUP BY
t0.username ORDER BY t0.username ASC "));

thanks, Ike

First of all, you should use mysql_real_escape_string() instead on any
data you use. You should also validate the username field before
sending it - since it's a GET parameter, anyone could put almost
anything in there (also true for POST, but only a tiny bit harder).
Then you can just use the username when building your SQL.

Also, you have several other problems in your SQL.

It's probably not a good idea to have a space in the aliases. And
strings are surrounded by single quotes, not double quotes in SQL.

Also, "t0.username like '%'" is meaningless - it will match any non-null
value.

And "t1.date >= '2006-01-01%' won't work. If you're going to use '%'
you must use like. If you're looking for anything >= 1/1/2006, just
compare like that.

Something like this (not checked):

$username = isset($_GET['username']) ? $_GET['username'] : null;

if ($username ... // validation here
$qid = mysql_query("SELECT t0.username AS Username,
COUNT(t1.closed) AS Ups_Handled\" ,
AVG(ABS(t1.closed)) AS Closing_Ratio
FROM associates t0,leads t1
WHERE t0.branch LIKE '".mysql_real_escape_string($username)."%' AND
t1.associatekey=t0.id AND
t1.date >= '2006-01-01' AND
t1.date <= '2006-12-31'
GROUP BY t0.username
ORDER BY t0.username ASC");

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 18 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Zenobia | last post by:
Hello I want a search & replace text in source code for several files in several directories. It would seem that both Dreamweaver MX 6 and GoLive 6 offer this feature but not for .aspx file...
3
by: tchurm | last post by:
Hi Pythonistas, Here's my problem: I'm using a version of MOOX Firefox (http://moox.ws/tech/mozilla/) that's been modified to run completely from a USB Stick. It works fine, except when I...
1
by: Tomomichi Amano | last post by:
Could some one tell me how I can seach and replace only one word in a textBox (THE FIRST WORD THAT COMES AFTER THE CURSOR). I already know how to replace ALL , but I don't know how to REPLACE one,...
1
by: Tomomichi Amano | last post by:
Hello. I want to make replace & search functions in my text editor. Thanks to the kind people here at the newsgroup, I was able to make the function. But I was not able to understand how to...
3
by: Craig Buchanan | last post by:
Is there a way to combine these two Replace into a single line? Regex.Replace(Subject, "\&", "&amp;") Regex.Replace(Subject, "\'", "&apos;") Perhaps Regex.Replace(Subject, "{\&|\'}", "{&amp;|&apos;}")...
2
by: Jan | last post by:
Hello! I am looking for a way to do a search&replace in ASCII-Files by a vb.net 2005 programm. Of coarse I can open the files, loop to every line, make a replace, and save the line. But I wonder...
6
by: DataSmash | last post by:
Hello, I need to search and replace 4 words in a text file. Below is my attempt at it, but this code appends a copy of the text file within itself 4 times. Can someone help me out. Thanks! #...
2
by: Ola K | last post by:
Hi guys, I wrote a script that works *almost* perfectly, and this lack of perfection simply puzzles me. I simply cannot point the whys, so any help on it will be appreciated. I paste it all here,...
16
by: Proaccesspro | last post by:
I'm trying to create a search & replace function in Access. Specifically, I want to search for a specific SSN and replace it, if found. Not sure how to code the "guts" of it. Here is what I have...
6
by: simon.robin.jackson | last post by:
Ok. I need to develop a macro/vba code to do the following. There are at least 300 corrections and its expected for this to happen a lot more in the future. Therefore id like a nice...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.