while trying to figure out how to iterate through a data object, and retrieve each consecutive row, I am facing the problem of being without a consecutively numbered PRIMARY KEY. in effort to figure out, and better see what the heck is making this so darn difficult, i've constructed a little something which might make for a useful "Example Output".
// NOTE: Data Object Properties:
// the method is: selectAll('$table'))
// which returns the MYSQL_ASSOC from a simple "SELECT * FROM $table" query
$maindata = new mainData();
$select=array($maindata->selectAll('event'));
$i=0;
$myArray = array();
while($i<=$maindata->numrows) {
foreach($maindata as $x => $row) {
$myArray[$i] = $row;
$z = $i+1;
echo "<br /><span style=\"color:red;\">BEGIN: while() iteration $z </span> <br />during this foreach() loop, the value of print_r(\$row) is:<br />"; // AN ECHO ROW
print_r($row);
echo "<br />Therefore, \$myArray[".$i."] = <pre>";
print_r($row);
echo "</pre><br />And to demonstrate precisely what was stored in MY new array:";
echo "<br />with the ASSOCiative key (\$i) shown in \$myArray[\$i]:<br /><span style=\"color:blue\"> \$myArray[".$x."]</span> holds: <br /> <pre style=\"color:blue\">"; // AN ECHO ROW
print_r($myArray[$i]);
echo "</pre><span style=\"color:lightgray;\">END iteration $z </span><br />";
$i++;
}
}
i know it's helping me to 'see' what's giong on. 🙂
ATTN Google People finding this:
This little "viewer" i created while trying to understand why my looping through a Data Access Object was showing the same info every time. by using print_r, i was able to see ever element of the Object, individually, throughout each iteration of the loop. i recommend, if you did find this while doing research, that you reference also:
http://phpbuilder.com/board/showthread.php?t=10332665#post10767829
-- i needed a primary key for a table w/out any consistent enumeration.
after finally achieving what i sought out to do w/ the Data Object, i found that the code below painted a nice picture of the results -- for later sorting w/ direct reference to the associative keys within these arrays
$maindata = new mainData();
$myArray = array();
for($i=0;$i<=$maindata->numrows;$i++) {
echo "<br />Iteration no. $i <br /><pre>";
$myArray[$i] = $maindata->selectAll('event',$i);
echo "\$myarray[".$i."] is valued at<br />";
print_r($maindata->selectAll('event',$i));
echo "</pre>";
}