RE: [PHP] Count function. (Newbie Question)
Hi There are 2 issues: You need to maintain a page counter You need to pass the page counter and the total page count from page to page You can do this via url params (xxx.html?page=$page_countrecord_count=$record_count), sessions or cookies depending HTH -Original Message- From: Michael O'Neal [mailto:[EMAIL PROTECTED]] Sent: Monday, April 09, 2001 9:32 AM To: [EMAIL PROTECTED] Subject: [PHP] Count function. (Newbie Question) Hi, I'm trying to display a record count of some sort on a page I'm working on. For example, "Record 1 of 15". I can display the 1st number ok, but I'm a bit confused on what the count function should look like for the 2nd number (15, in this case). Here is my current (not working) code. ?php $query = "SELECT count(*) FROM mango_pr"; $result = mysql_query($query); $record_count = mysql_fetch_row($result); ? And then I'm calling the code with an "echo" later on: b?php echo $record_count ? /b/font This obviously isn't right...can anyone offer any suggestions? Thanks, mto Michael O'Neal Web Producer/ Autocrosser ST 28 '89 Civic Si - M A N G O B O U L D E R - http://www.thinkmango.com [EMAIL PROTECTED] p-303.442.1821 f-303.938.8507 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Count function. (Newbie Question)
Look here as a starting point: http://www.php.net/manual/en/function.mysql-num-rows.php I don't know the exact answer to your question but I hope that this helps. -- Rodney Michael O'Neal wrote: Hi, I'm trying to display a record count of some sort on a page I'm working on. For example, "Record 1 of 15". I can display the 1st number ok, but I'm a bit confused on what the count function should look like for the 2nd number (15, in this case). Here is my current (not working) code. ?php $query = "SELECT count(*) FROM mango_pr"; $result = mysql_query($query); $record_count = mysql_fetch_row($result); ? And then I'm calling the code with an "echo" later on: b?php echo $record_count ? /b/font This obviously isn't right...can anyone offer any suggestions? Thanks, mto Michael O'Neal Web Producer/ Autocrosser ST 28 '89 Civic Si - M A N G O B O U L D E R - http://www.thinkmango.com [EMAIL PROTECTED] p-303.442.1821 f-303.938.8507 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Count function. (Newbie Question)
Well, in this code, you are going to receive one line from your table that displays the total number of records. And that is it. Here is a sample from one of my tables, using the MySQL CLI: mysql select count(*) from locker; +--+ | count(*) | +--+ | 47 | +--+ 1 row in set (1.65 sec) If you can be a little more specific about what you want, maybe type up what you expect out, we can fix your query statement. Also, in this line: b?php echo $record_count ? /b/font You should put a ';' after the variable, just to save yourself the hassle of a parse error, when you get working code. On 4/9/01 9:32 AM, "Michael O'Neal" [EMAIL PROTECTED] wrote: Hi, I'm trying to display a record count of some sort on a page I'm working on. For example, "Record 1 of 15". I can display the 1st number ok, but I'm a bit confused on what the count function should look like for the 2nd number (15, in this case). Here is my current (not working) code. ?php $query = "SELECT count(*) FROM mango_pr"; $result = mysql_query($query); $record_count = mysql_fetch_row($result); ? And then I'm calling the code with an "echo" later on: b?php echo $record_count ? /b/font This obviously isn't right...can anyone offer any suggestions? Thanks, mto Michael O'Neal Web Producer/ Autocrosser ST 28 '89 Civic Si - M A N G O B O U L D E R - http://www.thinkmango.com [EMAIL PROTECTED] p-303.442.1821 f-303.938.8507 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Count function. (Newbie Question)
Hi There are 2 issues: You need to maintain a page counter You need to pass the page counter and the total page count from page to page You can do this via url params (xxx.html?page=$page_countrecord_count=$record_count), sessions or cookies depending HTH Let me elaborate a little bit more. I don't think I explained myself very well. Sorry to waste the bandwidth. I am building a little press-release administration for our sales department. There is a single page that contains form fields where they can input thier data. I want the users/admins to be able to see what record number they are editing, and how many total records there are in the db. I have figured out the record number by echoing the "ID" of the record. I can't figure out how to display how many *total* records there are in that db. Does your tip still apply? Thanks again, mto Michael O'Neal Web Producer/ Autocrosser ST 28 '89 Civic Si - M A N G O B O U L D E R - http://www.thinkmango.com [EMAIL PROTECTED] p-303.442.1821 f-303.938.8507 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Count function. (Newbie Question)
No, this is different - try $query = "SELECT id,count(*) as result_count FROM mango_pr"; $result = mysql_query($query); $row = mysql_fetch_array($result); $id=$row['id']; $result_count=$row['result_count']; echo "$id,$result_count"; You might need to make the form action=$PHP_SELF if you want the form to loop Also you can use a progream structure like if ($submit) { // validate and update new stuff } else { // display the form action=$PHP_SELF } to display and validate the form -Original Message- From: Michael O'Neal [mailto:[EMAIL PROTECTED]] Sent: Monday, April 09, 2001 9:53 AM To: [EMAIL PROTECTED] Subject: RE: [PHP] Count function. (Newbie Question) Hi There are 2 issues: You need to maintain a page counter You need to pass the page counter and the total page count from page to page You can do this via url params (xxx.html?page=$page_countrecord_count=$record_count), sessions or cookies depending HTH Let me elaborate a little bit more. I don't think I explained myself very well. Sorry to waste the bandwidth. I am building a little press-release administration for our sales department. There is a single page that contains form fields where they can input thier data. I want the users/admins to be able to see what record number they are editing, and how many total records there are in the db. I have figured out the record number by echoing the "ID" of the record. I can't figure out how to display how many *total* records there are in that db. Does your tip still apply? Thanks again, mto Michael O'Neal Web Producer/ Autocrosser ST 28 '89 Civic Si - M A N G O B O U L D E R - http://www.thinkmango.com [EMAIL PROTECTED] p-303.442.1821 f-303.938.8507 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Count function. (Newbie Question)
Ya know, you don't even have to go that far. Now thati know more what you were looking for, after submitting a query like: SELECT * FROM table You will get all the data in your table. In php, you will have a $result to access that array of data (mysql_fetch_array(), mysql_fetch_row(),mysql_fetch_object() ) Using php, $number_of_records = mysql_num_rows_affected($result); Will return the number of records retrieved, in this case, the total amount. Don't need two queries, don't need put the count() function in the query. There are a lot of pieces of information regarding your query, that can be returned, without additional queries or extra statements in mysql. Take aminute to look at the names of ALL the mysql functions in PHP http://www.php.net/manual/en/ref.mysql.php On 4/9/01 10:30 AM, "Dell Coleman" [EMAIL PROTECTED] wrote: No, this is different - try $query = "SELECT id,count(*) as result_count FROM mango_pr"; $result = mysql_query($query); $row = mysql_fetch_array($result); $id=$row['id']; $result_count=$row['result_count']; echo "$id,$result_count"; You might need to make the form action=$PHP_SELF if you want the form to loop Also you can use a progream structure like if ($submit) { // validate and update new stuff } else { // display the form action=$PHP_SELF } to display and validate the form -Original Message- From: Michael O'Neal [mailto:[EMAIL PROTECTED]] Sent: Monday, April 09, 2001 9:53 AM To: [EMAIL PROTECTED] Subject: RE: [PHP] Count function. (Newbie Question) Hi There are 2 issues: You need to maintain a page counter You need to pass the page counter and the total page count from page to page You can do this via url params (xxx.html?page=$page_countrecord_count=$record_count), sessions or cookies depending HTH Let me elaborate a little bit more. I don't think I explained myself very well. Sorry to waste the bandwidth. I am building a little press-release administration for our sales department. There is a single page that contains form fields where they can input thier data. I want the users/admins to be able to see what record number they are editing, and how many total records there are in the db. I have figured out the record number by echoing the "ID" of the record. I can't figure out how to display how many *total* records there are in that db. Does your tip still apply? Thanks again, mto Michael O'Neal Web Producer/ Autocrosser ST 28 '89 Civic Si - M A N G O B O U L D E R - http://www.thinkmango.com [EMAIL PROTECTED] p-303.442.1821 f-303.938.8507 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]