PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 7th, 2012, 09:53 AM
Triple_Nothing Triple_Nothing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 313 Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 15 h 8 m 35 sec
Reputation Power: 5
If/then written right?

Howdy y'all. I have the simple if/then in my while loop below. It is to meerly place an 'X' if an item has been paid. If the item HAS been paid, the value retrieved from the db is 1, otherwise 0. When the while loop runs, I get no errors, but every item is being marked with an 'X', even though a 0 (zero) has been return from the db. Am I overlooking something?

PHP Code:
 $invoices mysqli_query($con,"SELECT * FROM `invoices` WHERE MONTH(due) = " $month " ORDER BY `due` ASC;");
$category mysqli_query($con,"SELECT * FROM `category`;");
while(
$row mysqli_fetch_assoc($category)) {
      
$cat[] = $row;


PHP Code:
while ($list mysqli_fetch_assoc($invoices)) {
        if(
$list['paid'] = "1") { $paid "X"; } else { $paid ""; }
        echo 
"      <tr>
        <td align=\"center\">" 
$paid "</td>
        <td align=\"center\">" 
date('Y-d-m',strtotime($list['due'])) . "</td>
        <td align=\"right\">$" 
$list['amount'] . "</td>
        <td align=\"left\">" 
$cat[$list['category']-1]['name'] . "</td>
        <td align=\"left\">" 
$list['comment'] . "</td>
      </tr>\n"
;


Last edited by Triple_Nothing : December 7th, 2012 at 09:55 AM.

Reply With Quote
  #2  
Old December 7th, 2012, 09:59 AM
aeternus's Avatar
aeternus aeternus is offline
For POny!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Location: Amsterdam
Posts: 416 aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 5 Days 4 h 56 m 43 sec
Reputation Power: 114
change your code to this
PHP Code:
if($list['paid'] == "1") { $paid "X"; } else { $paid ""; } 

notice the double ==

You used a single one, which pretty much assigns the value of 1, making all loops true.

Btw if this value is sored as an integer (which I would recommend) You don't need quotes around the 1
__________________
PHP Tutorial

Last edited by aeternus : December 7th, 2012 at 10:02 AM.

Reply With Quote
  #3  
Old December 7th, 2012, 10:02 AM
Aurum84 Aurum84 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 74 Aurum84 User rank is Sergeant (500 - 2000 Reputation Level)Aurum84 User rank is Sergeant (500 - 2000 Reputation Level)Aurum84 User rank is Sergeant (500 - 2000 Reputation Level)Aurum84 User rank is Sergeant (500 - 2000 Reputation Level)Aurum84 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 23 h 5 m 49 sec
Reputation Power: 17
Change:

PHP Code:
if($list['paid'] = "1"


to

PHP Code:
if($list['paid'] == "1"


edit: beaten bij Aeturnus

Reply With Quote
  #4  
Old December 7th, 2012, 10:06 AM
Triple_Nothing Triple_Nothing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 313 Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 15 h 8 m 35 sec
Reputation Power: 5
Yep. It's still morning... The quotes weren't intended, just a troubleshootin thought. Thanks for pointin out the double equal signs.
Comments on this post
aeternus agrees: Wield the power of coffee

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > If/then written right?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap