I need help about programming

Discussion in 'Programming' started by great_friend, Jul 29, 2008.

  1. #1
    Hello Guys

    my name is Azeem and i am working on php / mysql

    i want to showing ids from table and make code this

    <?php
    $sql="select * from $table where cat_id=$cat_id";
    $result=mysql_query($sql);
    while($rs=mysql_fetch_array($result))
    {
    echo $id=$rs['id'].",";
    ?>

    and showing result like this
    1,2,3,4,

    but i want result like this 1,2,3,4
    means not include coma(,) in last digit

    anyone tell me that how can i do this ?
    please help me
    i am thank to yours
     
    great_friend, Jul 29, 2008 IP
  2. Limotek

    Limotek Peon

    Messages:
    165
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Change it to something like

    
    <?php
    $i = 0;
    $sql="select * from $table where cat_id=$cat_id";
    $result=mysql_query($sql);
    while($rs=mysql_fetch_array($result))
    {
    if ($i<>0) echo ',';
    echo $id=$rs['id'];
    $i++;
    }
    ?>
    Code (PHP):
     
    Limotek, Jul 29, 2008 IP