SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Thread: How do you...

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    Ontario, Canada
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do you...

    I was just curious how one would go about the following:

    I have created a table in MySQL with a column called routemap, for some rows I will have information and others I will not. Is there a way that when coding in PHP you can ignore the ones that have no information. Ok this sound rather confusing but let me explain further. For the rows with information in the routemap column, I want to display the information as follows:

    PHP Code:
    <br>&nbsp;ip policy route-map <?=$data->routemap?>
    However for the rows with no information under routemap I do not want anything to be displayed. Is there any simple method (or long method) of doing so, as I do not wish to add the
    Code:
    <br>&nbsp;ip policy route-map
    to every row that has information in my database.

    Any help on this issue would be greatly appreciated (god I am such a newbie).

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think adding
    Code:
    WHERE routemap NOT NULL
    to the SELECT query should do it

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    Ontario, Canada
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes but I failed to mention that there will be other information in the rows that I do want displayed, and unless I am mistaken the WHERE routemap NOT NULL would actually ignore the entire row.

    Also I can't do a WHERE routmap NOT NULL and then another loop say as WHERE routmap NULL which of would display all the rows, but not in the order I need, I need them ordered by id.

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    something like
    PHP Code:
    <?php
    if (isset($data->routemap)) {
    echo 
    "<br>&nbsp;ip policy route-map {$data->routemap}";
    }
    ?>

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    Ontario, Canada
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok let me try that

  6. #6
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    Ontario, Canada
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It didn't seem to work, my code is as follows:

    PHP Code:
    <?php
    $query 
    mysql_query("SELECT * FROM sheet2 ORDER BY id");
    while (
    $data mysql_fetch_object($query)) {
    ?>
    !
    <br>interface <?=$data->interface?>
    <?php 
    if (isset($data->description)) { 
    echo 
    "<br>&nbsp;description {$data->description}"

    ?>
    <?php 
    if (isset($data->ip)) { 
    echo 
    "<br>&nbsp;ip address {$data->ip} {$data->subnet}"

    ?><?php 
    if (isset($data->sip)) { 
    echo 
    "&nbsp;secondary<br>&nbsp;ip address {$data->sip} {$data->ssubnet}"

    ?>
    <?php 
    if (isset($data->routemap)) { 
    echo 
    "<br>&nbsp;ip policy route-map {$data->routemap}"

    ?>
    <?php 
    if (isset($data->pvc)) { 
    echo 
    "<br>&nbsp;pvc {$data->pvc}"

    ?>
    <br>&nbsp;!
    <br>
    <?php
    }
    ?>
    And wherever I do not have information in the database for a particular column the text is still displayed.

  7. #7
    SitePoint Addict Viral's Avatar
    Join Date
    Nov 2001
    Location
    Washington DC
    Posts
    294
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I understand what you are saying. If I'm correct, you're saying you want to get a result set back, but if routemap is NULL, you want that field to display nothing. That's an easy mysql query...
    Code:
    select IFNULL(routemap,'') as routemap from table
    That will return either the value of routemap, or if it's NULL, it will return an empty string ''. (that's 2 single quotes, not a double quote). Obviously, add your other fields normally to the query.

    Hope this helps,
    --Viral
    A computer without Windows is like a chocolate cake without mustard.

  8. #8
    SitePoint Addict Viral's Avatar
    Join Date
    Nov 2001
    Location
    Washington DC
    Posts
    294
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, looking at your last post, I see this wouldn't work for you. An empty string is still setting the var. So your isset check is wrong. Do the query I showed above, but change your code to

    if ($data->routemap != '') {

    That should work for you...
    --Viral
    A computer without Windows is like a chocolate cake without mustard.

  9. #9
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    Ontario, Canada
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks viral, your suggestion worked perfectly for what I needed. I greatly appreciate that help, also thanks silan for the help as well ^_^


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
  •