Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Thanked 0 Times in 0 Posts

    Count and rows code

    What is the explanation or meaning of this code:

    PHP Code:
    $totalarr count($opname) - 1

    PHP Code:
    $totalrows mysql_num_rows($result);
    $trows $totalrows 1
    Thank you

  2. #2
    Senior Coder
    Join Date
    Apr 2010
    Thanked 110 Times in 109 Posts
    Count = Counts all elements in an array, or properties in an object.

    mysql_num_rows = Retrieves the number of rows from a result set. This command is only valid for statements like SELECT or SHOW that return an actual result set. To retrieve the number of rows affected by a INSERT, UPDATE, REPLACE or DELETE query, use mysql_affected_rows().

  3. #3
    Regular Coder
    Join Date
    May 2008
    Thanked 5 Times in 5 Posts
    $totalarr = count($opname) - 1;

    $totalarr is most likely refering to an array based on 'arr', once count() has done its business as explained by myfayt, then a -1 is added to the final score combat the fact that in programming indexing starts at 0 not 1. Due to this little confusing fact when you have 5 elements in array you will actually stop on index 4. so you want $totalarr to reflect the correct index as the array has. If you were to try and access the last element of an array using a value from $totalarr without having the -1... you will get an out of bounds error. This will happen because you were asking it to access index 5 when the array only goes index 4.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts