If / then statement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mikey P

    If / then statement

    This is probably one of my weaker points and any directions or
    starting off point would be greatly appreciated.

    Below is the statement i have now to call up a search and basically
    call up images:

    <?php

    $query = mysql_query("SE LECT DISTINCT * FROM itltest WHERE
    city='$city2' AND state='$state2' AND directorytile<> 'NULL' ORDER BY
    company LIMIT 10") or die (mysql_error()) ;

    while ($row = mysql_fetch_ass oc($query)) {

    echo('<a href="wpa.php?j obnum=' . $row['jobnum'] . '&custID=' .
    $row['custID'] . '&wpastate=' . $row['wpastate'] . '&wpacity=' .
    $row['wpacity'] . '"><img src="' . $row['directorytile'] .
    '"></a><br><br>');

    }

    ?>


    What i'd like to do is expand it to if one field in mysql is filled
    out then the href is that field instead of going to the wpa.php page.
    Hope that makes sense. In a nutshell there will be the ability to fill
    out a unique url. IF that specific url is filled out then the image's
    href needs to go to that url. Thanks again for any direction. - Mikey
    p
  • Michael Fesser

    #2
    Re: If / then statement

    .oO(Mikey P)
    [color=blue]
    >$query = mysql_query("SE LECT DISTINCT * FROM itltest WHERE
    >city='$city2 ' AND state='$state2' AND directorytile<> 'NULL' ORDER BY[/color]
    ^^^^^^
    Why are you testing for a 'NULL'-string instead of the real NULL value?

    'NULL' != NULL

    You should use the IS NOT NULL operator instead.
    [color=blue]
    >echo('<a href="wpa.php?j obnum=' . $row['jobnum'] . '&custID=' .[/color]
    ^
    You have to use &amp; when printing out URLs. The above is invalid code
    and might lead to unexpected results.
    [color=blue]
    >What i'd like to do is expand it to if one field in mysql is filled
    >out then the href is that field instead of going to the wpa.php page.[/color]

    In your while-loop before printing out the link check for that field:

    while ($row = mysql_fetch_ass oc($query)) {
    if (!empty($row['url'])) {
    $url = $row['url'];
    } else {
    $url = 'wpa.php?jobnum =...';
    }
    printf('<a href="%s"><img src="%s"></a><br><br>',
    $url,
    $row['directorytile']);
    }

    It's also possible to let MySQL create the final URL, have a look at the
    IF() and CONCAT() functions in the manual.

    HTH
    Micha

    Comment

    • Brad Kent

      #3
      Re: If / then statement

      Michael Fesser <netizen@gmx.ne t> wrote in message news:<fl3go0t4t etd6i7hd6bl8ll8 6fh77s1ttd@4ax. com>...
      [color=blue][color=green]
      > >echo('<a href="wpa.php?j obnum=' . $row['jobnum'] . '&custID=' .[/color]
      > ^
      > You have to use &amp; when printing out URLs. The above is invalid code
      > and might lead to unexpected results.
      >[/color]

      I was going to call bull on this, but you are, in fact, correct.

      I've even experienced this before. thought it was a browser quirk..
      duh.
      But, I wouldn't go so far as to say you "have" to. I never have...
      but as of now, I am.

      Comment

      Working...