Filtering Empty Array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bananahead
    New Member
    • Aug 2008
    • 9

    Filtering Empty Array

    Hello,

    Im a noob when it comes to php, and Im trying to figure out how to work out a code that will allow me to filter out an array.

    Basically, I have a system to assign offers to my clients and I have a page that is used to assign offers. Once all offers are assigned to a client, I dont want the form to be displayed anymore, but i cant get it work. here is the code:

    [PHP]$html .= "<div style='backgrou nd-image:url(image s/gradientdiv.gif ); height:26px;'>$ row[firstname] $row[lastname](<a href=\"javascri pt:showDiv('div $member_id');\" style='color:bl ue;'>Assign Offers</a>)</div> <div id='div$member_ id' style='display: none; background-color:#FFFFD9;' >"; $sql_select_off ers = "select o.offer_id, o.offer_name from offers o where not exists (select * from members_offers inner join offers on members_offers. offer_id = offers.offer_id where members_offers. member_id = $member_id and o.offer_id = offers.offer_id )"; $result_set_off ers = mysql_query($sq l_select_offers ); $html .= '<form action="assign_ offers.php">Che ck to Assign:<br />'; $html .= "<input type='hidden' name='member_id ' value='$member_ id' />"; while($row = mysql_fetch_arr ay($result_set_ offers)) { $html .= "<input type='checkbox' name='$row[offer_id]' value='$row[offer_id]' />$row[offer_name]<br />"; } $html .= "<input type='submit' value='Save' /></form></div>"; }[/PHP]


    The code works fine, but it retrieves all users from the DB, and even those that have all offers already assigned to them, so basically I end up having a <div> tag with only "check to assign" and the save button in it. How can I hide those records that have offers all assigned already?

    Thanks a bunch!!!
    Last edited by Atli; Aug 1 '08, 08:22 PM. Reason: Cleaned up the title
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    Your code is not clean.

    But let me understand what you're trying to do first.

    You display a page with check boxes.

    User checks whatever checkbox they like.

    You store that in the database.

    Then the user should be directed to another page?


    Am I warm?


    Let us know,


    Dan

    Comment

    • bananahead
      New Member
      • Aug 2008
      • 9

      #3
      Sorry for the code, I pasted and tried to fix it, but it came up like that
      [code=php]
      <?php

      include 'includes/conecta.php';

      $sql_select = "select member_id, firstname, lastname
      from members";

      $result_set = mysql_query($sq l_select);

      $html = '';

      while($row = mysql_fetch_arr ay($result_set) ) {

      $member_id = $row['member_id'];
      $html .= "<div style='backgrou nd-image:url(image s/gradientdiv.gif ); height:26px;'>$ row[firstname] $row[lastname](<a href=\"javascri pt:showDiv('div $member_id');\"
      style='color:bl ue;'>Assign Offers</a>)</div>
      <div id='div$member_ id' style='display: none; background-color:#FFFFD9;' >";
      $sql_select_off ers = "select o.offer_id, o.offer_name
      from offers o
      where not exists (select *
      from members_offers inner join offers
      on members_offers. offer_id = offers.offer_id
      where members_offers. member_id = $member_id
      and o.offer_id = offers.offer_id )";
      $result_set_off ers = mysql_query($sq l_select_offers );


      $html .= "<form action='assign_ offers.php'>Che ck to Assign: <input type='checkbox' name='checkall' onclick=\"check UncheckAll(this );\"/><br />";
      $html .= "<input type='hidden' name='member_id ' value='$member_ id' />";

      while($row = mysql_fetch_arr ay($result_set_ offers)) {
      $html .= "<input type='checkbox' name='$row[offer_id]' value='$row[offer_id]' />
      $row[offer_name]<br />";
      }
      $html .= "<input type='submit' value='Save' /></form></div>";

      }

      ?>
      [/code]

      I have a contorl panel for my employess to feed customer data into it. Part of the process is to select offers that will be assigned to that customer. They do it by checking the checkboxes and that flags them as assigned to that customer.

      The problem is that with the code above,( which lists all customers and a div where the checkboxes are to be checked) is that if I check all the checkboxes for each one of the customers returned from the database, after I assign all offers, the div will still be generated, but since the offers are marked as assigned already, they wont show on the div, but the form tag still exists. I want to able to hide that once a customer gets all offers assigned to him.

      I think I made a bit more clear now :)
      Last edited by Atli; Aug 1 '08, 08:23 PM. Reason: Added [code] tags

      Comment

      Working...