Maximum value in while command

Discussion in 'PHP' started by misterdh, Jul 2, 2010.

  1. #1
    Hi

    I want to display all tables in a while loop.

    $id=0;
    while($id<=7)
      {
      echo "The name is " . $name[$id] . " and the URL is " . $url[$id] . "<br />";
      $id++;
      }
    PHP:
    Where it sais "=7" I want the number to be maximum value. Meaning that if I have 7 rows it will say 7 and if I add 3 new rows it will automatically increase to 10..

    How can I do this?

    Thanks in advance :)
     
    misterdh, Jul 2, 2010 IP
  2. misterdh

    misterdh Peon

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Nevermind .. I figured it out :)
     
    misterdh, Jul 2, 2010 IP
  3. netload

    netload Member

    Messages:
    105
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    28
    #3
    $length = count($name);
    while ($i <= $length) {
    PHP:
    Another solution - try to use foreach cycle

    foreach ($name as $table_id => $table_name) {
      echo "The name is " . $table_name . " and the URL is " . $url[$table_id] . "<br />";
    }
    PHP:
     
    netload, Jul 2, 2010 IP
  4. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #4
    I think you missed this part :p

     
    lukeg32, Jul 2, 2010 IP