473,399 Members | 3,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

empty variable if/then

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.

Feb 28 '06 #1
2 4723
try this :

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

im not shure if I cleary understand the question because im french ...
so .. tell me if that help you !!
by the way u should always valid the $mysql_query before doing anything
:) !

Feb 28 '06 #2
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.
js*******@attglobal.net
==================
Feb 28 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I...
3
by: tornado | last post by:
Hi all, I am pretty new to PHP. I was reading PHP manual and trying out the example from 2nd chapter (A simple Tutorial). When i try to print the variable as given in the example it returns...
10
by: David Graham | last post by:
Hi I have been busy going through the last weeks postings in an attempt to absorb javascript syntax (I guess it's not possible to just absorb this stuff in a passive way - I'm getting way out of...
3
by: Erica | last post by:
I am trying to display an error if the txtmsg variable is true and the cellnumber and cellprovider variables are empty. Here is the code that generates my error: If request("txtmsg") = "true"...
8
by: Lyn | last post by:
I am trying to get my head around the concept of default, special or empty values that appear in Access VBA, depending on data type. The Access Help is not much (help), and the manual that I have...
21
by: M D | last post by:
You know how you assume you know until you find out you don't know. Well, I typed into a function definition "..., new String("")). I know what I want. Everyone reading this knows what I want....
5
by: Shapper | last post by:
Hello, I am using this code line to check i a variable exists: If cookie Is Nothing Then .... How can I check if cookie is empty when cookie exists? Thanks, Miguel
26
by: anonieko | last post by:
In the past I always used "" everywhere for empty string in my code without a problem. Now, do you think I should use String.Empty instead of "" (at all times) ? Let me know your thoughts.
1
by: Brad Pears | last post by:
I am using vb.net 2005 and SQL server 2000. In my table I have a date field of type "smalldatetime". In my vb application, the user may or may not enter a date value into the appropriate text box....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.