note 61422 added to function.array
| From: | billatcarneycodotcom at osu1 dot php dot net | Date: | Fri, 03 Feb 2006 04:42:17 +0000 |
| Subject: | note 61422 added to function.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-102904@lists.php.net to get a copy of this message | ||
I wanted to be able to control the flow of data in a loop instead of just building tables with it or
having to write 500 select statements for single line items. This is what I came up with thanks to
the help of my PHP brother in FL. Hope someone else gets some use out it.
<?
//set array variable
$results = array();
//talk to the db
$query = "SELECT * FROM yourtable";
$result = mysql_query($query) or die(mysql_error());
//count the rows and fields
$totalRows = mysql_num_rows($result);
$totalFields = mysql_num_fields($result);
//start the loop
for ( $i = 0; $i < $totalRows; ++$i ) {
//make it 2 dim in case you change your order
$results[$i] = mysql_fetch_array($result);
//call data at will controlling the loop with the array
echo $results[your_row_id]['your_field_name']; }
//print the entire array to see what lives where
print_r($results); ?>
----
Server IP: 64.71.164.2
Probable Submitter: 68.101.4.135
----
Manual Page -- http://www.php.net/manual/en/function.array.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61422
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61422&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61422&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61422&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61422&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61422&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61422&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61422&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61422&report=yes
Search -- http://master.php.net/manage/user-notes.php