Checkboxes - Loop That Takes The Values And Processes And Writes The Changes To The Database.
I generate a form page from my MySQL database. let's say the table structure is:
Table A
> ID, title, active
the number of rows generated by the query is dynamic. If a field's value is 1, then the form output appears as
<input type=checkbox name=$ID checked> $title
and if not
<input type=checkbox name=$ID> $title
At the bottom of the form there is a submit button. The visitor can check/uncheck rows and then submit the form. I need to write a loop (possibly foreach) that takes the values and processes them and writes the changes to the database.
View Complete Forum Thread with Replies
Related Forum Messages:
Build A Page That Takes Form Data, Processes It In A Second Page
I'm trying to build a page that takes form data, processes it in a second page, then sends the user to a third,depending on data processing. On the second page, I am trying to get the page to have some sort of "Loading" message while the backend processes the data, but I can't seem to get anything to work. Does anyone know how I can get that Loading message to display?
View Replies !
Get Values From Checkboxes
I have 20 checkboxes called myfield..(do i have to call myfield[]?) now in the post of this how can I pull up all the checked values in a string (separated by commas) What I really want to do is let teh user choose which fields should be queried and then build the sql with those fields. I have all this code in asp and i'm trying to workout how to tranlsate to php.
View Replies !
Validate Checkboxes Then Insert Values Into DB
I have a group of checkboxes: <input type="checkbox" name="programs" value="1"> <input type="checkbox" name="programs" value="2"> <input type="checkbox" name="programs" value="3"> <input type="checkbox" name="programs" value="4"> <input type="checkbox" name="programs" value="5"> the user has to check at least one box before submitting the form. so i used some javascript to do the validation. <script language="JavaScript"> function validateForm() { //----------- check check boxes // set var checkbox_choice to false var checkbox_choice = false; // Loop from zero to the one minus the number of radio button selections for (counter = 0; counter < myForm.programs.length; counter++) { // If a radio button has been selected it will return true // (If not it will return false) if (myForm.programs[counter].checked) checkbox_choice = true; } if (!checkbox_choice) { // If there were no selections made display an alert box alert("Please select the program(s) you have watched.") return (false); } </javascript> the validation works fine. but then i am having trouble capturing which checkboxes the user checked and insert that information into the DB. I understand that a way to capture which checkboxes the user checked is to name the checkbox name like "programs[]" so that php knows to treat it like an array. I tried doing that but my javascript validation function didn't work if i use "programs[]" instead of "programs".
View Replies !
Iterate Through Values From All Checked Checkboxes
I have one page, where there are a rows of checkboxes. A button selects all checkboxes, and then presses delete. When delete is pressed, I want to go to a next page and run a sql command for every single box thats checked. The checkboxes store a value, and multiple boxes can be checked. On the second page, whch is the form actin, I simply want to iterate through and pull which values are checked and run a sql command for each value. I have no idea how to do this. I assume you willl have to use a for each statement, but am having trouble programming this.
View Replies !
Multiple Checkboxes - How To Insert The Values Into The DB
I have a sql sb and in one of the tables it is a field called group. This field contains some numbers, etc "2 5 4" In a form i have som checkboxes Code: [ ] Some text (value 1) [x] Some text (value 2) [ ] Some text (value 3) [X] Some text (value 4) [X] Some text (value 5) I want these checkboxes to be checked accordingly to the field in the db. In this case with my example above the second, fourth and fifth checkbox is selected. Also on how to insert the values into the DB. This is probably very simple, but I have a bad day, and i can't figure this out.
View Replies !
Howto Search SET For Multi-values With Checkboxes?
I have the following situation: - 1) table A with a SET datatype containing 48 elements - 2) table with primary ID, a unique pow(2,x) value, a name Each record in table A can have a number of elements in the SET datatype and each element is basically linked with a specific record from table B, which as you can guess more information about the specific SET element. For example, table A contains adverts and out of the 48 elements one can choose useful ones. People can search the site looking for specific (multiple) elements resulting in a number of matching adverts. I wanted to make the searching very fast and so I worked with SET. But when the SET elements would be ('a','b','c') for example I wouln't be able to search for "a,c" easily coz '%$searchstring%' and its % does not work with the 'b' in the middle. SO... a binary search would be in place. Since the elements got a specific order and the records in table B have a matching order with the elements string, I could make a form with checkboxes. I could keep the IDs in table B nicely following from 1 to 48 and work with form processing where a number would be calculated using a sum of pow(2,x) values where x is a corresponding rank in the table B and thus in the elementsstring of SET in table A. So far all is clear? I know this is gonna be messy, since it would have to use the pow function so often and slow the thing down, so I'd rather work with pow(2,x) values that are already put in the database and worked with as value for the checkboxes, it would safe time on processing. So I added a BIGINT column to the table B and added 1 for record 1, 2 for record 2, 4 for record 3, 8 for record 4, you get the picture. BUT, I'm running into problems with the BIGINT since PHP starts messing around with float... making it look like 23423423+19 or so, making my idea completely useless. WHAT should I do? Split up the SET COLUMN of 48 elements over 2 SET COLUMNs of 24 elements so I don't need to use a BIGINT? Or are their any other clever ways to search quickly? Adding 48 columns to the table is not an option, since it would take up too much unused diskspace when many records are involved. A SET is more diskspace economic and fast, but I just got a problem searching quickly for multiple values.
View Replies !
Checkboxes - Display The Checkbox Values As Checked
I've a form in which there are multiple checkboxes. I'm able to insert the checkbox values to a single field in MySQL database. The problem is that when i go to the edit page it should display the checkbox values as checked for those that r checked and then we can change the checkboxes and update the values in the database. Code:
View Replies !
2 Values In A Loop
In a guestbook the im building, I want to set the <tr> bgcolor in a difrent color each msg (the same effect is also here in these forums).The code is a while loop (to get mysql results). How can I do it ?
View Replies !
How Do You Send Data To A Database Via Checkboxes?
I am using PHP to send and retrieve data from a MySQL database via HTML forms. I am using text boxes and everything is fine. If I have a page with checkboxes on, and the users check them and click on the submit button, how does this show up in the database? Nothing seems to show up for me.
View Replies !
Looping Through Checkboxes To Update A Database
I'm developing an application that is highly database dependent. I've to use checkboxes in a number of places so as to ease the use of the system. However, I'm experiencing problems when it comes to looping through the checkboxes so as to update the related info to the database. I'm retrieving info from a a database, then the user has to select a number of unpredetermined records. When he does this, a flag for the selected record is set. But I experience problems when it comes to looping through the checkboxes to set the flags for the selected records.....
View Replies !
Create Checkboxes From Database Data
I'm trying to create checkboxes from a database table header row and then pass that to another page. The checkboxes are gotten from the "header" row of the mysql table. I check which of these checkboxes are selected and if it is selected, I display the data for the rest of the rows under that same column which is selected as a checkbox. Here's the code to generate the checkboxes:
View Replies !
Form Checkboxes - Inserting Into A Database
I have a survey that i am doing, and one of the questions is pick your top two questions out of six answers. When I submit the form how do I know what check boxes they click and how do I know if they clicked three instead of two?
View Replies !
Is It Possibe To Sum Values While In Loop?
I would like to know if it's possible to add values while using a foreach loop. In the array below I have values lesser and greater than 10. I was wondering if during the loop I can check if the value is higer than 10 and basically sum all the values greater than 10. Example: $myarray = array(12, 6, 25, 2, 1, 15, 20); foreach($myarray as $val){ if($val >10){ //STARTING ADDING TO THE NEXT VALUE THAT IS GREATER THAN 10 }}
View Replies !
Adding Values From While Loop
How do you go about adding all the values from a while loop. Here is my code: <?php $query = mysql_query("SELECT * FROM `Enemies` WHERE location='$location'") or die(mysql_error()); $num_row = mysql_num_rows($query) or die(mysql_error()); while($row = mysql_fetch_assoc($query)) { $rarity = $row['rarity']; $value = $rarity/100; $value2 = $value*$num_row; } ?> So this code would loop through 3 times for example and I would like to add up all of the $value2's. Now I know there is a way to do this, but I can't remember I think its along the line of $value2[0]+$value2[1]+$value2[2] or something like that, but as I said I can't remember.
View Replies !
Loop Array Values
how to loop the values from an array into an sql query. I'm quessing you do this with the foreach function, but I'm pretty lost at the moment on how to accomplish it. I have the below code, which will look at each row in a table, and echo that field's info into array, giving me values of 10, 12, 31, etc. for each row. I want to compare those values with another table, but not sure how to proceed. // Gets all the player capitals $sql = 'SELECT capitals FROM game_141 WHERE id >= 2' $playerdata = mysql_query($sql); while ($row = mysql_fetch_assoc($playerdata)) { $capitals = $row["capitals"]; $capitals = explode(",",$capitals); print_r($capitals); echo '<br />' } //Compare each array value to the country id $sql = "SELECT id, name FROM countries WHERE XXXXXX"//Not sure how to proceed $q = mysql_query($sql); while ($a_state = mysql_fetch_assoc($q)){ $STATES[$a_state['id']] = array('name' => $a_state['name']); // } print_r($STATES);
View Replies !
Simple Loop To Get Values
i am trying to loop through results in my db, however, i cant get it to work. i need the echo to ouput something with " in it. <?php //Begin of Checking Loop $URLarray = array( parse_str("$QUERY_STRING"); $db = mysql_connect("localhost", "url_tester_user","xxxxx") or die("Could not connect."); if(!$db) die("no db"); if(!mysql_select_db("url_tester_db",$db)) die("No database selected."); $acc1="SELECT add_url from urls"; $acc2=mysql_query($acc1) or die("Could not select accounts."); ..............
View Replies !
Foreach Loop - How To Get Values
I have one big problem and I dont know how to solve it. This is a code: while ($row=mysql_fetch_array($spisak)) { <form action="naruci.php" method="post"> <input type="checkbox" name="id[]" value="<?php echo $row[proizvodID]; ?>"><br> <input type="text" name="kolicina[]"> </form> } I try to use foreach foreach ($id as $value) { echo $id; } And I success to get $id values but I dont know how to get $kolicina values.
View Replies !
Loop Through Recordset And Add Values
I need help with what should be a simple function. I want to loop through a recordset returned from a sql select statement, and add the values of field 1 from each record. But, I also want to preserve the original value of each record.
View Replies !
Using Checkboxes To Update Multiple Database Entries
I have a query that shows a list of options that a user can toggle on or off using a checkbox. query... form... while($row = mysql_fetch_array($result))... <input name="menu_show_attribute[]" type="checkbox" class="checkbox"'); if ($row['menu_show_attribute'] == 1) { echo (' value="'.$row[menu_id].'" checked /> } else { echo (' value="'.$row[menu_id].'" />'); } The list is generated from boolean values in a DB. This populates my form with checkboxes, some are checked and others are not. I'm using an if statement to sort it (checked). This works fine. The problem is when the user un-checks a checkbox, the value does not get passed and the DB does not update - set/change it to 0. The only values that get passed are the checkboxes that are checked. Below is the query / code after the submit button has been pressed. Are radio buttons the answer? Any help / suggestions would be very much appreciated. //process form for ($i = 0; $i < count($menu_show_attribute); $i++) { if (isset($menu_id) == 'checked') { $menu_show_attribute = 1; } elseif ($menu_show_attribute != 'checked') { $menu_show_attribute = 0; } $query = 'UPDATE menu SET menu_show_attribute = "'. $menu_show_attribute.'" WHERE menu_id = "'. $menu_show_attribute[$i].'"' echo("<br>"); echo $query; $result = mysql_query($query, $db) or die(mysql_error()); }
View Replies !
Selecting Multiple Dynamic Checkboxes From A Database
I have dynamic checkboxes with values populated from a database table and want to set the boxes to selected based on values from another table. Basically, I have a table of users, a table of categories (populates the checkboxes) and a table that is populated when multiple categories are selected per user (the table used to set the checkboxes to selected)..hope this is clear..Its for an 'Edit user' page, displaying the info for the user. Code:
View Replies !
Hitcounter That Writes To A Txt File
I am trying to write a hitcounter that writes to a txt file called hits.txt. I am also trying to makesure that the ip address is unique before it writes to the txt file. I am not able to get this working could any one tell me what is wrong with my code? Code:
View Replies !
Foreach Loop Contains Arrays In Some Values
I'm looping through the keys and values of a form submission using foreach($_POST as $key => $value) echo "$key = $value<br>"; No problems there. All works as expected. But seveal of the values are arrays and the echo comes out like: subjectone = Array subjecttwo = Array There could be as many as 9 elements in each array but there may be as few as one. How can I get those $value that are arrays to echo the entire array using a foreach loop? I would like to end up with all values printed in the page whether in an array or not.
View Replies !
Maths And Loop, Spreading Values
I have some code that I just cannot see why its not doing as it should. The code is feed 5 numbers, atleast one of those number is a negative value, the code the re-distributes the negatives amoung the positive values proportionally thus finishing up with 5 numbers that are all positive or zero. Code:
View Replies !
Retieve & Loop Through Values / Records
How in php do i retrieve the values and loop through the values also I need to get the id of the first record put in (I am adding a member and then a correlating set of schools (a separate table with schoolid,memberid) -- so how do i get the member id of the last inserted record to put in the member_school table).
View Replies !
Php Exec To C Program That Writes File
I'm trying to use the exec() call in php to run a program that I've written and compiled from C. This program attempts to create a new file and write data into it. If I simply run the program from the shell, it writes the file no problem. If i run the program through an exec call in a php script, however, the program executes but it seems to not have the correct permissions to be able to write the file.
View Replies !
Adding Values To An Array In A Foreach Loop.
I am creating a function for my horse site that will choose the color of the horse. I have a database full of horse breeds and all the possible colors they can be. Here is what the "color" column might hold for one of the horse breeds: solid,paint The word "solid" can be a bunch of different colors...so I am trying to make my script add all these colors to an array I am populating that holds all the possible colors for that breed. Here is my current code for the function with comments to let you know what is going on Code:
View Replies !
Writes The Email Address To The Text File
I've got a PHP form processor running that sends the forms fields via email and then writes the email address of the sender to a text file on the server. I've got it working perfectly except when it writes the email address to the text file, it puts them all on the same line. I need to get it to put each address on the next line down. This is probably a pretty simple thing to do but my eyes are bugging after trying for a while now. Here is the code that writes to the text file: ////////////write to file/////////// $out = fopen("/home/myserver/leads.txt","a"); if (!$out) { print("Could not append to file"); exit; } $T1 = $_POST[$reply_to_field]; fwrite($out,"$T1 "); fclose($out);
View Replies !
Selecting Multiple Values From Multiple Tables Using Checkboxes
I've been struggling with this for a bit but cannot seem to find a simpler, cleaner way of doing this. a. I have a Table A - Customers , Table B - Contacts . b. I have a form where a user types the first few alphabets of a customer name and then gets a list of contacts, cities. c. The user is supposed to select multiple options from this list and then send that data to another form for processing. I'm able to only pass data from Table A, not from B . Could someone please have a look at the 2 snippets of code and advise? And is there a way both these php scripts could be combined in a single one ? Code:
View Replies !
Database Loop
I need to loop through a database, take the phone number value, send an individual message to each number. This is my attempt. It only takes one number from the database insteading of looping through and sending a message to all the numbers. Code:
View Replies !
PHP Processes
I have a cronjob triggering a php script that takes several minutes to accomplish. I need to prevent multiple triggering by the cronjob mulfunctioning. So I would like a clean way to know how many instances of a certain php are currently working on the server. is there a server variable for that? if not, how do I know (via php) how many concurrent accesses are there to a certain php page? for example in mysql (the "SHOW PROCESSLIST" command), but I need a similar function for the php page iself.
View Replies !
Fot Loop And Updating To Database
Below is a php page that has a txt box that needs to update a quantity. I just need this code to allow me to update the new quanity inputted into the box... the below code is created in a For loop (see full code below).. The FOR loop is the thing thats confusing me.. My problem: How do i update records many text boxes created in a for loop at the same time?? Code:
View Replies !
Database Query Within A Loop
I am trying to iterate through an array of inputs and validate whether each exists in the database ... so I loop through and run a select statement against the database, and based on that I take the appropriate action ... what is happening is that only the first query is ran (first run through the loop) .. I am guessing it it because I can not re-use the $rows123 array? is that correct? what is the right way to do this? Code:
View Replies !
Background Processes
I'd like to know how to send an external process to the background, so that I can run multiple instances of the same process at one time. Any tips, links.. etc?
View Replies !
Listing Processes In PHP
Using PHP, is it possible to return and display a list of currently running processes on the client's machine? In fact, is it possible to run a system command on a client's machine?
View Replies !
Automated Processes
Customers post 'projects' to my site. These 'projects' are closed after 10 days. I could run a script on the default.php page that detects this, but it seems a waste of resources to run it everytime someone visits the site. Is there a way around this, for example the first visitor to the site in any, say, 3 hour period, runs the script & switches the most recently outdated projects from open to closed?
View Replies !
|