Re: results of mysql_fetch are returning the incorrect records
| From: | David Robley | Date: | Wed, 14 Aug 2002 03:47:25 +0000 |
| Subject: | Re: results of mysql_fetch are returning the incorrect records | ||
| References: | 1 | Groups: | php.db php.dev php.lang php.windows |
| Request: | Send a blank email to php-dev+get-86784@lists.php.net to get a copy of this message | ||
In article <20020814024113.19123.qmail@pb1.pair.com>, kimlalee@hotmail.com
says...
> I have problems with mysql_fetch return the wrong records. If I execute the
> sql statement in mysql, I receive the correct results. When I used
> mysql_fetch function, it does not return the correct results. Below is my
> function and the format sql statement
>
> function companiesByBusiness_ZipCode_BusinessOrContactName( $ctgyno,
> $zipcode, $businessandcontactname ) {
> $sql = "select company_no, name, contact, business_phone, mobile_phone,
> services_desc, brief_bio, pager, address, city, state, zipcode,
> picture_file, case ifnull(picture_file, 'No Picture') when 'No Picture'
> then
> 'b' else 'a' end pic_ind from company";
> if( $ctgyno != "ALL") {
> $sql .= " where business_ctgy_no = $ctgyno";
> if( $zipcode != "" ) {
> $sql .= " and (zipcode like '".substr( $zipcode, 0, 3 )."%' and
> zipcode
> != '$zipcode')";
> }
> if( $businessandcontactname != "" ) {
> $sql .= " and (name = '$businessandcontactname'";
> $sql .= " or contact = '$businessandcontactname')";
>
> }
> $sql .= " order by pic_ind, name, company_no";
> }
>
> $query = mysql_query( $sql ) or die( $sql."<p>".mysql_error() );
>
> //$numrows = mysql_num_rows( $query );
> while( $assoc = mysql_fetch_assoc( $query ) ) {
> $rows[] = $assoc;
>
> sql statement:
> select company_no, name, contact, business_phone, mobile_phone,
> services_desc, brief_bio, pager, address, city, state, zipcode,
> picture_file, case ifnull(picture_file, 'No Picture') when 'No Picture'
> then
> 'b' else 'a' end pic_ind from company where business_ctgy_no = 1 and
> (zipcode like '276%' and zipcode != '27616') and (name = 'Gil
> Bryan' or
> contact = 'Gil Bryan') order by pic_ind, name, company_no
>
> It seems like it is ignoring the last condition, name = 'Gil Bryan' or
> contact = 'Gil Bryan'). Any help is greatly appreciated.
>
> }
>
> return $rows;
> }
First, I'd suggest echoing $sql just before you send it to mysql to ensure
that what you hope is there is actually there. Also, what are you
returning from your function? Or how are you using the data gathered from
your tables?
--
David Robley
Temporary Kiwi!
Quod subigo farinam