If / then statement

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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:


$query = mysql_query("SELECT 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_assoc($query)) {

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



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

Re: If / then statement

 .oO(Mikey P)

Quoted text here. Click to load it
Why are you testing for a 'NULL'-string instead of the real NULL value?


You should use the IS NOT NULL operator instead.

Quoted text here. Click to load it
You have to use &amp; when printing out URLs. The above is invalid code
and might lead to unexpected results.

Quoted text here. Click to load it

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

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

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


Re: If / then statement

Quoted text here. Click to load it

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..
But, I wouldn't go so far as to say you "have" to.  I never have...
but as of now, I am.

Site Timeline