Current location: Hot Scripts Forums » Programming Languages » PHP » What if there is no entry?


What if there is no entry?

Reply
  #1 (permalink)  
Old 07-25-03, 02:54 PM
Cagez's Avatar
Cagez Cagez is offline
Eeew, dirty!
 
Join Date: Jun 2003
Location: Toronto, Ontario
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
What if there is no entry?

I'm writing a little article manager and I want to have it pull the avatar out of my vbulletindatabase based on a userid. I've got what I want, but what if the user doesn't have an avatar? This means that there won't be a row for that username in "customavatar" (where vb keeps the avatar info). Will mySQL through an error or will the u.filename just be blank? This is what I'm hoping for because I want to show a default image if they haven't set one.

TIA

PHP Code:

//(TABLE_PREFIX is a define of my table prefix I'm using for my system)


'SELECT a.articleid, a.categoryid, a.title, a.desc, u.filename FROM '.TABLE_PREFIX.
'_articles a, customavatar u WHERE u.userid = a.userid ORDER  BY a.articleid DESC LIMIT 0 , 10' 
Reply With Quote
  #2 (permalink)  
Old 07-26-03, 05:59 AM
nd2 nd2 is offline
Wannabe Coder
 
Join Date: Jun 2003
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
'SELECT a.articleid, a.categoryid, a.title, a.desc, u.filename FROM '.TABLE_PREFIX.
'_articles a, customavatar u WHERE u.userid = a.userid ORDER BY a.articleid DESC LIMIT 0 , 10'

in that query if it does not find a match for u.userid = a.userid it will not return the result.

however if you do a LEFT JOIN

'SELECT a.articleid, a.categoryid, a.title, a.desc, u.filename FROM '.TABLE_PREFIX.
'_articles a LEFT JOIN customavatar u ON u.userid = a.userid WHERE u.userid = a.userid ORDER BY a.articleid DESC LIMIT 0 , 10'

if there is no avatar, it will return a empty rows if it does not exsist.
__________________
IonCMS (Coming Soon.)
http://ioncms.com
--
Ncaster (Free php/mysql cms)
http://ncaster.cjb.net
Reply With Quote
  #3 (permalink)  
Old 07-27-03, 12:07 PM
Cagez's Avatar
Cagez Cagez is offline
Eeew, dirty!
 
Join Date: Jun 2003
Location: Toronto, Ontario
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Sweet, I'll test it out Thanks
Reply With Quote
  #4 (permalink)  
Old 07-29-03, 02:06 AM
nd2 nd2 is offline
Wannabe Coder
 
Join Date: Jun 2003
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
np
__________________
IonCMS (Coming Soon.)
http://ioncms.com
--
Ncaster (Free php/mysql cms)
http://ncaster.cjb.net
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
New Web Host, New Problem! justchat PHP 2 09-29-03 02:39 PM
Form Not working sparky PHP 5 06-19-03 12:54 PM


All times are GMT -5. The time now is 05:07 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.