Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 07-03-2008, 05:33 PM Mysql Empty Rows
choskins102's Avatar
Super Talker

Posts: 137
Name: Casey
Trades: 3
I want to pull information down from a MySQL databse. If the row is populated, then it displays the information properly. However, if the row is empty, It leave the information blank. I want to replace this blank area with a default message. Here is an example of my code:

Code:
<?php
$con = mysql_connect($host, $user, $pass);
mysql_select_db($db, $con);

$sql = mysql_query("SELECT * FROM $table");
while ($row = mysql_fetch_array($sql)
{
echo $row['user']." - ".$row['gender'];
}
?>
The user field is required so there is always information set for that, but the gender field is optional. If the user has not opted to specify a gender, I want a message that says '<Not Specified>'.

I know I can set this as the default in the MySQL database, but I don't want to. How can I do this?
choskins102 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-03-2008, 06:23 PM Re: Mysql Empty Rows
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
This would be handled like this:
PHP Code:
while ($row mysql_fetch_array($sql)) {
if (!empty(
$row['gender'])) {
echo 
$row['user']." - ".$row['gender'];
} else {
echo 
$row['user']." - <Not Specified>";
}

__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.
wayfarer07 is online now
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Reply     « Reply to Mysql Empty Rows
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.21650 seconds with 12 queries