Webmaster Forum


Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Coding Forum Problems with your code? Let's hear about it.

Ezilon Directory   ClickBooth Network   V7N Directory

Reply
 
LinkBack Thread Tools Display Modes
Old 04-14-2006, 12:14 AM   #1 (permalink)
Contributing Member
 
I like pie's Avatar
 
Join Date: 10-12-03
Location: California
Posts: 254
iTrader: 0 / 0%
Latest Blog:
None

I like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the rough
Send a message via ICQ to I like pie Send a message via AIM to I like pie Send a message via MSN to I like pie Send a message via Yahoo to I like pie
php and multiple checkbox processing

Here's the situation:

Users can send other users messages, which are stored in two different tables, users_inbox and users_outbox.

When user #1 reads his inbox, it displays all messages in the users_inbox table that have a to_id of "1". It also displays a checkbox next to each message, the code of which looks like:

Code:
echo "<td><input type=checkbox name=message value=$row[id]></td>";
$row[id] is the message's id number btw. What I want to be able to do is have it so that users can select multiple messages and then delete them. I have no idea how to go about this though.

To make matters worse, I assume that I need the name to = message[] instead of just message, but that screws up a bit of javascript I have on the page that enables users to select or deselect all messages:

Code:
<input type="button" name="CheckAll" value="Check All" onClick="checkAll(document.post.message)"> <input type="button" name="UnCheckAll" value="Uncheck All" onClick="uncheckAll(document.post.message)">
I really am lost here... and it's holding me back from doing more important things. Can somebody help me with how to go about processing this information?
__________________
Foohon Pie Productions
I like pie is offline  
Add Post to del.icio.us
Reply With Quote
Sponsored Links
SEO Hosting by HostGator  Advertise Here  Buy Blog Links
Old 04-14-2006, 02:12 AM   #2 (permalink)
Moderator
 
ToddW's Avatar
 
Join Date: 01-11-04
Location: Folsom
Posts: 2,646
iTrader: 0 / 0%
ToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest order
Send a message via AIM to ToddW
Correct you use message[]

I have select all, and deselect all javascript and do exactly what you want in php too.

I`ll get the code in a few for you I`m on laptop atm.
__________________
Learn about Bear Grylls, Les Stroud, Man Vs. Wild & SurvivorMan at Survival TV Shows
Order Exciting Inspirational Posters from Inspirational Posters at great value.
ToddW is offline  
Add Post to del.icio.us
Reply With Quote
Old 04-14-2006, 02:27 AM   #3 (permalink)
Moderator
 
ToddW's Avatar
 
Join Date: 01-11-04
Location: Folsom
Posts: 2,646
iTrader: 0 / 0%
ToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest order
Send a message via AIM to ToddW
PHP Code:
if (count($message) > 0) {
        for (
$i=0;$i<count($message);$i++) {
                
$id        $message[$i];        
                
$sql        mysql_query("DELETE FROM inbox WHERE id=$id");
        }

That's just how I like to do the variables makes it easier to read/edit hte sql for me, but you get hte idea.
__________________
Learn about Bear Grylls, Les Stroud, Man Vs. Wild & SurvivorMan at Survival TV Shows
Order Exciting Inspirational Posters from Inspirational Posters at great value.
ToddW is offline  
Add Post to del.icio.us
Reply With Quote
Old 04-14-2006, 02:31 PM   #4 (permalink)
Contributing Member
 
I like pie's Avatar
 
Join Date: 10-12-03
Location: California
Posts: 254
iTrader: 0 / 0%
Latest Blog:
None

I like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the rough
Send a message via ICQ to I like pie Send a message via AIM to I like pie Send a message via MSN to I like pie Send a message via Yahoo to I like pie
Thanks Todd, that works great. I'm still having trouble with the javascript though, having [] in the input seems to be screwing things up.

Code:
<SCRIPT LANGUAGE="JavaScript"> function checkAll(field) { for (i = 0; i < field.length; i++) field[i].checked = true ; } function uncheckAll(field) { for (i = 0; i < field.length; i++) field[i].checked = false ; } </script>
That's the script I'm using when calling uncheckAll(document.post.message), and it works ok when the checkboxes have the same name, which does me no good obviously. How would I re-write this to accept message[] instead of just message?
__________________
Foohon Pie Productions
I like pie is offline  
Add Post to del.icio.us
Reply With Quote
Old 04-14-2006, 03:31 PM   #5 (permalink)
Moderator
 
LazyJim's Avatar
 
Join Date: 10-13-03
Location: UK
Posts: 2,819
iTrader: 0 / 0%
Latest Blog:
None

LazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to all
Send a message via MSN to LazyJim
Post

I think there are several options.

I read that PHP might work without the [] in the HTML.
All the message[] fields are not made into an array till after PHP processes the HTTP POST Request, which contains a string like the variables on the end of a URL (?var=value&another_variable=another_value)
Your message fields would look something like this:
?message[]=20&message[]=12&message[]=99&action=delete
PHP auto-magically splits them up and makes you a $_POST array of all these, and as a nice trick puts the ones ending in [] into an array (as you know).

But search the PHP web site and you'll find another global variable with the original string, which should contain all the form fields that were ticked regardless of the square-brackets[]. Examine this string with your own function and you don't need to use the [].
In other words a small extra bit of PHP should avoid re-working your Javascript/HTML.

Alternatively write a JavaScript function that finds the input elements a different way. For example give them all a class value <input class="group1" ...> then your functions get the array of all input elements and modifies any where class contains "group1" etc. something like:
Code:
function checkAll(group_name) { var inputs = getElementsByTagName("INPUT"); for (i = 0; i < inputs.length; i++) if ( inputs[i].class.search(group_name) ) inputs[i].checked = true; }
__________________

-LJ-

My advice is to look at each case individually, with an informed mind and an appropriately balanced and objective viewpoint.

Web Design and Development, Ipswich, UK.
My deviantArt
LazyJim is offline  
Add Post to del.icio.us
Reply With Quote
Old 04-14-2006, 03:43 PM   #6 (permalink)
Contributing Member
 
I like pie's Avatar
 
Join Date: 10-12-03
Location: California
Posts: 254
iTrader: 0 / 0%
Latest Blog:
None

I like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the rough
Send a message via ICQ to I like pie Send a message via AIM to I like pie Send a message via MSN to I like pie Send a message via Yahoo to I like pie
Phew... luckily there seems to be an easier way.

It turns out it will work if I change checkAll(document.post.message[]) to checkAll(document.post['message[]'])

Although I wonder if this isn't properly fixing the problem. But hey, it works in firefox and IE and that's good enough for me.

Thanks for your help Todd and Jim. =)
__________________
Foohon Pie Productions

Last edited by I like pie : 04-14-2006 at 03:46 PM.
I like pie is offline  
Add Post to del.icio.us
Reply With Quote
Old 04-14-2006, 04:02 PM   #7 (permalink)
Moderator
 
ToddW's Avatar
 
Join Date: 01-11-04
Location: Folsom
Posts: 2,646
iTrader: 0 / 0%
ToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest orderToddW is a web professional of the highest order
Send a message via AIM to ToddW
If that doesn't work let me know.

I can post my Check ALl/Uncheckall JS.
__________________
Learn about Bear Grylls, Les Stroud, Man Vs. Wild & SurvivorMan at Survival TV Shows
Order Exciting Inspirational Posters from Inspirational Posters at great value.
ToddW is offline  
Add Post to del.icio.us
Reply With Quote
Old 04-14-2006, 07:43 PM   #8 (permalink)
Contributing Member
 
I like pie's Avatar
 
Join Date: 10-12-03
Location: California
Posts: 254
iTrader: 0 / 0%
Latest Blog:
None

I like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the rough
Send a message via ICQ to I like pie Send a message via AIM to I like pie Send a message via MSN to I like pie Send a message via Yahoo to I like pie
well it works ok, but out of curiosity, how did you do it?
__________________
Foohon Pie Productions
I like pie is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum

Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to put checkbox value into mysql database GoWFB_SEO Coding Forum 4 07-31-2006 09:41 AM
Checkbox and textbox relationship..... chrissyPH Coding Forum 4 07-07-2004 02:37 AM


Sponsor Links
Get exposure! Get exposure! Find Scripts Web Hosting Directory Get exposure! SEO Blog


All times are GMT -7. The time now is 10:58 PM.
© Copyright 2008 V7 Inc