From: "Dan Shirah" on
Hello all,

I am running the following query...I get the results I want, but for some
reason I am getting every valid result twice?

Any ideas?

$name_query = "SELECT caa44240002, caa44240003, caa44240004, caa442400018
FROM caa44240
WHERE caa442400018 = '$case_id'";
if ($case_category == "CJ") {
$name_query.="AND caa44240002 = 'C'
AND caa44240003 = '1'";
}
if ($case_category == "CF" || "MM" || "CT" || "TR" || "MO" || "IN" ||
"CO") {
$name_query.="AND caa44240002 = 'D'
AND caa44240003 = '1'";
}
$name_result = ifx_query ($name_query, $connect_id);
while ($name = ifx_fetch_row($name_result)) {
$party_name = TRIM($name['caa44240004']);
print_r($name);
}

print_r($name) will return:
John
John
Mary
Mary
Cindy
Cindy
From: "Bastien Koert" on
On Fri, Jul 25, 2008 at 4:55 PM, Dan Shirah <mrsquash2(a)gmail.com> wrote:

> Hello all,
>
> I am running the following query...I get the results I want, but for some
> reason I am getting every valid result twice?
>
> Any ideas?
>
> $name_query = "SELECT caa44240002, caa44240003, caa44240004, caa442400018
> FROM caa44240
> WHERE caa442400018 = '$case_id'";
> if ($case_category == "CJ") {
> $name_query.="AND caa44240002 = 'C'
> AND caa44240003 = '1'";
> }
> if ($case_category == "CF" || "MM" || "CT" || "TR" || "MO" || "IN" ||
> "CO") {
> $name_query.="AND caa44240002 = 'D'
> AND caa44240003 = '1'";
> }
> $name_result = ifx_query ($name_query, $connect_id);
> while ($name = ifx_fetch_row($name_result)) {
> $party_name = TRIM($name['caa44240004']);
> print_r($name);
> }
>
> print_r($name) will return:
> John
> John
> Mary
> Mary
> Cindy
> Cindy
>

maybe a distinct in the field selection

select DISTINCT blah from blah where...

--

Bastien

Cat, the other other white meat
From: Paul Gregg on
In mail.php.general, Dan Shirah <mrsquash2(a)gmail.com> wrote:
> $name_result = ifx_query ($name_query, $connect_id);
> while ($name = ifx_fetch_row($name_result)) {
> $party_name = TRIM($name['caa44240004']);
> print_r($name);
> }
>
> print_r($name) will return:
> John
> John
> Mary
> Mary
> Cindy
> Cindy

I don't know anything about the Informix functions, but in other database
types fetch_row can return "doubly indexed" entries. e.g.
array(
0 => 'John',
'name' => 'John',
)

I would suggest you use var_dump() or var_export() to get a better idea of
what is in $name - you might find if this is the case that your code
is not necessarily wrong because you are getting the right number of rows.

Note it is hard to tell from your code - because your code would run
print_r() for every loop - but that isn't what your suggested output is.

Regards,
PG