Results Display

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Arulraj
Forum Newbie
Posts: 10
Joined: Sun Dec 14, 2003 11:41 pm
Location: India

Results Display

Post by Arulraj »

Hello,

I am facing peculiar problem.

When I am executing the query in the DB2 environment it gives the correct row count. But when I am executing from PHP it gives one row less. If there the query is having only one row, it gives empty row.

Anyone has faced this problem? I have tried all possible ways but of no solution.

Any solution.

thanks in advance
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post by igoy »

Can you Please post some Code ?
Arulraj
Forum Newbie
Posts: 10
Joined: Sun Dec 14, 2003 11:41 pm
Location: India

Post by Arulraj »

there are Four Input hence 16 conditions, I am giving first eight condition
if(($RNO=="") and ($CNAME=="") and ($DOB=="") and ($FATHER==""))
{
echo "<p align =\"center\">Select the search criteria correctly.</p>";
}

elseif(($RNO!="") and (($CNAME=="") or ($DOB=="") or ($FATHER=="")))
{
$Query = "SELECT RNO as RegNo,DOB as BirthDate,NAME as ChildName ,F_NAME as FatherName,M_NAME as MotherName FROM $council WHERE RNO='$RNO'";
}
elseif(($CNAME!="") and (($RNO=="") or ($DOB=="") or ($FATHER=="")))
{
$Query = "SELECT RNO as RegNo,DOB as BirthDate,NAME as ChildName ,F_NAME as FatherName,M_NAME as MotherName FROM $council WHERE NAME like '%$CNAME%' ORDER BY DOB";
}
elseif(($DOB!="") and (($CNAME=="") or ($RNO=="") or ($FATHER=="")))
{
$Query = "SELECT RNO as RegNo,DOB as BirthDate,NAME as ChildName ,F_NAME as FatherName,M_NAME as MotherName FROM $council WHERE DOB='$DOB' ORDER BY RDATE";
}
elseif(($FATHER!="") and (($CNAME=="") or ($RNO=="") or ($DOB=="")))
{
$Query = "SELECT RNO as RegNo,DOB as BirthDate,NAME as ChildName ,F_NAME as FatherName,M_NAME as MotherName FROM $council WHERE F_NAME like '%$FATHER%' ORDER BY RDATE";
}

elseif((($RNO!="") and ($CNAME!=="")) and (($DOB=="") or ($FATHER=="")))
{
$Query = "SELECT RNO as RegNo,DOB as BirthDate,NAME as ChildName ,F_NAME as FatherName,M_NAME as MotherName FROM $council WHERE RNO='$RNO' and NAME like '%$CNAME%' ORDER BY RDATE";
}
elseif((($RNO!="") and ($DOB==!"")) and (($CNAME=="") or ($FATHER=="")))
{
$Query = "SELECT RNO as RegNo,DOB as BirthDate,NAME as ChildName ,F_NAME as FatherName,M_NAME as MotherName FROM $council WHERE RNO='$RNO' and DOB='$DOB ORDER BY RDATE";
}
elseif((($RNO!="") and ($FATHER!=="")) and (($DOB=="") or ($NAME=="")))
{
$Query = "SELECT RNO as RegNo,DOB as BirthDate,NAME as ChildName ,F_NAME as FatherName,M_NAME as MotherName FROM $council WHERE RNO='$RNO' and FATHER like '%$FATHER%' ORDER BY RDATE";
}

elseif((($CNAME!="") and ($DOB==!"")) and (($RNO=="") or ($FATHER=="")))
{
$Query = "SELECT RNO as RegNo,DOB as BirthDate,NAME as ChildName ,F_NAME as FatherName,M_NAME as MotherName FROM $council WHERE DOB='$DOB' and NAME like '%$CNAME%' ORDER BY RDATE";
User avatar
Saethyr
Forum Contributor
Posts: 182
Joined: Thu Sep 25, 2003 9:21 am
Location: Wichita, Kansas USA
Contact:

Post by Saethyr »

no change just making easier to read

Code: Select all

<?php
if(($RNO=="") and ($CNAME=="") and ($DOB=="") and ($FATHER=="")) 
{ 
echo "<p align ="center">Select the search criteria correctly.</p>"; 
} 

elseif(($RNO!="") and (($CNAME=="") or ($DOB=="") or ($FATHER==""))) 
{ 
$Query = "SELECT RNO as RegNo,DOB as BirthDate,NAME as ChildName ,F_NAME as FatherName,M_NAME as MotherName FROM $council WHERE RNO='$RNO'"; 
} 
elseif(($CNAME!="") and (($RNO=="") or ($DOB=="") or ($FATHER==""))) 
{ 
$Query = "SELECT RNO as RegNo,DOB as BirthDate,NAME as ChildName ,F_NAME as FatherName,M_NAME as MotherName FROM $council WHERE NAME like '%$CNAME%' ORDER BY DOB"; 
} 
elseif(($DOB!="") and (($CNAME=="") or ($RNO=="") or ($FATHER==""))) 
{ 
$Query = "SELECT RNO as RegNo,DOB as BirthDate,NAME as ChildName ,F_NAME as FatherName,M_NAME as MotherName FROM $council WHERE DOB='$DOB' ORDER BY RDATE"; 
} 
elseif(($FATHER!="") and (($CNAME=="") or ($RNO=="") or ($DOB==""))) 
{ 
$Query = "SELECT RNO as RegNo,DOB as BirthDate,NAME as ChildName ,F_NAME as FatherName,M_NAME as MotherName FROM $council WHERE F_NAME like '%$FATHER%' ORDER BY RDATE"; 
} 

elseif((($RNO!="") and ($CNAME!=="")) and (($DOB=="") or ($FATHER==""))) 
{ 
$Query = "SELECT RNO as RegNo,DOB as BirthDate,NAME as ChildName ,F_NAME as FatherName,M_NAME as MotherName FROM $council WHERE RNO='$RNO' and NAME like '%$CNAME%' ORDER BY RDATE"; 
} 
elseif((($RNO!="") and ($DOB==!"")) and (($CNAME=="") or ($FATHER==""))) 
{ 
$Query = "SELECT RNO as RegNo,DOB as BirthDate,NAME as ChildName ,F_NAME as FatherName,M_NAME as MotherName FROM $council WHERE RNO='$RNO' and DOB='$DOB ORDER BY RDATE"; 
} 
elseif((($RNO!="") and ($FATHER!=="")) and (($DOB=="") or ($NAME==""))) 
{ 
$Query = "SELECT RNO as RegNo,DOB as BirthDate,NAME as ChildName ,F_NAME as FatherName,M_NAME as MotherName FROM $council WHERE RNO='$RNO' and FATHER like '%$FATHER%' ORDER BY RDATE"; 
} 

elseif((($CNAME!="") and ($DOB==!"")) and (($RNO=="") or ($FATHER==""))) 
{ 
$Query = "SELECT RNO as RegNo,DOB as BirthDate,NAME as ChildName ,F_NAME as FatherName,M_NAME as MotherName FROM $council WHERE DOB='$DOB' and NAME like '%$CNAME%' ORDER BY RDATE";
?>
Arulraj
Forum Newbie
Posts: 10
Joined: Sun Dec 14, 2003 11:41 pm
Location: India

Post by Arulraj »

I am using only notepad thatswhy. The syntax is correct.

I want to know why the rows are not getting populated as it should be.

If there is only one recoed then php reports no record found and if there are 8 records it shows only 7 records on the table display.

If anyone gets any clue, please clarify the doubt
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

#1. ($RNO=="") and ($RNO!="") should be replaced with: (isset($RNO)) or (!isset($RNO)) or (empty($RNO)).

#2. I don't think the queries are the problem, could you please post the rest of the code where you echo the rows.
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post by Paddy »

Damn those else ifs make it hard to read. You can build the query one the fly using seven ifs if you like.

Code: Select all

<?php
$Query = "SELECT RNO as RegNo,DOB as BirthDate,NAME as ChildName ,F_NAME as FatherName,M_NAME as MotherName FROM $council";
if ($RNO!="")
{
    $Query = $Query." WHERE RNO='".$RNO."'";
    $ifused = "true";
}
if ($CNAME!="")
{
     if ($ifused != "")
    {
         $Query = $Query." AND ";
    }
    $Query = $Query." WHERE NAME like '%".$CNAME."%' ORDER BY DOB";
    $ifused = "true";
}
if ($DOB!="")
{
     if ($ifused != "")
    {
         $Query = $Query." AND ";
    }
    $Query = $Query." WHERE DOB='".$DOB."' ORDER BY RDATE";
    $ifused = "true";
}
if ($FATHER!="")
{
     if ($ifused != "")
    {
         $Query = $Query." AND ";
    }
    $Query = $Query." WHERE F_NAME like '%".$FATHER."%' ORDER BY RDATE";
    $ifused = "true";
}
?>
If you can understand what Duff said about isset then put that in the code. I did it this way in case you didn't. His was is better though. I haven't tested this code by the way but you can see what I am trying to do.
Arulraj
Forum Newbie
Posts: 10
Joined: Sun Dec 14, 2003 11:41 pm
Location: India

Post by Arulraj »

Thanks Duffy and Paddy,

I could solve the problem. I have misused the if condition.

Anyhow thanks for your valuable suggestion.

thanks
Post Reply