Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
killing-hours
RavenNuke(tm) Development Team



Joined: Oct 01, 2010
Posts: 438
Location: Houston, Tx

PostPosted: Wed Feb 16, 2011 3:45 pm Reply with quote

Hey all-

I've been at this for a couple days now and I'm so hung up on stupid checkboxes. Maybe one of you will have a better idea of how to handle this before I spill my brains on a wall.

I'm setting a switch of sorts for my system and I'm trying to do it with a form that links checkboxes back to a database. The way the form is created on the page is to run through a while loop and create a table row with the company name and checkbox.

What I can't figure out is how this checkbox is to be "unique" so that when the form is submitted I can switch one of the fields in the database from 0 to 1 or visa verca.

-------------------------

Here's the flow.

3 fields in database: ID, Name, Active

Form is built with "while(list" loop creating a new table row and td's for the table row.

Code:
while(list($id, $name, $active) = $db->sql_fetchrow($query)) {

   
   echo '<tr><td>'.$name.'</td>';
   echo '<td align="center"><input type="checkbox" name="chk" /></tr>';

};


the "Active" field will need to switch from 0 -> 1 or 1 -> 0 based on checkbox status.

------------------------

Any insight or help will be appreciated. Thanks.

_________________
Money is the measurement of time - Me
"You can all go to hell…I’m going to Texas" -Davy Crockett 
View user's profile Send private message
Palbin
Site Admin



Joined: Mar 30, 2006
Posts: 2583
Location: Pittsburgh, Pennsylvania

PostPosted: Wed Feb 16, 2011 7:39 pm Reply with quote

Code:
name="chk' . $id .'"

_________________
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan. 
View user's profile Send private message
killing-hours







PostPosted: Thu Feb 17, 2011 8:33 am Reply with quote

Right... I tried that Palbin...

Here's the problem with doing it that way though. As the table fills with more companies... I would have to go back re-program the actual submit script to catch the individual "$_POST['chkID']" ....unless there is some other way to pick them up in the script I'm unaware of.

This is one of those types of things that will need to work all on it's own and shouldn't have to be reprogrammed as the table expands.


Last edited by killing-hours on Thu Feb 17, 2011 11:39 am; edited 1 time in total 
Palbin







PostPosted: Thu Feb 17, 2011 11:07 am Reply with quote

Code:
name="chk[' . $id .']"

Then just iterate through the array when the form i submitted.
 
killing-hours







PostPosted: Thu Feb 17, 2011 11:28 am Reply with quote

Holy cow... that Idea never even crossed my mind. I was trying to figure out on the script side how to work with an array but nothing seemed plausible. I'll try this when I get a chance and appreciate your insight bud!

on a side note... Did you happen to determine if ajaxModules was safe for use or not?
 
Palbin







PostPosted: Thu Feb 17, 2011 7:02 pm Reply with quote

It seems safe. Since it is on the admin side it does not have to be perfect as normal users can not access it.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
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 vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©