Jump to content

[SOLVED] PHP increasing numbers


DrFishNips

Recommended Posts

This is a simple question but I couldn't think of what to put into google to get info on it. I need to dynamically number database results starting from 1. For example lets say I have a database with 3 entries "monkey", "badger", "armadillo" when I display the contents I need it to be like

1.) Armadillo

2.) Badger

3.) Monkey

Link to comment
https://forums.phpfreaks.com/topic/163522-solved-php-increasing-numbers/
Share on other sites

Or just add a counter to the loop $i++

Yeah thats what I'm talking about. I tried that and it works but the number starts at 0 for some reason. Do you know how to make it start at 1?

 

Put $i=1 before the loop.  If you post the relevant code it will be easier to help.

Sorry heres the code

  $query = "SELECT * FROM potg_memb_pm WHERE memb_username = '$pm_login' ORDER BY 'msg_date' LIMIT 10";

  $result = mysql_query($query);

  $num = mysql_num_rows($result);



  $i=0;

  while ($i < $num) {



    $msg_id = mysql_result($result, $i, "id");

    $memb_id = mysql_result($result, $i, "memb_id");

    $msg_sender = mysql_result($result, $i, "msg_sender");

    $msg_subject = mysql_result($result, $i, "msg_subject");

    $msg_body = mysql_result($result, $i, "msg_body");

    $msg_date = mysql_result($result, $i, "msg_date");

    $msg_time = mysql_result($result, $i, "msg_time");





    echo "  <tr>\n";

    echo "    <td><a class=\"gb_link\" href=\"?get=members&page=pm&action=show&msg=$msg_id\">";  echo $i; echo "</a></td>\n";

    echo "    <td><a class=\"gb_link\" href=\"?get=members&page=pm&action=show&msg=$msg_id\">$msg_subject</a></td>\n";

    echo "    <td><a class=\"gb_link\" href=\"?get=members&member=$memb_id\">$msg_sender</a></td>\n";

    echo "    <td>$msg_date</td>\n";

    echo "    <td>$msg_time</td>\n";

    echo "    <td><input type=\"checkbox\" name=\"1\" value=\"1\"></td>\n";

    echo "  </tr>\n";

    echo "        <br>\n";



    ++$i;

  

 

It lists members PM's and I'm trying to number the PM's from 1 up.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.