--- Terence <[EMAIL PROTECTED]> wrote:
> I am trying to get the results of a function, which queries MySQL, back
> into an array for me to order. I only want to print out certain fields
> (I call the same query, but use different fields in different places).
> 
> This works is I print out the fields in the function itself:
> 
> while($row = mysql_fetch_array($result)) {
>     echo $row["id"] . "<br>";
> }

So why do you not want to use this method? Does it not do what you need?


> This however prints out an unending list of values:
[snip]
> $mysql_query = mysql_fetch_array($result);
> 
> while($row = $mysql_query) {
>     echo $row["id"] . "<br>";
> }

$row here is being set to a result set. You are querying MySQL (with an
empty query, something I've never tried), and until MySQL fails, this will
run forever.

You probably want to run your query once and then loop through the result
set. Mind your variable names as well, because your use of $row above adds
to the confusion.

$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);

Use things like that. You can also make sure $result is not false prior to
using it, because that is indicative of a failed query.

Hope that helps.

Chris

=====
My Blog
     http://shiflett.org/
HTTP Developer's Handbook
     http://httphandbook.org/
RAMP Training Courses
     http://www.nyphp.org/ramp

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to