472,334 Members | 2,469 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Need to substitute #where# with $where

if ($willLimitByDB) $sql = preg_replace('/#([^#]+)#/i', '$$1',
$sql);

This does not give me the results I want, instead of the value of
$where in $sql, I literally get '$where' instead.

How do I substitute #where# with $where?

Thanx
Phil

Mar 15 '06 #1
5 2252
comp.lang.php wrote:
if ($willLimitByDB) $sql = preg_replace('/#([^#]+)#/i', '$$1',
$sql); This does not give me the results I want, instead of the value of
$where in $sql, I literally get '$where' instead. How do I substitute #where# with $where? Thanx
Phil

given: $sql="select * from table";
and $where="where a = 'a'";

$sql .= $where;
//concatenate it before you edit it...
if ($willLimitByDB) $sql = preg_replace('/#([^#]+)#/i', '$$1', $sql);

Mar 15 '06 #2

noone wrote:
comp.lang.php wrote:
if ($willLimitByDB) $sql = preg_replace('/#([^#]+)#/i', '$$1',
$sql);

This does not give me the results I want, instead of the value of
$where in $sql, I literally get '$where' instead.

How do I substitute #where# with $where?

Thanx
Phil

given: $sql="select * from table";
and $where="where a = 'a'";

$sql .= $where;
//concatenate it before you edit it...
if ($willLimitByDB) $sql = preg_replace('/#([^#]+)#/i', '$$1', $sql);


Thanx but you were looking at the wrong "WHERE.."

the query is this

"SELECT id, first_name, last_name, (SELECT count(id) #where#) as
paginate_total, email, address, city, state, zip, phone FROM person
$where "

You want "#where#" inside the subselect substituted with $where

I got it though thanx to someone that knows RegExp modifiers

$sql = preg_replace('/#([^#]+)#/ie', '$$1', $sql);

Phil

Mar 15 '06 #3
comp.lang.php wrote:

"SELECT id, first_name, last_name, (SELECT count(id) #where#) as
paginate_total, email, address, city, state, zip, phone FROM person
$where "

You want "#where#" inside the subselect substituted with $where


So basically you are selecting "id, first_name, last_name ..." and
count of the returned results? Why not just ask the DB how many rows it
returned?

/marcin
Mar 16 '06 #4

Marcin Dobrucki wrote:
comp.lang.php wrote:

"SELECT id, first_name, last_name, (SELECT count(id) #where#) as
paginate_total, email, address, city, state, zip, phone FROM person
$where "

You want "#where#" inside the subselect substituted with $where


So basically you are selecting "id, first_name, last_name ..." and
count of the returned results? Why not just ask the DB how many rows it
returned?

/marcin


Because the resultset will have, for example, only 20 rows while the
entire table might have 20,000 rows. I must show how many total
records exist, all the while, only display a unit of 20.

Phil

Mar 16 '06 #5
comp.lang.php wrote:
"SELECT id, first_name, last_name, (SELECT count(id) #where#) as
paginate_total, email, address, city, state, zip, phone FROM person
$where "

You want "#where#" inside the subselect substituted with $where
So basically you are selecting "id, first_name, last_name ..." and
count of the returned results? Why not just ask the DB how many rows it
returned?

Because the resultset will have, for example, only 20 rows while the
entire table might have 20,000 rows. I must show how many total
records exist, all the while, only display a unit of 20.


But your original post said:
"How do I substitute #where# with $where?"

So if your count-select is also governed by the same "where"
statement, then your count will be that of the selected set.

There are also simpler ways (IMHO) to get the total, eg, just run a
second separate select query with only count(id).

/m
Mar 17 '06 #6

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

Similar topics

4
by: nephish | last post by:
hey there, i have a script that retrieves my email, but i need it to be able to strip all the stuff off except the body (the message itself) so i...
5
by: Gary McCullough | last post by:
What I want to do sounds simple, but it's defeating me. I want to substitute all occurences of a colon : character in a string with an @ character...
6
by: Martijn van Oosterhout | last post by:
I've had some fun in the past where I've had to grant a lot of tables and other similar system commands. Unfortunatly, you can't use queries to fill...
3
by: Susan | last post by:
Customer Orders are ranked from 1 to 10 and are assigned an order type of 1, 2 or 3. The table for this is: TblOrderRankType OrderRankTypeID...
35
by: Felix Kater | last post by:
The C-faq says that "The malloc/free implementation remembers the size of each block allocated and returned, so it is not necessary to remind it of...
7
by: Jack Addington | last post by:
I've got a fairly simple application implementation that over time is going to get a lot bigger. I'm really trying to implement it in a way that...
3
by: MLH | last post by:
Instead of DLookUp(Field, Tbl/Qry, Where clause), I was hoping to be able to substitute an expression for the tbl/qry parm ?DLookUp("","tblAdmin...
18
by: bsruth | last post by:
I tried for an hour to find some reference to concrete information on why this particular inheritance implementation is a bad idea, but couldn't. ...
3
by: aschauhan18 | last post by:
Hi Does Anybody help me Substitute Of Last() Function Of Ms Acces 2000 in Sql Server 2000 . This is my query...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

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.