This is a discussion on If / then statement within the PHP Language forums, part of the PHP Programming Forums category; This is probably one of my weaker points and any directions or starting off point would be greatly appreciated. Below ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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("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'] . '"></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 |
|
|||
|
.oO(Mikey P)
>$query = mysql_query("SELECT DISTINCT * FROM itltest WHERE >city='$city2' AND state='$state2' AND directorytile<>'NULL' ORDER BY ^^^^^^ 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. >echo('<a href="wpa.php?jobnum=' . $row['jobnum'] . '&custID=' . ^ You have to use & when printing out URLs. The above is invalid code and might lead to unexpected results. >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. 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>', $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 |
|
|||
|
Michael Fesser <netizen@gmx.net> wrote in message news:<fl3go0t4tetd6i7hd6bl8ll86fh77s1ttd@4ax.com>. ..
> >echo('<a href="wpa.php?jobnum=' . $row['jobnum'] . '&custID=' . > ^ > You have to use & when printing out URLs. The above is invalid code > and might lead to unexpected results. > I was going to call bull on this, but you are, in fact, correct. http://ppewww.ph.gla.ac.uk/~flavell/...mgetbyurl.html 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. |