If statement

  • jordonshaw
  • Student
  • Student
  • User avatar
  • Posts: 96
  • Loc: Tennessee

Post 3+ Months Ago

For some reason I'm having an off day and can't figure this out to save my life. Here is my code:

PHP Code: [ Select ]
<?php
$course_set = mssql_query("SELECT * FROM SNP_crsunits WHERE crs_id = '{$course1['crs_id']}'", $connection);
        while ($course = mssql_fetch_array($course_set)) {
            if ($course['edit_av']=='1') {
                $edit_av = '#A9F5A9';
            };
           
        echo "
           <tr>
           <td>{$course['unit']}</td>
           <td>&nbsp;<input type=\"text\" name=\"a_name\" value=\"{$course['unit_title']}\" /></td>
           <td>&nbsp;</td>            
           <td align=\"center\" bgcolor=\"{$edit_av}\">&nbsp;" . str_replace("1", "X", ($course['edit_av'])) . " </td>
           </tr>"
?>
  1. <?php
  2. $course_set = mssql_query("SELECT * FROM SNP_crsunits WHERE crs_id = '{$course1['crs_id']}'", $connection);
  3.         while ($course = mssql_fetch_array($course_set)) {
  4.             if ($course['edit_av']=='1') {
  5.                 $edit_av = '#A9F5A9';
  6.             };
  7.            
  8.         echo "
  9.            <tr>
  10.            <td>{$course['unit']}</td>
  11.            <td>&nbsp;<input type=\"text\" name=\"a_name\" value=\"{$course['unit_title']}\" /></td>
  12.            <td>&nbsp;</td>            
  13.            <td align=\"center\" bgcolor=\"{$edit_av}\">&nbsp;" . str_replace("1", "X", ($course['edit_av'])) . " </td>
  14.            </tr>"
  15. ?>


So, basically when it does the loop, it should only change the background of the cell if edit_av = 1; however, if I have 8 units and 3 should be colored, it's making all of the backgrounds colored.
Moderator Remark: Changed [code] tags to [php] to enable highlighting
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8416
  • Loc: USA

Post 3+ Months Ago

Change the top to the following... The changed codes is noted in the code

PHP Code: [ Select ]
<?php
$course_set = mssql_query("SELECT * FROM SNP_crsunits WHERE crs_id = '{$course1['crs_id']}'", $connection);
        while ($course = mssql_fetch_array($course_set)) {
            $edit_av = '#FFFFFF';  // This has being added
            if ($course['edit_av']=='1') {
                $edit_av = '#A9F5A9';
            }
           
        echo "
           <tr>
           <td>{$course['unit']}</td>
           <td>&nbsp;<input type=\"text\" name=\"a_name\" value=\"{$course['unit_title']}\" /></td>
           <td>&nbsp;</td>            
           <td align=\"center\" bgcolor=\"{$edit_av}\">&nbsp;" . str_replace("1", "X", ($course['edit_av'])) . " </td>
           </tr>"
?>
  1. <?php
  2. $course_set = mssql_query("SELECT * FROM SNP_crsunits WHERE crs_id = '{$course1['crs_id']}'", $connection);
  3.         while ($course = mssql_fetch_array($course_set)) {
  4.             $edit_av = '#FFFFFF';  // This has being added
  5.             if ($course['edit_av']=='1') {
  6.                 $edit_av = '#A9F5A9';
  7.             }
  8.            
  9.         echo "
  10.            <tr>
  11.            <td>{$course['unit']}</td>
  12.            <td>&nbsp;<input type=\"text\" name=\"a_name\" value=\"{$course['unit_title']}\" /></td>
  13.            <td>&nbsp;</td>            
  14.            <td align=\"center\" bgcolor=\"{$edit_av}\">&nbsp;" . str_replace("1", "X", ($course['edit_av'])) . " </td>
  15.            </tr>"
  16. ?>
  • jordonshaw
  • Student
  • Student
  • User avatar
  • Posts: 96
  • Loc: Tennessee

Post 3+ Months Ago

Worked perfectly! Thanks!
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8416
  • Loc: USA

Post 3+ Months Ago

Yup :D Any time*






* When I'm online, in the mood, understanding your problem, know the answer, have the time, and eager to help.

:lol:
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

Nice disclaimer. We might have to borrow this and make it a permanent definition of 'any time' at Ozzu. :lol:
  • jordonshaw
  • Student
  • Student
  • User avatar
  • Posts: 96
  • Loc: Tennessee

Post 3+ Months Ago

Bogey,

Can you take a look at this and see if you can offer any help. I'm really hung up on it:

programming-forum/post-from-query-t101805.html

Thanks!
Jordon
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8416
  • Loc: USA

Post 3+ Months Ago

UPSGuy wrote:
Nice disclaimer. We might have to borrow this and make it a permanent definition of 'any time' at Ozzu. :lol:

Go ahead :D Glad you liked it :)
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8416
  • Loc: USA

Post 3+ Months Ago

jordonshaw wrote:
Bogey,

Can you take a look at this and see if you can offer any help. I'm really hung up on it:

programming-forum/post-from-query-t101805.html

Thanks!
Jordon

I'll take a look at it at as soon as I can
  • jordonshaw
  • Student
  • Student
  • User avatar
  • Posts: 96
  • Loc: Tennessee

Post 3+ Months Ago

Thanks Bogey; however, I had somebody look at it today, so I'm good! I'll post a solution to that thread shortly, for everybody else can see.

Thanks,
Jordon
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8416
  • Loc: USA

Post 3+ Months Ago

Oh, ok then. Glad you got it worked out.

Post Information

  • Total Posts in this topic: 10 posts
  • Users browsing this forum: No registered users and 53 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.