Re: mysql_data_seek in a FOR loop
| From: | Tom Rogers | Date: | Tue, 22 Oct 2002 16:50:11 +0000 |
| Subject: | Re: mysql_data_seek in a FOR loop | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-120949@lists.php.net to get a copy of this message | ||
Hi,
Wednesday, October 23, 2002, 2:11:24 AM, you wrote:
JB> Where I have a DB return more than 10 rows of information I need to print
JB> two columns (actually four) of data, so side-by-side layout is needed. I
JB> tried using mysql_data_seek() to accomplish this, but to no avail. Can
JB> anyone see where I have gone wrong?
JB> $stat = "SELECT DISTINCT(event) AS eventname, COUNT(event) AS eventcount
JB> FROM tblHistory WHERE userID = '" . $userid . "' GROUP BY event ";
JB> if(!($dbstat = mysql_query($stat, $dbconnect))){
JB> print("MySQL Error: " . mysql_error() . "\n");
JB> exit();
JB> }
JB> // print stats to page for user
JB> $numrows = mysql_num_rows($dbstat);
JB> print("<table cellpadding=\"3\" cellspacing=\"0\"
JB> border=\"0\"
width=\"65%\">>\n");
JB> $statrow = mysql_fetch_object($dbstat);
JB> if($numrows > 10){
JB> $seek1 = 0;
JB> $seek2 = 10;
JB> for($i = 1; $i <= 11; $i++){
JB> print(" <tr
JB> bgcolor=\"#99FFFF\">\n");
JB> print($seek1);
JB> mysql_data_seek($dbstat, "$seek1");
JB> print(" <td>" .
JB> $statrow->eventname . "</td>\n");
JB> print(" <td
JB> align=\"right\">" . $statrow->eventcount .
JB> "</td>\n");
JB> mysql_data_seek($dbstat, $seek2);
JB> print($seek2);
JB> print(" <td>" .
JB> $statrow->eventname . "</td>\n");
JB> print(" <td
JB> align=\"right\">" . $statrow->eventcount .
JB> "</td>\n");
JB> print(" </tr>\n");
JB> $seek1++; $seek2++;
JB> }
JB> }
JB> print("</table>\n");
JB> Thanks in advance!
JB> Jay
JB> "Too much code, not enough sleep."
You have to do the seek then fetch the row pointed to into the object,
mysql_fetch_object() gets one complete row of all fields not all rows
at once.....but arrays are easier :)
--
regards,
Tom