Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.