473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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='background-image:url(images/gradientdiv.gif); height:26px;'>$row[firstname] $row[lastname](<a href=\"javascript:showDiv('div$member_id');\" style='color:blue;'>Assign Offers</a>)</div> <div id='div$member_id' style='display:none; background-color:#FFFFD9;'>"; $sql_select_offers = "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_offers = mysql_query($sql_select_offers); $html .= '<form action="assign_offers.php">Check to Assign:<br />'; $html .= "<input type='hidden' name='member_id' value='$member_id' />"; while($row = mysql_fetch_array($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!!!
Aug 1 '08 #1
2 1076
dlite922
1,584 Expert 1GB
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
Aug 1 '08 #2
Sorry for the code, I pasted and tried to fix it, but it came up like that
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.     include 'includes/conecta.php';
  4.  
  5.     $sql_select = "select member_id, firstname, lastname 
  6.                     from members";
  7.  
  8.     $result_set = mysql_query($sql_select);
  9.  
  10.     $html = '';
  11.  
  12.     while($row = mysql_fetch_array($result_set)) {
  13.  
  14.         $member_id = $row['member_id'];
  15.         $html .= "<div style='background-image:url(images/gradientdiv.gif); height:26px;'>$row[firstname] $row[lastname](<a href=\"javascript:showDiv('div$member_id');\" 
  16.                     style='color:blue;'>Assign Offers</a>)</div>
  17.                     <div id='div$member_id' style='display:none; background-color:#FFFFD9;'>";
  18.         $sql_select_offers = "select o.offer_id, o.offer_name
  19.                                 from offers o 
  20.                                 where not exists (select *
  21.                                 from members_offers inner join offers 
  22.                                     on members_offers.offer_id = offers.offer_id
  23.                                 where members_offers.member_id = $member_id
  24.                                     and o.offer_id = offers.offer_id)";
  25.         $result_set_offers = mysql_query($sql_select_offers);
  26.  
  27.  
  28.         $html .= "<form action='assign_offers.php'>Check to Assign: <input type='checkbox' name='checkall' onclick=\"checkUncheckAll(this);\"/><br />";
  29.         $html .= "<input type='hidden' name='member_id' value='$member_id' />";
  30.  
  31.         while($row = mysql_fetch_array($result_set_offers)) {        
  32.             $html .= "<input type='checkbox' name='$row[offer_id]' value='$row[offer_id]' />
  33.                         $row[offer_name]<br />";
  34.         }
  35.         $html .= "<input type='submit' value='Save' /></form></div>";
  36.  
  37.     }
  38.  
  39. ?>
  40.  
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 :)
Aug 1 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: William Park | last post by:
1. Here is shell version of Python filter() for array. Essentially, you apply a command on each array element, and extract only those elements which it returns success (0). This is specialized...
3
by: Alex Ayzin | last post by:
Hi, I have a problem that might be easy to solve(possibly, I've just overlooked an easy solution). Here we go: I have a dataset with 2 datatables in it. Now, I need to do the following: if...
13
by: kevinold | last post by:
Hello everyone, I have a list of about 1600 employees that I'd like to have displayed in a form. I'd like to make the "search" for the user as easy as possible. I ran across this:...
3
by: MattB | last post by:
I have a RadioButtonList then binds to a DataTable in my Web Form. The DataTextField is called "descrip" and I want to bind only records that don;t have an empty descrip field. My initial...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
2
by: Bob Stearns | last post by:
I thought that the given expression was always TRUE if "not_there" wasn't among the keys (or subscripts if you will) of $_SESSION. Below find a dump of $_SESSION, a small snippet of code and the...
0
by: Romulo NF | last post by:
Greetings again everyone Recently i´ve been asked to develop a script to allow filtering in the content of the table, with dinamic options based on the own content. Example: a table with the name of...
3
by: Krish | last post by:
Hi All, I have a component that reads a file and returns the data as a an array of objects. Now I want to add the capability of filtering on this. This means if an array of objects is returned...
1
by: G04 | last post by:
Hi All, I have a continuous form with all records. For each field there is a combo in the form header and the form also contains a Toggle button "Apply Filter". When clicked, it changes to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.