Re: [PHP] while() looping over query results twice?

2001-10-25 Thread Kurt Lieber

I don't think so, but if I have to suspect my code or a bug in php, I'll 
suspect my code. :)

I did a quick "if (isset($companyID_string)) { print "true"; } else { print 
"false";} and that didn't turn up anything, but I didn't spend a whole lot of 
effort on it.

Like I said, I'm pretty sure I screwed something up -- when I have more time, 
I'll try and figure out what it was.

Thanks again to all who responded.

--kurt

On Thursday 25 October 2001 13:22, you wrote:
> what I guessed was that you were using the variables somewhere else in the
> script above this code.  then you were adding on to them again.  without
> resetting them to blank.  Are you using these vars somewhere else (above
> this) in your code?



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] while() looping over query results twice?

2001-10-25 Thread Jim Lucas

what I guessed was that you were using the variables somewhere else in the
script above this code.  then you were adding on to them again.  without
resetting them to blank.  Are you using these vars somewhere else (above
this) in your code?

jim
- Original Message -
From: "Kurt Lieber" <[EMAIL PROTECTED]>
To: "Jim Lucas" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Thursday, October 25, 2001 1:17 PM
Subject: Re: [PHP] while() looping over query results twice?


> OK, so I defined the variables before using them and that solved the
problem.
>  (Thanks!)
>
> I'm still curious as to why not defining them ahead of time would cause
the
> data within each string to get duplicated.  In other words, if the query
> results are "a,b,c,d", then by not defining the variable ahead of time
> produces "a,b,c,d,a,b,c,d" which is weird.
>
> At this point, my problem is solved, so this is more of an academic
question
> than anything.
>
> Thanks for the help.
>
> --kurt
>
> On Thursday 25 October 2001 13:03, Jim Lucas wrote:
> > I notice that you are concatinating then each time.  try setting them to
> > ="" before using them
> >
> >  $companyID_string = "";
> >  $companyName_string = "";
> > then:
> > while()
> > {
> > $companyID_string .= "," . $query_data[0];
> > $companyName_string .= "," . $query_data[1];
> > }
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] while() looping over query results twice?

2001-10-25 Thread Kurt Lieber

OK, so I defined the variables before using them and that solved the problem. 
 (Thanks!)

I'm still curious as to why not defining them ahead of time would cause the 
data within each string to get duplicated.  In other words, if the query 
results are "a,b,c,d", then by not defining the variable ahead of time 
produces "a,b,c,d,a,b,c,d" which is weird.

At this point, my problem is solved, so this is more of an academic question 
than anything.

Thanks for the help.

--kurt

On Thursday 25 October 2001 13:03, Jim Lucas wrote:
> I notice that you are concatinating then each time.  try setting them to
> ="" before using them
>
>  $companyID_string = "";
>  $companyName_string = "";
> then:
> while()
> {
> $companyID_string .= "," . $query_data[0];
> $companyName_string .= "," . $query_data[1];
> }

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] while() looping over query results twice?

2001-10-25 Thread Jim Lucas

I notice that you are concatinating then each time.  try setting them to =""
before using them

 $companyID_string = "";
 $companyName_string = "";
then:
while()
{
$companyID_string .= "," . $query_data[0];
$companyName_string .= "," . $query_data[1];
}
Jim

ps.  try using the mysql_fetch_array()  and calling to the vars as
$query_data[] instead.

- Original Message -
From: "Kurt Lieber" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, October 25, 2001 12:51 PM
Subject: [PHP] while() looping over query results twice?


> I'm executing a query that returns some a UID and a company name.  I'm
using
> the following code to loop over that query result set:
>
> $result = mysql_query($myQuery) //$myQuery gets defined earlier
> $resultCount = mysql_num_rows($result);
> $companyID = array();
> while($query_data = mysql_fetch_row($result)) {
> $companyID[$query_data[0]] = $query_data[1];
> $companyID_string .= "," . $query_data[0];
> $companyName_string .= "," . $query_data[1];
> }
>
> I've used $resultCount to verify the query is returning 4 rows.  However,
the
> while loop above is looping over the results twice -- $companyID_string
and
> $companyName_string each have 8 values.  Looking at the values shows that
> it's the 4 rows duplicated.
>
> What the heck am I doing wrong?
>
> --kurt
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] while() looping over query results twice?

2001-10-25 Thread Mike Eheler

Trying using mysql_fetch_array, and using the field names. This is the 
recommended behaviour in PHP4:

$result = mysql_query($myQuery) //$myQuery gets defined earlier
$resultCount = mysql_num_rows($result);
$companyID = array();
while($query_data = mysql_fetch_array($result)) {
$companyID[$query_data['CompanyID']] = $query_data['CompanyName'];
$companyID_string .= "," . $query_data['CompanyID'];
$companyName_string .= "," . $query_data['CompanyName'];
}

That probably isn't the problem, but hey.. you never know.

I also noticed there's no ; after mysql_query ;)

Lastly, you could also do (for debugging):

while ($query_data = mysql_fetch_array($result)) {
$tmp[] = $query_data;
}

echo '';
ob_start();
print_r($tmp);
$text = ob_get_contents();
ob_end_clean();
echo htmlspecialchars($text);
echo '';

To see what exactly is being returned.

Mike

Kurt Lieber wrote:

>I'm executing a query that returns some a UID and a company name.  I'm using 
>the following code to loop over that query result set:
>
>$result = mysql_query($myQuery) //$myQuery gets defined earlier
>$resultCount = mysql_num_rows($result);
>$companyID = array();
>while($query_data = mysql_fetch_row($result)) {
>$companyID[$query_data[0]] = $query_data[1];
>$companyID_string .= "," . $query_data[0];
>$companyName_string .= "," . $query_data[1];
>}
>
>I've used $resultCount to verify the query is returning 4 rows.  However, the 
>while loop above is looping over the results twice -- $companyID_string and 
>$companyName_string each have 8 values.  Looking at the values shows that 
>it's the 4 rows duplicated.
>
>What the heck am I doing wrong?
>
>--kurt
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] while() looping over query results twice?

2001-10-25 Thread Kurt Lieber

I'm executing a query that returns some a UID and a company name.  I'm using 
the following code to loop over that query result set:

$result = mysql_query($myQuery) //$myQuery gets defined earlier
$resultCount = mysql_num_rows($result);
$companyID = array();
while($query_data = mysql_fetch_row($result)) {
$companyID[$query_data[0]] = $query_data[1];
$companyID_string .= "," . $query_data[0];
$companyName_string .= "," . $query_data[1];
}

I've used $resultCount to verify the query is returning 4 rows.  However, the 
while loop above is looping over the results twice -- $companyID_string and 
$companyName_string each have 8 values.  Looking at the values shows that 
it's the 4 rows duplicated.

What the heck am I doing wrong?

--kurt

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]