Re: results of mysql_fetch are returning the incorrect records
| From: | K. Lee | Date: | Thu, 15 Aug 2002 21:23:40 +0000 |
| Subject: | Re: results of mysql_fetch are returning the incorrect records | ||
| References: | 1 2 | Groups: | php.db php.dev php.lang php.windows |
| Request: | Send a blank email to php-dev+get-86881@lists.php.net to get a copy of this message | ||
I tried echo the sql in this function but I do not know where it print the
statement. This function is inside *.inc file which is require in the html
that I am printing the results of the query. So, to answer your question, I
using the data to display on a html page. I am returning an array from this
function.
"David Robley" <robleyd@paradise.net.nz> wrote in message
news:MPG.17c498384b7c51e5989777@news.php.net...
> 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