David T-G wrote:

Note that I don't recommend this as the best approach, and I don't think
that anyone else does, either.  Usually you want to avoid sucking an
entire database into your script's memory; the database (and its coders)
almost always handles data better than we mere mortals.  A much better
approach is to make your select call per specific ID and get out only the
name(s) that you need, and then go back later and make a different call.
The only time I can see sense in scanning the whole table is when you
want to dump the entire list of people or some such, and then rather than
doing it in two steps of loading your $everyone and then spitting out I'd
probably do something like

  $sql = "select id,name from a_table order by department" ;
  $result = mysql_query($sql) ;
  while ( $row = mysql_fetch_array($result) )
    { print "ID: {$row['id']}\tName: {$row['name']}<br>\n" ; }

to just run through the data.  I'm sure others here know of even better
ways to print a roster :-)

% % Any help would be wonderful! :)



Indeed, I was trying to simply display a list of the data. I had coded the formatting and displaying first, based on the array I described, then tackled the MySQL part last. I see now that it prevented me from seeing the better idea of removing the array from the equation completely. Your information was invaluble.

I did however go with mysql_fetch_assoc instead of mysql_fetch_array for efficiency. :)

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

Reply via email to