Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder jcdevelopment's Avatar
    Join Date
    Oct 2007
    Location
    Cowboy Nation
    Posts
    2,182
    Thanks
    174
    Thanked 257 Times in 257 Posts

    Adding numbers to each row

    I have this current code that easily spits out entered data along with a time stamp.

    PHP Code:
    <?php
    $db 
    mysql_connect('*','*','*');
    mysql_select_db('*',$db);

    $sel "SELECT * from rsvp_101";

    $q mysql_query($sel,$db);
    echo 
    "<table>";
    while (
    $row mysql_fetch_assoc($q)) {


      
    $first_name $row['first_name'];
      
    $last_name $row['last_name'];
      
    $office $row['office'];
      
    $guests $row['guests'];
      
    $date $row['date'];
     


      echo(
    "
      
      <tr><td>$first_name $last_name </td> <td>$office </td><td> Guests attending: $guests</td><td> $date</tr>
      
      <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
      <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
      "
    );
      
                

      
    }

    ?>
    I am just looking for a solution in PHP to add, in numerical order, a number on each line repeating. Does anyone know of a way so it will look something like this:

    1 name office date
    2 name office date
    3 name office date
    etc....

    thanks for any help.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,464
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    like this?

    PHP Code:
    <?php 
    $db 
    mysql_connect('*','*','*'); 
    mysql_select_db('*',$db); 

    $sel "SELECT * from rsvp_101"

    $q mysql_query($sel,$db); 
    echo 
    "<table>"

    $line=1;

    while (
    $row mysql_fetch_assoc($q)) { 


      
    $first_name $row['first_name']; 
      
    $last_name $row['last_name']; 
      
    $office $row['office']; 
      
    $guests $row['guests']; 
      
    $date $row['date']; 

    echo(

       
      <tr><td>$line</td><td>$first_name $last_name </td> <td>$office </td><td> Guests attending: $guests</td><td> $date</tr> 
       
      <tr><td>&nbsp;</td><td>&nbsp;</td></tr> 
      <tr><td>&nbsp;</td><td>&nbsp;</td></tr> 
      "
    ); 
    $line++;

                

       


    ?>

  • Users who have thanked mlseim for this post:

    jcdevelopment (02-29-2012)

  • #3
    Senior Coder jcdevelopment's Avatar
    Join Date
    Oct 2007
    Location
    Cowboy Nation
    Posts
    2,182
    Thanks
    174
    Thanked 257 Times in 257 Posts
    could have sworn i tried that.... It never worked, probably placed it in the whil statement. Thanks!


  •  

    Tags for this Thread

    Posting Permissions

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