Re: empty variable if/then



Mikey P wrote:
Hi there, i'm trying to figure out if there is an empty variable in a
search to return an alternative result...

like:

$query = mysql_query("SELECT * FROM db WHERE city='$city2' AND
state='$state2' ORDER BY title");
while($row = mysql_fetch_assoc($query)){
if (empty($url)) {
echo($row['title'] . '<br>');
} else {
echo
echo('<b><a href="' . $row['url'] . '>' . $row['title'] . '</a></b>');
}
}

from what it looks like it seems to be searching and saying if there is
any result that is empty in $url return this result. I guess i need to
know how to say.. if there is an empty $url on this row return this
result if there isn't then return the other. :) hope that makes some
sort of sense... Sorry i'm still fairly new at this.


Mikey,

It depends on the contents of the column 'url'. It could be null, or it could be a zero length string ("").

If you insert null values when there is no URL, then you should use

if(is_null($row['url']) ...

If it's an empty string, it could still be padded with blanks, so you can use something like

if (empty(trim($row['url'])) ...


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.



Relevant Pages

  • Re: how to show only entered fields ?
    ... >>Before you echo out the form value check to see if it's empty. ... >>comparing it to an empty string will do, but if it doesn't try comparing ...
    (comp.lang.php)
  • Re: Convertin dbnull to string
    ... I think what you should do is to assign dbnull value to ... >a valid DateTime. ... >> DbNull is a special value and not an empty string. ...
    (microsoft.public.dotnet.framework.adonet)
  • Wordpress <=2.0.2 cache shell injection
    ... if user registration is enabled, ... php files. ... DB_PASSWORD costant could be empty, ... echo 'No response from '.$host.':'.$port; die; ...
    (Bugtraq)
  • Re: Enter "Empty" if cell is blank within a variable range
    ... Dim Test As String ... My suggeste code will populate all empty cells columns A:B, ... I have checked the value of the cell with the following. ... The debugger displays an empty string value. ...
    (microsoft.public.excel.programming)
  • Re: Bash problems?
    ... The first returns true for either empty files or empty directories; the second returns true only if the given file is an empty directory. ... $ if isempty emptydir; then echo 'yes'; else echo 'no'; fi ... $ if isempty emptyfile; then echo 'yes'; else echo 'no'; fi ...
    (Fedora)