dbTalk Databases Forums  

filters in the WHERE clause

comp.databases.mysql comp.databases.mysql


Discuss filters in the WHERE clause in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
JRough
 
Posts: n/a

Default filters in the WHERE clause - 06-29-2010 , 03:29 PM






I have a question on this sql. It looks like it is right with the
filters but when I run the page
I get the WHERE clause twice. I don't understand why. I know it is
somthing simple with the concatenation..

Here is the error with the where clause twice:

------608 SELECT DISTINCT bu, cart_id, ndc, error_flag, item_id,
description, upc, ndc_uom, std_uom FROM cart_inventory, onelink WHERE
ndc =ndc AND bu ='08010' WHERE ndc =ndc AND bu ='08010' LIMIT 100,100

I think it is in this line but it looks right and I don't want the
filter to not work. I don't see what I'm missing.
thanks,
---sql --------

$sql="SELECT DISTINCT bu, cart_id, ndc, error_flag, item_id,
description, upc, ndc_uom, std_uom ";
$sql.="FROM inventory, link ";
$sqlWhere="WHERE ndc=ndc ";
if ($bu!=''){ $sqlWhere.="AND bu ='$bu' ";}
if ($cart_id !='') { $sqlWhere.="AND cart_id='$cart_id' ";}
if (($zoneid !='') && ($zonenm!='')) { $sqlWhere.="AND zoneid
='$zoneid'AND zonenm='$zonenm' ";}
if ( $error_flag!=''){$sqlWhere.="AND error_flag='$error_flag' ";}
$sqlOrder="ORDER BY $order ";

if( $page=='' ){
$nRecs=nrows($sql.=$sqlWhere);
echo "<font color='red'>" .$nRecs . "</font>\n";

$_SESSION['recs']=$nRecs;


$startPage=100;
}else{
$startPage=$page *100;
}

$sqlLimit="LIMIT $startPage,100 ";
$sql.= $sqlWhere ." " . $sqlLimit ;
die($sql);

Reply With Quote
  #2  
Old   
Doug Miller
 
Posts: n/a

Default Re: filters in the WHERE clause - 06-29-2010 , 03:44 PM






In article <a4d3c5de-118a-43f7-b621-d14bb0403dfa (AT) u36g2000prg (DOT) googlegroups.com>, JRough <jlrough (AT) yahoo (DOT) com> wrote:
Quote:
I have a question on this sql. It looks like it is right with the
filters but when I run the page
I get the WHERE clause twice. I don't understand why.
Because you concatenated the WHERE clause onto the query twice, of course.

Quote:
I know it is somthing simple with the concatenation..
Yes, it is.
...
Quote:
$nRecs=nrows($sql.=$sqlWhere);
...
$sql.= $sqlWhere ." " . $sqlLimit ;

Reply With Quote
  #3  
Old   
JRough
 
Posts: n/a

Default Re: filters in the WHERE clause - 06-29-2010 , 04:33 PM



On Jun 29, 1:44*pm, spamb... (AT) milmac (DOT) com (Doug Miller) wrote:
Quote:
In article <a4d3c5de-118a-43f7-b621-d14bb0403... (AT) u36g2000prg (DOT) googlegroups..com>, JRough <jlro... (AT) yahoo (DOT) com> wrote:

I have a question on this sql. *It looks like it is right with the
filters but when I run the page
I get the WHERE clause twice. *I don't understand why.

Because you concatenated the WHERE clause onto the query twice, of course..

I know it is somthing simple with the concatenation..

Yes, it is.
..

* * * *$nRecs=nrows($sql.=$sqlWhere);
..
* *$sql.= *$sqlWhere ." " . *$sqlLimit ;

Reply With Quote
  #4  
Old   
JRough
 
Posts: n/a

Default Re: filters in the WHERE clause - 06-29-2010 , 06:19 PM



On Jun 29, 1:44*pm, spamb... (AT) milmac (DOT) com (Doug Miller) wrote:
Quote:
In article <a4d3c5de-118a-43f7-b621-d14bb0403... (AT) u36g2000prg (DOT) googlegroups..com>, JRough <jlro... (AT) yahoo (DOT) com> wrote:

I have a question on this sql. *It looks like it is right with the
filters but when I run the page
I get the WHERE clause twice. *I don't understand why.

Because you concatenated the WHERE clause onto the query twice, of course..

I know it is somthing simple with the concatenation..

Yes, it is.
..

* * * *$nRecs=nrows($sql.=$sqlWhere);
..
* *$sql.= *$sqlWhere ." " . *$sqlLimit ;
the problem is on the line in the paging.
if( $page=='' ){
$nRecs=nrows($sql.=$sqlWhere); XXXXXXXX
echo "<font color='red'>" .$nRecs . "</font>\n";

I have to hard wire the number of rows in the query into the pages or
the pages won't work but I don't know how to get the value in the
query into the line.with the X's. I just need the count $sql and the
$sqlwhere filters above where the query gets called.

the nrows function is :
function nrows($sql) {
$sql="SELECT COUNT(*) AS cnt " . substr($sql,
strpos($sql,"FROM"));
$result=mysql_query($sql);
if ( !$result ) {die("<font color='red'>Invalid query:</font>" .
mysql_error() . "<br>$sql");}
$dbarray = mysql_fetch_array($result);
$nCnt=$dbarray['cnt'];
$cnt=($nCnt==1) ? "1 Record" : "$nCnt";
return $cnt;
}//end nrows

Reply With Quote
  #5  
Old   
Jerry Stuckle
 
Posts: n/a

Default Re: filters in the WHERE clause - 06-29-2010 , 08:14 PM



Doug Miller wrote:
Quote:
In article <a4d3c5de-118a-43f7-b621-d14bb0403dfa (AT) u36g2000prg (DOT) googlegroups.com>, JRough <jlrough (AT) yahoo (DOT) com> wrote:
I have a question on this sql. It looks like it is right with the
filters but when I run the page
I get the WHERE clause twice. I don't understand why.

Because you concatenated the WHERE clause onto the query twice, of course.

I know it is somthing simple with the concatenation..

Yes, it is.
..
$nRecs=nrows($sql.=$sqlWhere);
..
$sql.= $sqlWhere ." " . $sqlLimit ;
Doug, google this newsgroup on who you're talking to. He has repeatedly
shown he has no understanding of even the simplest programming concepts.

You're wasting your time.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex (AT) attglobal (DOT) net
==================

Reply With Quote
  #6  
Old   
Doug Miller
 
Posts: n/a

Default Re: filters in the WHERE clause - 06-29-2010 , 08:47 PM



In article <i0e5q3$n8m$1 (AT) news (DOT) eternal-september.org>, Jerry Stuckle <jstucklex (AT) attglobal (DOT) net> wrote:
Quote:
Doug Miller wrote:
In article
a4d3c5de-118a-43f7-b621-d14bb0403dfa...oglegroups.com>, JRough
jlrough (AT) yahoo (DOT) com> wrote:
I have a question on this sql. It looks like it is right with the
filters but when I run the page
I get the WHERE clause twice. I don't understand why.

Because you concatenated the WHERE clause onto the query twice, of course.

I know it is somthing simple with the concatenation..

Yes, it is.
..
$nRecs=nrows($sql.=$sqlWhere);
..
$sql.= $sqlWhere ." " . $sqlLimit ;

Doug, google this newsgroup on who you're talking to. He has repeatedly
shown he has no understanding of even the simplest programming concepts.
She, not he. J is for Janis, IIRC.
Quote:
You're wasting your time.
Possibly.

Reply With Quote
  #7  
Old   
JRough
 
Posts: n/a

Default Re: filters in the WHERE clause - 06-29-2010 , 10:40 PM



On Jun 29, 6:47*pm, spamb... (AT) milmac (DOT) com (Doug Miller) wrote:
Quote:
In article <i0e5q3$n8... (AT) news (DOT) eternal-september.org>, Jerry Stuckle <jstuck... (AT) attglobal (DOT) net> wrote:
Doug Miller wrote:
In article
a4d3c5de-118a-43f7-b621-d14bb0403... (AT) u36g2000prg (DOT) googlegroups.com>, JRough
jlro... (AT) yahoo (DOT) com> wrote:
I have a question on this sql. *It looks like it is right with the
filters but when I run the page
I get the WHERE clause twice. *I don't understand why.

Because you concatenated the WHERE clause onto the query twice, of course.

I know it is somthing simple with the concatenation..

Yes, it is.
..
* * * *$nRecs=nrows($sql.=$sqlWhere);
..
* *$sql.= *$sqlWhere ." " . *$sqlLimit ;

Doug, google this newsgroup on who you're talking to. *He has repeatedly
shown he has no understanding of even the simplest programming concepts.

She, not he. J is for Janis, IIRC.



You're wasting your time.

Possibly.'Thank you .
Okay, I think I have the issue pinpointed. I don't understand the
nrows function entirely which is part of it .

revised sql and sqlwhere:
$sql.=$sqlWhere;
$result=mysql_query($sql);
if ( !$result ) {die("<font color='red'>Invalid query:</font>" .
mysql_error() . "<br />$sql");}
$nRecs= nrows($result);
echo $nRecs;
if( $page=='' ){
// $nRecs=nrows($sql.= $sqlWhere);

echo "<font color='red'>" .$nRecs . "</font>\n";
$_SESSION['recs']=$nRecs;
$startPage=100;
}else{
$startPage=$page *100;
}

$sqlLimit="LIMIT $startPage,100 ";
$sql.= $sqlWhere ." " . $sqlLimit ;


----nrows function-----
function nrows($sql) {
$sql="SELECT COUNT(*) AS cnt " . substr($sql,
strpos($sql,"FROM "));
$result=mysql_query($sql);
if ( !$result ) {die("<font color='red'>Invalid query:</font>" .
mysql_error() . "<br>$sql");}
$dbarray = mysql_fetch_array($result);
$nCnt=$dbarray['cnt'];
$cnt=($nCnt==1) ? "1 Record" : "$nCnt";
return $cnt;
}//end nrows

Now the error is Invalid query
You have an error in your SQL syntax, check the manual that
corresponds to you MySQL server version for the right syntax to use
near
Resource id#7 at line 1
SELECT COUNT(*) AS cnt Resource id #7

If I could understand nrows or fix this error everything would
probably work. I didn't understand why the echo nrows
shouldn't be
$nRecs= nrows($sql .=$sqlWhere) and how it works.
thanks,

Reply With Quote
  #8  
Old   
JRough
 
Posts: n/a

Default Re: filters in the WHERE clause - 06-29-2010 , 10:42 PM



On Jun 29, 6:47*pm, spamb... (AT) milmac (DOT) com (Doug Miller) wrote:
Quote:
In article <i0e5q3$n8... (AT) news (DOT) eternal-september.org>, Jerry Stuckle <jstuck... (AT) attglobal (DOT) net> wrote:
Doug Miller wrote:
In article
a4d3c5de-118a-43f7-b621-d14bb0403... (AT) u36g2000prg (DOT) googlegroups.com>, JRough
jlro... (AT) yahoo (DOT) com> wrote:
I have a question on this sql. *It looks like it is right with the
filters but when I run the page
I get the WHERE clause twice. *I don't understand why.

Because you concatenated the WHERE clause onto the query twice, of course.

I know it is somthing simple with the concatenation..

Yes, it is.
..
* * * *$nRecs=nrows($sql.=$sqlWhere);
..
* *$sql.= *$sqlWhere ." " . *$sqlLimit ;

Doug, google this newsgroup on who you're talking to. *He has repeatedly
shown he has no understanding of even the simplest programming concepts.

She, not he. J is for Janis, IIRC.



You're wasting your time.

Possibly.
Okay, I think I have the issue pinpointed. I don't understand the
nrows function entirely which is part of it .

revised sql and sqlwhere:
$sql.=$sqlWhere;
$result=mysql_query($sql);
if ( !$result ) {die("<font color='red'>Invalid query:</font>" .
mysql_error() . "<br />$sql");}
$nRecs= nrows($result);
echo $nRecs;
if( $page=='' ){
// $nRecs=nrows($sql.= $sqlWhere);

echo "<font color='red'>" .$nRecs . "</font>\n";
$_SESSION['recs']=$nRecs;
$startPage=100;
}else{
$startPage=$page *100;
}

$sqlLimit="LIMIT $startPage,100 ";
$sql.= $sqlWhere ." " . $sqlLimit ;

----nrows function-----
function nrows($sql) {
$sql="SELECT COUNT(*) AS cnt " . substr($sql,
strpos($sql,"FROM "));
$result=mysql_query($sql);
if ( !$result ) {die("<font color='red'>Invalid query:</font>" .
mysql_error() . "<br>$sql");}
$dbarray = mysql_fetch_array($result);
$nCnt=$dbarray['cnt'];
$cnt=($nCnt==1) ? "1 Record" : "$nCnt";
return $cnt;

}//end nrows

Now the error is Invalid query
You have an error in your SQL syntax, check the manual that
corresponds to you MySQL server version for the right syntax to use
near
Resource id#7 at line 1
SELECT COUNT(*) AS cnt Resource id #7

If I could understand nrows or fix this error everything would
probably work. I didn't understand why the echo nrows
shouldn't be
$nRecs= nrows($sql .=$sqlWhere) and how it works.
thanks,

Reply With Quote
  #9  
Old   
Captain Paralytic
 
Posts: n/a

Default Re: filters in the WHERE clause - 06-30-2010 , 03:40 AM



On 30 June, 02:47, spamb... (AT) milmac (DOT) com (Doug Miller) wrote:
Quote:
In article <i0e5q3$n8... (AT) news (DOT) eternal-september.org>, Jerry Stuckle <jstuck... (AT) attglobal (DOT) net> wrote:
Doug Miller wrote:
In article
a4d3c5de-118a-43f7-b621-d14bb0403... (AT) u36g2000prg (DOT) googlegroups.com>, JRough
jlro... (AT) yahoo (DOT) com> wrote:
I have a question on this sql. *It looks like it is right with the
filters but when I run the page
I get the WHERE clause twice. *I don't understand why.

Because you concatenated the WHERE clause onto the query twice, of course.

I know it is somthing simple with the concatenation..

Yes, it is.
..
* * * *$nRecs=nrows($sql.=$sqlWhere);
..
* *$sql.= *$sqlWhere ." " . *$sqlLimit ;

Doug, google this newsgroup on who you're talking to. *He has repeatedly
shown he has no understanding of even the simplest programming concepts.

She, not he. J is for Janis, IIRC.



You're wasting your time.

Possibly.
Yes, the J is for Janis and anyone who tries to help is definitely
wasting their time.

Janis is to programming what a bricklayer is to brain surgery.

Reply With Quote
  #10  
Old   
Jerry Stuckle
 
Posts: n/a

Default Re: filters in the WHERE clause - 06-30-2010 , 05:20 AM



Doug Miller wrote:
Quote:
In article <i0e5q3$n8m$1 (AT) news (DOT) eternal-september.org>, Jerry Stuckle <jstucklex (AT) attglobal (DOT) net> wrote:
Doug Miller wrote:
In article
a4d3c5de-118a-43f7-b621-d14bb0403dfa...oglegroups.com>, JRough
jlrough (AT) yahoo (DOT) com> wrote:
I have a question on this sql. It looks like it is right with the
filters but when I run the page
I get the WHERE clause twice. I don't understand why.
Because you concatenated the WHERE clause onto the query twice, of course.

I know it is somthing simple with the concatenation..
Yes, it is.
..
$nRecs=nrows($sql.=$sqlWhere);
..
$sql.= $sqlWhere ." " . $sqlLimit ;
Doug, google this newsgroup on who you're talking to. He has repeatedly
shown he has no understanding of even the simplest programming concepts.

She, not he. J is for Janis, IIRC.
You're wasting your time.

Possibly.
Yea, I knew that, also. Just too late at night, I guess

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex (AT) attglobal (DOT) net
==================

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.