0

I want to write row number by point rating. But I can't do it this for last point.

    <?php
               $self=$db->query("SELECT * FROM table ORDER BY exam_name DESC");
               $a1=1;
               foreach ($self as $order)
               {

                   if($order['exam_name']==$gb['exam_name']) //$gb = selected exam by user id

                   {
                       echo $a1;
                       break;

                   }
                   $a1++;

               }
    ?>
K.Dᴀᴠɪs
  • 9,945
  • 11
  • 33
  • 43
llw
  • 1
  • 2
  • 1
    If you need to "break" out of a results loop, you're not constructing the right query. – Scuzzy Nov 26 '18 at 00:40
  • I deleted "break", no change. All point's ok but last saved points rating dont writing. – llw Nov 26 '18 at 00:48
  • Possible duplicate of [How to find the foreach index](https://stackoverflow.com/questions/141108/how-to-find-the-foreach-index) – Sean Pianka Nov 26 '18 at 01:24
  • No, fetch it was used twice. I deleted one and working. – llw Nov 26 '18 at 02:11
  • I would just let the MySQL do the work, but you would need to start `$a1 = 0` before the loop and `$a1++` directly inside the loop above your if statement. You never reach the last increment. – StackSlave Nov 26 '18 at 06:32
  • $a1 variable it does not matter, because used foreach. – llw Nov 27 '18 at 14:03

0 Answers0