20 Replies Latest reply: Oct 13, 2014 2:23 PM by Max Resnikoff RSS

    How to display image if field value= 'value'

    Max Resnikoff Community Member

      hi,

       

      how would I go about setting up a table cell which will display a tick if the user has paid, and an x if the user has not yet paid?

       

      In my database I have the field: payment.

      In the php code I have it set up so that values 0=not paid and 1=paid

       

      Thank you!

        • 1. Re: How to display image if field value= 'value'
          TwoSuits Community Member

          If I understand you question correctly, you just need a PHP If statement inside the cell. Assuming you have a recordset from your database (if not just change the variable as necessary) it would look something like this:

           

          <table>

            <tr>

              <td>Invoice Paid:</td>

              <td>

          <?php If ($yourRecodset['payment']==0) { ?>

              <img src="notpaid.jpg"/>

          <?php } else { ?>

              <img src="paid.jpg"/>

          <?php }?>

              </td>

            </tr>

          </table>

           

          (this assumes that the value can only be 0 or 1. If that is not the case, the Else should be replaced with another If)

           

          Hope this helps

           

          Scott

          • 2. Re: How to display image if field value= 'value'
            Max Resnikoff Community Member

            Thanks,

             

            This is what I have:

             

            <?php echo $row_clientinfo['paymentstatus']; ?>

            <?php if ($clientinfo['paymentstatus']==0) { ?>

            <img src="../../images/notpaid.png" width="100" height="50" />

            <?php if ($clientinfo['paymentstatus']==4) { ?>

            <img src="../../images/paid.png" width="100" height="50" />

            <?php }}?>

             

            But it doesnt seem to change if the value is 4.

            Is there something im missing?

             

            I have the field echoed on the page and it displays the right number, so it isnt something to do with the database.

            • 3. Re: How to display image if field value= 'value'
              TwoSuits Community Member

              You have nested your 'if ($clientinfo['paymentstatus']==4) {' statement inside your 'if ($clientinfo['paymentstatus']==0) {' statement. This means that the condition 4 code will never be seen as that block is only run when the value is 0.

               

              It should read:

               

              <?php echo $row_clientinfo['paymentstatus']; ?>

              <?php if ($clientinfo['paymentstatus']==0) { ?>

              <img src="../../images/notpaid.png" width="100" height="50" />

              <?php }?>

              <?php if ($clientinfo['paymentstatus']==4) { ?>

              <img src="../../images/paid.png" width="100" height="50" />

              <?php }?>

               

              Notice the first if statement is closed before the second is reached.

               

              Scott

              • 4. Re: How to display image if field value= 'value'
                MurraySummers CommunityMVP

                Is there something im missing?

                 

                 

                Yes - you have improperly (or inadvertently) nested your conditional tests -

                 

                <?php echo $row_clientinfo['paymentstatus']; ?>

                <?php if ($clientinfo['paymentstatus']==0) { ?>

                <img src="../../images/notpaid.png" width="100" height="50" />

                <?php } ?>

                <?php if ($clientinfo['paymentstatus']==4) { ?>

                <img src="../../images/paid.png" width="100" height="50" />

                <?php }?>

                 

                The way you had it written, the only time you would test to see if the value is 4 would be if the value==0 test SUCCEEDED.

                • 5. Re: How to display image if field value= 'value'
                  Max Resnikoff Community Member

                  It is still not working even with your code :/

                   

                  The first set for the not paid code is working. If i change the 0 to 1, it dissapears.

                  The second set doesnt want to work even if i change the equal to:1

                   

                  Capture.JPGCapture1.JPG

                  • 6. Re: How to display image if field value= 'value'
                    osgood_ CommunityMVP

                    Max Resnikoff wrote:

                     

                    It is still not working even with your code :/

                     

                    The first set for the not paid code is working. If i change the 0 to 1, it dissapears.

                    The second set doesnt want to work even if i change the equal to:1

                     

                    Capture.JPGCapture1.JPG

                    Try:

                     

                    <?php echo $row_clientinfo['paymentstatus']; ?>

                    <?php if ($clientinfo['paymentstatus']==0) { ?>

                    <img src="../../images/notpaid.png" width="100" height="50" />

                    <?php } ?>

                    <?php if ($clientinfo['paymentstatus']==4) { ?>

                    <img src="../../images/paid.png" width="100" height="50" />

                    <?php } ?>

                     

                    Should work if you database is set to 0 and 4 respectively/

                    • 7. Re: How to display image if field value= 'value'
                      TwoSuits Community Member

                      As the code in your last post stands, the only way the paid image will display is if the value is set to 4. If you want it to work with 0 and 1, where 1 is paid, you need to change

                       

                      <?php if ($clientinfo['paymentstatus']==4) { ?>

                       

                      to

                       

                      <?php if ($clientinfo['paymentstatus']==1) { ?>

                      • 8. Re: How to display image if field value= 'value'
                        MurraySummers CommunityMVP

                        Os, I don't think we are getting through...

                        • 9. Re: How to display image if field value= 'value'
                          osgood_ CommunityMVP

                          Infact you probably only need to test for NOT paid and just print paid if it doesnt meet the condition:

                           

                          <?php echo $row_clientinfo['paymentstatus']; ?>

                          <?php if ($clientinfo['paymentstatus']==0) { ?>

                          <img src="../../images/notpaid.png" width="100" height="50" />

                          <?php } 

                          else { ?>

                          <img src="../../images/paid.png" width="100" height="50" />

                          <?php } ?>

                          • 10. Re: How to display image if field value= 'value'
                            osgood_ CommunityMVP

                            MurraySummers wrote:

                             

                            Os, I don't think we are getting through...

                             

                            I hear ya Murray, how you doing? Not seen you around in a while - been busy?

                            • 11. Re: How to display image if field value= 'value'
                              TwoSuits Community Member

                              Can you guys (MurraySummers and osgood_) even see my replies? You seem to be repeating my answers. Your last is essentially the same as my original answer to the OP and the others are verbatim code to my second reply (apart from whitespace). If wires are crossing during posting then fine but you guys just seem to not even see/acknowledge my responses?

                              • 12. Re: How to display image if field value= 'value'
                                MurraySummers CommunityMVP

                                Sorry I omitted you. Indeed your initial answer is correct.

                                • 13. Re: How to display image if field value= 'value'
                                  MurraySummers CommunityMVP

                                  Yes - comes in waves, you know?

                                  • 14. Re: How to display image if field value= 'value'
                                    Max Resnikoff Community Member

                                    I found the issue:

                                     

                                    The variable was the problem.

                                     

                                    Instead of this:

                                    <?php if ($clientinfo['paymentstatus']==0) { ?>

                                    <img src="../../images/notpaid.png" width="100" height="50" />

                                    <?php } ?>

                                    <?php if ($clientinfo['paymentstatus']==4) { ?>

                                    <img src="../../images/paid.png" width="100" height="50" />

                                    <?php } ?>

                                     

                                    I put this:

                                     

                                    <?php $paymentstatus = $row_clientinfo['paymentstatus']; ?>

                                     

                                    <?php if ($paymentstatus ==0) { ?>

                                    <img src="../../images/notpaid.png" width="100" height="50" />

                                    <?php } ?>

                                    <?php if ($paymentstatus ==1) { ?>

                                    <img src="../../images/paid.png" width="100" height="50" />

                                    <?php } ?>

                                    • 15. Re: How to display image if field value= 'value'
                                      TwoSuits Community Member

                                      The variable is not the issue. The top one contains:

                                       

                                      <?php if ($clientinfo['paymentstatus']==4) { ?>

                                       

                                      whereas the bottom one contains:

                                       

                                      <?php if ($clientinfo['paymentstatus']==1) { ?>

                                       

                                      The reason it doesn't work is because the top version is looking for a value of  4 which does not exist!

                                      • 16. Re: Re: How to display image if field value= 'value'
                                        TwoSuits Community Member

                                        Max Resnikoff wrote:

                                         

                                        I found the issue:

                                         

                                        The variable was the problem.

                                         

                                        Instead of this:

                                        <?php if ($clientinfo['paymentstatus']==0) { ?>

                                        <img src="../../images/notpaid.png" width="100" height="50" />

                                        <?php } ?>

                                        <?php if ($clientinfo['paymentstatus']==4) { ?>

                                        <img src="../../images/paid.png" width="100" height="50" />

                                        <?php } ?>

                                         

                                        I put this:

                                         

                                        <?php $paymentstatus = $row_clientinfo['paymentstatus']; ?>

                                         

                                        <?php if ($paymentstatus ==0) { ?>

                                        <img src="../../images/notpaid.png" width="100" height="50" />

                                        <?php } ?>

                                        <?php if ($paymentstatus ==1) { ?>

                                        <img src="../../images/paid.png" width="100" height="50" />

                                        <?php } ?>

                                        Do you see the problem?

                                        • 17. Re: How to display image if field value= 'value'
                                          osgood_ CommunityMVP

                                          Max Resnikoff wrote:

                                           

                                          I found the issue:

                                           

                                          The variable was the problem.

                                           

                                          Instead of this:

                                          <?php if ($clientinfo['paymentstatus']==0) { ?>

                                          <img src="../../images/notpaid.png" width="100" height="50" />

                                          <?php } ?>

                                          <?php if ($clientinfo['paymentstatus']==4) { ?>

                                          <img src="../../images/paid.png" width="100" height="50" />

                                          <?php } ?>

                                           

                                          I put this:

                                           

                                          <?php $paymentstatus = $row_clientinfo['paymentstatus']; ?>

                                           

                                          <?php if ($paymentstatus ==0) { ?>

                                          <img src="../../images/notpaid.png" width="100" height="50" />

                                          <?php } ?>

                                          <?php if ($paymentstatus ==1) { ?>

                                          <img src="../../images/paid.png" width="100" height="50" />

                                          <?php } ?>

                                           

                                          The reason it doesn't work is because the top version is looking for a value of  4 which does not exist!

                                           

                                          Sorry TwoSuits - just winding you up - no offense meant - wasn't ignoring your replies, just thought maybe the OP wasn't understanding so just really reinforcing what you wrote.

                                          • 18. Re: How to display image if field value= 'value'
                                            osgood_ CommunityMVP

                                            MurraySummers wrote:

                                             

                                            Yes - comes in waves, you know?

                                             

                                            Yeah, same here. All or nothing.

                                            • 19. Re: How to display image if field value= 'value'
                                              Max Resnikoff Community Member

                                              I changed it. I only put 4 just to test it to see if it would work with 4!

                                              • 20. Re: Re: How to display image if field value= 'value'
                                                TwoSuits Community Member

                                                You do realise that the extra variable ($paymentstatus) is not required and that the below code will work exactly the same?

                                                 

                                                <?php if ($row_clientinfo['paymentstatus'] ==0) { ?>

                                                <img src="../../images/notpaid.png" width="100" height="50" />

                                                <?php } ?>

                                                <?php if ($row_clientinfo['paymentstatus'] ==1) { ?>

                                                <img src="../../images/paid.png" width="100" height="50" />

                                                <?php } ?>

                                                 

                                                Oh, and by the way - YOU'RE WELCOME!

                                                • 21. Re: Re: How to display image if field value= 'value'
                                                  Max Resnikoff Community Member

                                                  Well it didnt work with me. As soon as I changed it to a variable it worked.