SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast bjoddn's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    organizing numbers

    I have a list of numbers that I want to look like this :

    1
    1.1
    1.123

    2
    2.4
    2.4567

    3
    3.456

    etc...

    I want to have a space between the whole numbers and no space between the others.

    What I have tried so far is omething like this :

    if ($row->number == 2) { echo("<br> $row->number"); }
    if ($row->number == 3) { echo("<br> $row->number"); }
    etc..
    else{echo(" $row->number"); }

    But when I do that, the whole numbers come up twice.

    Is there a simpler way to do this ?

  2. #2
    SitePoint Evangelist N9ne's Avatar
    Join Date
    Aug 2002
    Location
    UK
    Posts
    596
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please could you post some more code? Are you using MySQL with this?

  3. #3
    SitePoint Enthusiast bjoddn's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, I am using MySql

    Actually, there is not more code to post. All I want is to have a space between whole numbers and no space between the others.

    The code itself goes something like this :


    // if records present
    if (mysql_num_rows($result) > 0)
    {
    // iterate through resultset
    // print article titles
    while($row = mysql_fetch_object($result))
    {
    if ($row->numer == 2){
    echo(" <br>$row->numer - <a href="index1.php?id=$row->ID"> $row->nafn</a><br>");
    }
    if ($row->numer == 3){
    echo(" <br>$row->numer - <a href="index1.php?id=$row->ID"> $row->nafn</a><br>");
    }
    else{
    echo(" $row->numer - <a href="index1.php?id=$row->ID"> $row->nafn</a><br>");
    }
    }

    }
    // if no records present
    // display message
    else
    {
    ?>
    <font size="1">Hr er ekkert til a skoa.</font>
    <?
    }

    The only difference between the IF's and the ELSE is that there is no <br> in front in the else. This is not working though because I get number 2 twice.

  4. #4
    orange pips! orange pips!
    Join Date
    Oct 2001
    Location
    Its all about location
    Posts
    652
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Instead of checking for "is the number 2", instead just see if it's an integer. If so, print it with its space. Else print it with no space. Try using the is_int() command. Returns true if its an integer, false otherwise.


Bookmarks

Posting Permissions

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