Re: Help with mysql rowpointer
| From: | Mike Flynn | Date: | Wed, 22 Aug 2001 13:19:19 +0000 |
| Subject: | Re: Help with mysql rowpointer | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-8996@lists.php.net to get a copy of this message | ||
To return the total amount of records in a table, just do:
$query = 'SELECT COUNT(*) FROM tblName';
$result = mysql_query($query);
$total_records = mysql_result($result, 0);
Or, for short,
$total_records = mysql_result(mysql_query($query), 0);
To step through the records, just do a normal SELECT query:
$query = 'SELECT stuff FROM tblName ';
$query .= "WHERE intStuff=$stuff ORDER BY stuff";
$result = mysql_query($query);
if ($row = mysql_fetch_row($result)) {
do {
while ($row = mysql_fetch_row($result));
}
else {
// stuff for if there are no records.
}
Does this answer your question? If not, please be more specific as to what I missed :)
-Mike
At 12:17 PM 8/22/2001 +0200, you wrote:
Hey there. I realize this is a forum for php-windows users,but knowing that most of you guys run a mysql db as backend i have a question for you.. I know there is a way to return the amount of records in the db by using the mysql_num_rows($resultid). My problem is that it only returns the total number of records from my query I have seen that there is a function called mysql_data_seel(par,par), but i am not sure how it works. My problem is the following> i want to do a print out of each record in the db , but the HTML code (to be exact the positioning of the HTML table should be different depending on the number of record printed out. To illustrate this is more or less what i want > i want to print out record 1 in one style , then i want to next record to be printed out in a different way. Is there a way to do a check on which number of record is printed out. I realize i cannot use the id simply because if i do a printout of total 4 records and i want to use a record with id = 100 e.g then it won't do me any good. Basically is there a way for me to check the number of record is printed out on a page. If i want to print out 4 records then the first row should be 1..Regardless of the ID stored in the db. I hope you understand me .if now i would be happy to reply with a more detailed instruction on my problem. in ODBC db i know one can use the rs.next object and method, but is there an equivalent to this in MYSQL.. Thanks everyone Lars Eirik -- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-windows-unsubscribe@lists.php.net For additional commands, e-mail: php-windows-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net
-=- Mike Flynn - Burlington, VT -=-mike@mikeflynn.net http://www.mikeflynn.net/ * Give blood * The modern conservative is engaged in one of man's oldest exercises in moral philosophy; that is, the search for a superior moral justification for selfishness.
-- James K. Galbraith