Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

Filtering drop-down data from mySQLHow will you know the selected items of the user?

I need help figuring out the problem with my code, I want to filter the category drop-down list based on the logged in user, so if they have already selected a category and entered the rest of the details in the form, that selected category should not appear in the drop-down list for that logged in user, whereas it should be a full list if a new user registers.

Please see the code attachment.
SQL
#######
<?php 
$query_bach = "SELECT * FROM bachelor ORDER BY bid";
$query_type = mysql_query($query_bach);
$query_rows = mysql_fetch_assoc($query_type);
?>
 
 
 
FORM
########
<form action="" method="post" id="done">
<select name="bid" id="email_field">
<?php 
$Previously_Selected_Items = $_SESSION['bid']; //this is where the selected item goes
 
while($query_rows = mysql_fetch_assoc($query_type))
{
   $foo = 0;
   for($i=0; $i<count($Previously_Selected_Items); $i++)
  {
   
   if($Previously_Selected_Items[$i] == $query_rows['bid'])
      {
          $foo = 1;
      }
 
   }
 
   if($foo == 0)
   {
  echo "<option value=\"".$query_rows['bid']."\">".$query_rows['btitle']."</option>";
   }
}
?>
</select>
<input type="submit" class="submit5" name="Submit1" value="Start Application">
</form>

Open in new window

0
ostrox
Asked:
ostrox
  • 48
  • 31
1 Solution
 
DavidSingletonCommented:
if i understand you right, you've missplaced your if statement

while($query_rows = mysql_fetch_assoc($query_type))
{
   $foo = 0;
   for($i=0; $i<count($Previously_Selected_Items); $i++)
  {
   
   if($Previously_Selected_Items[$i] == $query_rows['bid'])
      {
          $foo = 1;
      }
  else
   {
  echo "<option value=\"".$query_rows['bid']."\">".$query_rows['btitle']."</option>";
   }
 
   }
 
 
}
?>
</select>
<input type="submit" class="submit5" name="Submit1" value="Start Application">
</form>

Open in new window

0
 
ostroxAuthor Commented:
I don't know where the problem is, the if statement seems alright!
0
 
ostroxAuthor Commented:
I don't know where the problem is, the if statement seems alright!
0
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 
DavidSingletonCommented:
Ok perhaps I misunderstood what you were wanting.  I have a question for you though. Why are you looping through an array and not just searching the values of it?
while($query_rows = mysql_fetch_assoc($query_type))
{
   $foo = 0;
   if(in_array($query_rows['bid'], $Previously_Selected_Items))
    {
      $foo = 1;
    }
    if($foo == 0)
    {
      echo '<option value="' . $query_rows['bid'] . '">' . $query_rows['btitle'] . '</option>';
    }
}

Open in new window

0
 
ostroxAuthor Commented:
Because there a few items in that table and there is a option for admins to add and remove items from the table, so if i loop through it i get all entries available.
0
 
DavidSingletonCommented:
The code I posted will still look through the previously selected items just like yours did, its just more efficient.
0
 
ostroxAuthor Commented:
Still doesn't answer my first question though!?
0
 
DavidSingletonCommented:
If you run my code does it still not work for you?  Also what is it actually doing?  Does it just print out every option no matter what?  does the value in Previously selected items contain the EXACT same value as that in bid?  
0
 
ostroxAuthor Commented:
The code you provided works fine, just refined version of the code i already had working, and it basically prints no matter what as you say, so even though i have category A selected and inserted already for the currently logged in user, it's still appears in the drop-down list, which it should and that's what i'm login for!
0
 
DavidSingletonCommented:
what do you see when you print_r the previously selected, does the previously selected array contain the bid or the btitle.  I'm just asking because the code looks solid, i see no reason you should still be getting those unless the values aren't matching.
0
 
ostroxAuthor Commented:
Well I the code is solid for the display of the drop-down list, however I think my SQL needs to be modified, but i'm not sure, because how would the code know if the user who previously choose item a and logs out, and when they log back in that item should not be available to them (based on their email address, is what i'm going for).
0
 
DavidSingletonCommented:
ah i see, and your storing what they chose before in a session, which means when they log out or quit their browser their session is probably destroyed.  Well, there are a couple of things you could do here:

1.  Store it in your database, when they select it, just store it with a reference to the user, when they log in pull that field into your session variable.

2.  Write the data to a cookie.  I of course don't recommend this with any sensitive data, but you'll have to decide weather if someone sees this list it would compromise your site or not.
0
 
ostroxAuthor Commented:
Yes, that's right, but I already have the values in the database, the drop-down field values i have stored in a table and the users in a separate table and a main table where i get the values via sessions and add it to the main table, using LEFT JOIN i get all the fields i need.

Where would I add that reference, to what table? and How would I get that value back again with PHP?
0
 
DavidSingletonCommented:
Well, you could just simply add a comma separated list to your users table and throw it into an array when you pull it from php.

However, its generally considered bad practice to combine table uses like that.  It would probably be better to have a separate table for user options and such and store it in there.  

Either way will work for you through.
0
 
ostroxAuthor Commented:
Hey DavidSingleton, sorry for the late reply, umm how do you do that, add a comma to the users table exactly, do i add a new column to the users table or would this be easily created using a lookup table?
0
 
ostroxAuthor Commented:
Hi sorry to be asking so meny questions but i really need to figure this out, hopefully more replies would be good.
0
 
DavidSingletonCommented:
yeah just add a varchar field to the table the values you'll put in it will be comma separated.
0
 
ostroxAuthor Commented:
In what table exactly, do I add it too my members table or to my main table, i store all the drop-down items from two different tables and add their values to the main table, I don't really understand what you mean by comma seperated, where will they be seperated by commas, sorry i'm not good with sql.
0
 
ostroxAuthor Commented:
Anyone any further help, i don't understand your answer David!
0
 
DavidSingletonCommented:
It's not really sql.  Add a field in your members table that is a varchar field.  Since you need to track which items each Member selects, that is where you would want to put it.

Then, when they log in or whatever, pull from that field, and throw the value into your session variable.  When they select another item, update your session variable and that field in the members table with all the items they have selected.  The value in the actual table should look like: selection1,selection2,selection3  that is what i meant by comma separated.
0
 
ostroxAuthor Commented:
Alright I think i get it, but just so I'm sure, I currently collect the field values from a mysql table and store within a session variable pass that variable along to another page where they are inserted into another mysql table, now i should add an additional field so that same value is added to the members field and get the values from there instead right!?
0
 
DavidSingletonCommented:
the values in the members field will only show items that said member has actually selected.  Your getting all your values now fine, the problem is your not storing any of the variables that the user actually selects.  That is what goes into the members table.
0
 
ostroxAuthor Commented:
Alright thanks i will let you know soon how it worked out! thanks again for you reply!
0
 
ostroxAuthor Commented:
Alright I got it working, however i still need some help.  I'm using the code below, which works well and adds the category id into the members id, however how would i add the same for the the second drop-down category within this sql statement? and I'm using the following sql query but i'm not getting the desired result can you see what's wrong with it?

SELECT bid,  btitle, to_date, cats FROM bachelor, members WHERE cats ='$cid' ORDER BY bid ASC

Basically I want to get all the categories within the bachelor table to appear in a drop-down list and if a user has already select a value it's inserted in the cats field within the members table which based on the above cateogry would remove it from the drop down list as a possible selected items for a second application.
$id = $_SESSION['id'];
$ana = "UPDATE members SET 
cats = '".$_SESSION['bid']."'
WHERE id='$id'";

Open in new window

0
 
ostroxAuthor Commented:
Any input?
0
 
ostroxAuthor Commented:
Here's what I've changed around:

<?php
$Previously_Selected_Items = $_SESSION['cats'];

while($query_rows = mysql_fetch_assoc($query_type))
{
   $foo = 0;
   for($i=0; $i<count($Previously_Selected_Items); $i++)
  {

   if($Previously_Selected_Items[$i] == $query_rows['bid'])
      {
          $foo = 1;
      }
   }
 
if($foo == 0)
   {
  echo "<option value=\"".$query_rows['bid']."\">".$query_rows['btitle']."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>Programme Deadline:</strong>&nbsp;".$query_rows['to_date']."</option>";
      }
       
  }
?>
<?php 
$diz = $_SESSION['id'];
$query_bachs = "SELECT * FROM members WHERE id='$idz'";
$query_types = mysql_query($query_bachs);
$query_rowss = mysql_fetch_assoc($query_types);
 
$query_rowss['cats'] = $Previously_Selected_Items;
?>
 
<?php 
$query_bach = "SELECT * FROM bachelor ORDER BY bid ASC";
$query_type = mysql_query($query_bach);
$query_rows = mysql_fetch_assoc($query_type);
?>

Open in new window

0
 
ostroxAuthor Commented:
Actually it works they way I have it, well sort of, it works in Firefox only I don't know why? But regarding you answer: The value in the actual table should look like: selection1,selection2,selection3  that is what i meant by comma separated.

Using the update statement, how would i change that to make it work like you said, I can't get it to insert a comma after each insert, by the way i'm inserting the id of the category is that right?
0
 
ostroxAuthor Commented:
Actually it works they way I have it, well sort of, it works in Firefox only I don't know why? But regarding you answer: The value in the actual table should look like: selection1,selection2,selection3  that is what i meant by comma separated.

Using the update statement, how would i change that to make it work like you said, I can't get it to insert a comma after each insert, by the way i'm inserting the id of the category is that right?
0
 
DavidSingletonCommented:
you would use a concat to update the member something like:
update tblname set field = concat(field, ", ", newvalue) where memberid = id

Open in new window

0
 
ostroxAuthor Commented:
I've made like this, however what is supposed to be in the new value part of your code?!

$field_cat = $_SESSION['mid'];
 
$sql= "UPDATE members SET cats = concat($field_cat, ", ", newvalue) WHERE id=".$_SESSION['id'];

Open in new window

0
 
DavidSingletonCommented:
whatever they just selected.  $field_cat should actually just be the name of the field that already holds your data.  What your doing is combining the current data in the field with the new data, or if when they select an item you add it to the session variable you could just do:

update members set cats = $field_cat where id = userid
0
 
ostroxAuthor Commented:
Ok I'm using this code see blow.

But none the less, even if i input the values myself using commas, i'm still not able to get the function on the main page to work, so that if all values found in the members table (cats field) are equal to the id values of those in the bachelor table they should disappear from the list.

 $ba = $_SESSION['bid'];
 
$ana = "UPDATE members SET 
cats = concat(cats, ", ",$ba)
WHERE id=".$_SESSION['id'];

Open in new window

0
 
ostroxAuthor Commented:
Here's the code i'm using to populate the drop-down field:


<form action="" method="post" id="done">
<select name="bid" id="field">
<?php
$Previously_Selected_Items = $catsz;

while($query_rows = mysql_fetch_assoc($query_type))
{
   $foo = 0;
   for($i=0; $i<count($Previously_Selected_Items); $i++)
  {

   if($Previously_Selected_Items[$i] == $query_rows['bid'])
      {
          $foo = 1;
      }
   }
 
if($foo == 0)
   {
  echo "<option value=\"".$query_rows['bid']."\">".$query_rows['btitle']."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>Programme Deadline:</strong>&nbsp;".$query_rows['to_date']."</option>";
      }
       
  }
?>
</select>
<input type="submit" name="Submit" value="Start">
</form>
<?php 
$diz = $_SESSION['id'];
$catsz = $_SESSION['cats'];
$query_bachs = "SELECT * FROM members WHERE id='$idz' AND cats='$catsz'";
$query_types = mysql_query($query_bachs);
$query_rowss = mysql_fetch_assoc($query_types);
 
$query_rowss['cats'] = $query_rowss['cats'];
?>
 
<?php 
$query_bach = "SELECT * FROM bachelor ORDER BY bid ASC";
$query_type = mysql_query($query_bach);
$query_rows = mysql_fetch_assoc($query_type);
?>

Open in new window

0
 
DavidSingletonCommented:
The problem here isn't your code as much as it you don't understand whats going on.  When the user logs in you should be grabbing that field and putting it into your session variable that you check in your main page.

so at login you get your field cats into a variable $cats

then you do this:
$_SESSION['bid'] = explode(",", $cats);

adding that should make your drop down work assuming you have the correct values stored in your database.

The second part of this is when they chose a new option you need to save it to the field so that the next time they log in they can no longer select that same item.
0
 
ostroxAuthor Commented:
When the user logs in it does already grab all the fields, including the cats field which i can see using print_r and get this:
Array ( [id] => 34 [namef] => Allen [namel] => Micheals[email] => amicheals@gmaizl.com [password] => 7c4a8d09ca3762af61e59520943dc26494f8941b [cats] => , 22, 22, 22, 23, 3 [mcats] => )

which i've done using this code:
$sql="SELECT * FROM members WHERE email='$email' and password=sha1('$passwd')";
$result=mysql_query($sql);


$count=mysql_num_rows($result);
 
if ($count==1){
  $result_array = mysql_fetch_assoc($result);
  foreach($result_array as $key => $value)
  $_SESSION[$key] = $value;

This turns all values in my members table into sesion variables :)

Now, where do i add or do i need to add or create this $cats = $_SESSION['cats']; variable? and where do i exactly add $_SESSION['bid'] = explode(",", $cats);
0
 
ostroxAuthor Commented:
I know this must be frustrating dealing with this, because i sense that the answer right in front of me, but i've been up all night looking at this code and doing it around just to get it to work but nothing has worked so far, so if you dont mind just giving me a push towards a working solution i would appreciate it.
0
 
DavidSingletonCommented:
$cats = explode(",", $_SESSION['cats']);

that will put each comma separated entry into an array for your original code to search through.
0
 
ostroxAuthor Commented:
Hi I added your code, but just won't work, i've modified it a little but still it doesn't function, I've echoed the value of $_SESSION['cats']; and it prints the full value as it appears in the database, so i don't know where the problem is, here is the full code for this part.
<select name="bid" id="email_field">
<?php
$ab = $_SESSION['cats'];
$cats = explode(',', $ab);
$Previously_Selected_Items = cats;
 
while($query_rows = mysql_fetch_assoc($query_type))
{
   $foo = 0;
   for($i=0; $i<count($Previously_Selected_Items); $i++)
  {
 
   if($Previously_Selected_Items[$i] == $query_rows['bid'])
      {
          $foo = 1;
      }
   }
 
if($foo == 0)
   {
  echo "<option value=\"".$query_rows['bid']."\">".$query_rows['btitle']."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>Programme Deadline:</strong>&nbsp;".$query_rows['to_date']."</option>";
	}
 	
  }
?>
</select>

Open in new window

0
 
ostroxAuthor Commented:
Alright got it working, so far!

Just as a final question, when i add this value to the members table I'm using the code below, but for some reason, when I add this i also seem to pick the value from my second drop-down menu and inserts it into the same field meant only for the first drop-down list.
$ana = "UPDATE members SET 
 cats = '".$_SESSION['bid']."',
 cats = '".$_SESSION['mid']."'
 WHERE id=".$_SESSION['id'];
 
$anteret = mysql_query($ana) or die(mysql_error()); 	

Open in new window

0
 
ostroxAuthor Commented:
Hey David, How do I insert values into the database, without overwriting the previously added values?
0
 
DavidSingletonCommented:
either by writing all the values back into the database (You did store them in a session variable), or by using the concat statement i gave you above.  concat(fieldname, ",", $nevval)
0
 
ostroxAuthor Commented:
Yes, but how, I've posted the sql statment i currently have but that doesn't work, it just updates the value in the cats field with the newly selected id, i need it to add the id value into the cats field one after the other like: 1, 2, 3, 4, 5 etc
0
 
DavidSingletonCommented:
i just told you, update members set cats = concat(cats, "," newvalues) where id = whatever
0
 
DavidSingletonCommented:
new values would be your mid session variable
0
 
ostroxAuthor Commented:
Oh ok, i just saw that! Work great! and i can use this same code for update, but how would delete work?
0
 
DavidSingletonCommented:
why would you delete a user?
0
 
ostroxAuthor Commented:
No not delete a user, but to delete a selection from the drop-down menu, so if they chose item one but later wish to delete it, they would be able to do so, which they can, but it won't remove the value associated with the entry and the item within the drop-down list they had selected.  I'm using the code below to delete based on checkboxes, how can i add to this so it does what i need it to do?
<?
if(isset($_POST['checkbox'])){
$fshije = implode(',', $_POST['checkbox']);
 
$deletequery = "DELETE FROM main WHERE student_id IN ($fshije)";
mysql_query($deletequery);
}
?>

Open in new window

0
 
DavidSingletonCommented:
never having used this I can't verfiy that it works, but give it a shot.


$rm = 'value to remove';
$update = "update members set cats = replace(cats, $rm . ',', '')";

Open in new window

0
 
ostroxAuthor Commented:
Thanks, I'm having truble when i insert something with the value, everything work fine, except that i have to logout and login back in in order for the value to appear in the drop-down list, should i be refreshnig after insert of something else?
0
 
DavidSingletonCommented:
No, when you add it to the database, also add it to your session variable.  Your session variable is set when you log in thats why it works after you log back in.  Just add it to both the database and your session variable and you'll be fine.

$_SESSION['bid'][] = 'value';

I think that'll do it.
0
 
DavidSingletonCommented:
sorry, thats wrong, that was assuming that your variable was an array it should be:

$_SESSION['bid'] = $_SESSION['bid'] . ',' . $value;
0
 
ostroxAuthor Commented:
Sorry where do i add this to the insert statment or to the results?
0
 
DavidSingletonCommented:
add it in before the update statment
0
 
ostroxAuthor Commented:
None still doesn't work here's the code i'm using:
$wher = $_SESSION['id'];
 
// DRP LIS 1
 
$_SESSION['bid'] = $_SESSION['bid'] . ',' . $value;
$ana = "UPDATE members SET cats = concat(cats, ', ', '$value') WHERE id='$wher'";
$anteret = mysql_query($ana) or die(mysql_error()); 
 
 
// DRP LIS 2
$mbc_array = $_SESSION['mid'];
$mana = "UPDATE members SET mcats = concat(mcats, ', ', '$mbc_array') WHERE id='$wher'";
$manteret = mysql_query($mana) or die(mysql_error()); 
 
header("Location: thank_you.php"); 

Open in new window

0
 
ostroxAuthor Commented:
Hey man, sorry to ask but i have to know this as well, the delete part, i don't know how will that work exactly, this doesn't work
<?php
 
if(isset($_POST['checkbox'])){
$del= implode(',', $_POST['checkbox']);
$deletequery = "UPDATE members SET cats = replace(cats, $del. ',', '')";
mysql_query($deletequery);
}
?>

Open in new window

0
 
DavidSingletonCommented:
that is because $del is an array not a single value.  You need to get the single value that they "unmarked"  You need to be updating and deleting a single value, not the whole array.
0
 
ostroxAuthor Commented:
How?
0
 
DavidSingletonCommented:
$_POST['checkbox'] I assume holds the value that you wish to delete from the array.  thats the single value man.  replace(cats, $del . ',', '')
0
 
ostroxAuthor Commented:
Alright so remove implode(',', ); instead just use $_POST['checkbox'] is that right?

0
 
DavidSingletonCommented:
yes.  Your second update does the same thing, it tries to update with an array.
0
 
ostroxAuthor Commented:
I didnt get this working $_SESSION['bid'] = $_SESSION['bid'] . ',' . $value;

i have to logout and login back in in order for the value to appear in the drop-down list, should i be refreshnig after insert ?
0
 
DavidSingletonCommented:
if you want it to disappear as soon as they select it then yes you'll need to refresh the page.
0
 
ostroxAuthor Commented:
How do you mean refresh it? meta refresh? I want it so that when when the data is entred into the database, which is when the form comes to the final.php file and if all is succesfully added, it's redirected to a thank you page, where a user click on a link that sends them back to the drop-down selection menu, so when they go back, i want to have the drop-down already refreshed with the new values, i hope i'm being clear!?
0
 
DavidSingletonCommented:
if they leave the page and come back it should refresh, and the values they already selected should be gone from the drop down based on the code we have worked out here.  You need to do a bit of debugging to see what the problem is if thats not happening.  Does your database contain the right values when you go back to the drop down page?  What about your session variables?  If you can tell me what the actual problem is, maybe we can figure it out.
0
 
ostroxAuthor Commented:
Can you look at this code tell me why the delete function isn't working? I can't get each ', #' next each title so that it i would know how to delete it.

<?php
if ($_SESSION['email'] == $stu_rows['email']){
do {
do {
?>
<tr>
<td width="26" align="center" valign="middle" bgcolor="#FFFFFF"><? echo $memb_mrows['cats']; ?><input name="checkbox[]" type="checkbox" class="radio" id="checkbox[]" value="<? echo $memb_mrows['cats'] ?>">

</td>
<td width="241" bgcolor="#FFFFFF"><?php if ($stu_rows['btitle'] = $stu_rows['btitle']){$bac =  "<em>Bachelor</em>"; echo $stu_rows['btitle'].'</br>'.$bac; }else{
 echo "";
 }?><?php
 if ($stu_rows['mtitle'] = $stu_rows['mtitle']){
 $mas =  "<em>Master</em>"; echo $stu_rows['mtitle'] .'</br>'.$mas;
 }else{
 echo "";
 }
 ?>
 
 <? echo $kitty; ?>
 </td>
<td width="185" bgcolor="#FFFFFF"><span class="submited style2"><strong>Submitted</strong>: <?php echo $yourtime; ?></span></td>
</tr>
<?php
}
while ($memb_mrows = mysql_fetch_assoc($membs));
}
while ($stu_rows = mysql_fetch_assoc($admin_master));
?>

<tr>
</tr>
<?
if(isset($_POST['checkbox'])){
$fshije = $_POST['checkbox'];
 
$deletequery = "DELETE FROM main WHERE student_id IN ($fshije)";
 
$update = "UPDATE members SET cats = replace(cats, $fshije . ',', '')";
mysql_query($update);
}
?>

Open in new window

0
 
ostroxAuthor Commented:
Well the delete issue is a main issue for me right now, I want to delete both the ',id #' for each drop-down menu selection, but also there would be a seocnd piece of code that would delete the entire entry from the datbase, which i already have just need to bind it to the delete of the entry and remove the category associated with that entry, hope i'm being clear.

In regards to the refresh page, the code we've so far put in together i've tried a few variations but nothing works so far, only if the user logs out then will it update the drop-down list, but when the user enters data they are returned to the drop-down list page which still has the selected value, i guess since it's still has the current value stored in the session, so after it's entered into the database i would need to get the newly added value and add it to a the $_SESSION['bid']; variable, i'm not sure if that's the way it's supposed to be done!?
0
 
ostroxAuthor Commented:
Ok the code you posted above about deleting it, i tried in sql and it worked in this form: UPDATE members SET cats = replace(cats, ', 23', '')"; but I can't get the results dynamically for each entry so that ', 23' is instead replaced by the value held in a variable $fsh (Which should be in the the same format as seen in the above update statement.

I think I'm not getting the right values from mysql, i think, could this be a problem? I'm have two queries one who getting all the entry titles and it's corresponding dates and the other to get all the values for the drop-down list so that i could get the value i need within the $fsh variable, i have both queries with a nested do while statment.
0
 
DavidSingletonCommented:
so, fsh is an array of values you wish to remove?  If thats the case just loop through your array.  If you mean that fsh = ', 23' then make sure you have it quoted right.

 Here's the problem I'm having, you keep saying this or that doesn't work, but you provide no debug information.  does mysql kick an error back at you? Are you getting any php errors.  As far as php/mysql goes this is fairly basic stuff.  We're probably over 60 messages long in this thread, your original question has been answered, post any error info your getting so we can get this thing closed down.
0
 
ostroxAuthor Commented:
No, fsh is a variable of mysql_fetch_array, the gets the values i want, however i get all the values within the field, instead of being able to divide between each value and entries that have the same value stored in, that's the whole point of the application, basically i want to know how to remove the values being added that you showed me in earlier posts.
0
 
ostroxAuthor Commented:
I've trying doing it this way, but it will only delete the comma before the $del (was $fsh) variable, how do i get it to delete the numeric value after the comma as well!?
<?
if(isset($_POST['checkbox'])){
$fsh= implode(',', $_POST['checkbox']);
$del = $stu_rows['cats'] == $fshije;
 
$update = "UPDATE members SET cats = replace(cats, ', $del', '')";
echo $fshije;
mysql_query($update);
}
?>

Open in new window

0
 
DavidSingletonCommented:
if i understand your code correctly (which its very possible i don't) the acatual value your wanting to get rid of in the database is stored in $_POST['checkbox']

again, if you would just echo the value of $del you would see what its trying to replace.  That would probably tell you why it's not working.  

if the following doesn't work change mysql_query($update) to echo $update and print the results here.

So then:
$del = $_POST['checkbox'];
$update = "UPDATE members SET cats = replace(cats, ', $del', '')";

Open in new window

0
 
ostroxAuthor Commented:
Right, what i've done is selected all my tables with inner and left joins in mysql and looped it in php so that i can print out the title, the data and the value of the categorie id's within one loop statement, and just to test it, i've echoed the value of del and get this:

Category 1
Bachelor  ,11 ,22 ,23      Submitted: March 9, 2009

Category 2
Bachelor  ,11 ,22 ,23       Submitted: March 9, 2009

Category 3
Bachelor  ,11 ,22 ,23       Submitted: March 9, 2009

Category 4
Bachelor  ,11 ,22 ,23       Submitted: March 9, 2009
0
 
ostroxAuthor Commented:
David, if you could assist just a little further i would appriciate it since i'm close to getting it right, basically it only deletes the comma and not both the comma and the value, if you could just help me figure out the problem, which i've been posting about it'd appreciate it a lot!
0
 
DavidSingletonCommented:
i want you to echo the value of $_POST['checkbox'] and report that please
0
 
ostroxAuthor Commented:
it prints out just array no result nothing
0
 
DavidSingletonCommented:
how are you passing the SINGLE value that you want removed from the array.  I assume the user chooses that single value somehow.  Your script is only removing the , because that single value that you're wanting to remove isn't present in the variable.  Do you see what I'm saying, I'm assuming check box is supposed to be that single value.  The fact that the $_POST is blank means your only trying to replace comma, not any value.  the value you want to replace has to get to your page somehow.
0
 
ostroxAuthor Commented:
I've actually got it working now, by adding the cats and mcats fields into main, so when i add them the values of bid and mid from bachelors and masters into bid and mid into main, i also decided to add those values into cats (bid) and mcats (mid), this gave me single values that correspond to the dilimited values in the members cats and mcats fields (which are respresented in ,12,34,3,46 etc) and doing a do while in the form and adding the checkbox value to cats, I was able to both delete an entry in the main table and update the cats category within members, the only problem now is, i can't get mcats (mid) to work!!! Because i'm looping through values that either print out cats or mcats, how would i be able to get values for both and distinguish between the two...

<input name="checkbox[]" type="checkbox" class="radio" id="checkbox[]" value="<? echo $stu_rows['cats'];  ?>">

How do i make sure the above stores the values for both cats and mcats
<?
if(isset($_POST['checkbox'])){
$del = implode(',', $_POST['checkbox']);
 
$del2= "DELETE FROM main WHERE cats IN ($del)";
mysql_query($del2);
 
$del3= "UPDATE members SET cats = Replace(cats, ', $del', '')";
mysql_query($del3);
 
}
?>

Open in new window

0
 
ostroxAuthor Commented:
0
 
ostroxAuthor Commented:
Can I or how do I add more than one value to a session variable?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 48
  • 31
Tackle projects and never again get stuck behind a technical roadblock.
Join Now