Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Dymanic Populating Checkboxes


i like to retrieve a value from DB,
accordingly i like to display the checkbox, either checked or not.

Now im able to retrieve the value from DB, i can show even show the
checkbox, but i cant make it checked????

the Code i used to display as follows,

#Require the database class
require_once('../dbinfoinc.php');

#Get an array containing the resulting
record
$query = "SELECT * FROM event";
$result = mysql_query($query);

$num=mysql_numrows($result);
mysql_close();

$i=0;
while ($i < $num) {
if(($i % 2) == 0) { $c =
'"TableDetail"' }
else { $c = '"TableDetail2"' }

$event_id=mysql_result($result,$i,"event_id");

$event_name=mysql_result($result,$i,"event_name");

$event_publish=mysql_result($result,$i,"publish");
// if(($event_publish) == 0) {
$event_publish = 'No' }
// else { $event_publish = 'YES'
}
$take_action = 'Delete'
echo "<tr>
<td Class='navText'
align='center' class=$c>$event_id</td>
<td class='navText'
class=$c>$event_name</td>
<td class='navText'
align='center' class=$c><input type='checkbox'
name='publish' if($event_publish==1){'CHECKED'}?></td>
<td class='navText'
align='center' class=$c><a
href='delete_event.php?event_id=$event_id'>$take_action</a></td></tr>";

$i++;
}
?>




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Populating A Select Box
What I want to do for members of my website is to allow them to click a button that will add their name to a list that populates a select box.  I can do this on my own, but I was curious if I have to use a database in order for this to be possible. 

PHP + MYSQL, Populating Drop Down Box
I am looking to generate a dropdown box from MYSQL data:

db name = h2, table = Working, Column = Home.

Populating Two Combo Boxes
I have one combo box (Category) which is populated by a MySQL table using php. I am trying to use the onchange javascript to submit the value selected so that I can populate the other combo box (sub-category) based on what was previously choosen. So can anybody give me a clue on how to submit the first boxes value so that the second can see what was selected (javascript function).

Populating Dropdown List
I am wanting to know how to populate the <SELECT> dropdown menu with all existing values from the DB and also have the value associated with that id selected. This is an updating area of my admin. Any ideas? Here's the code so far. At the moment it only retrieves the value assigned to that id. PHP Code:

Populating A Drop Down Menu
How would I go about populating a Drop Down menu from data in MySQL? If you can show me wither a URL to learn this, or if you feel like telling me here, that would be great.

Re-populating A Form If Errors
I am learning php. I have created a simple Web page with a form.
After receing the POST request, I do some error checking. In case of
errors, I would like to re-post the page, but with the current values
for each field.

I have organized my files like this:
1) Webpage with the form (all in html, form action points to a php
file)
2) php file that receives the request.

Populating Form Text Box.
I have a PHP form for entering data on-line into a mySQL
table..
Because of the intended search facility, I require one field in the form
to be completed with exact and precise item names and spelling.
In testing, I had achieved this with look-up tables.
Ideally I would like the selected item from one of five drop-down lists
to autopopulate the form text field when selected.
Alternatively at least the option of copy and paste.
Copy and paste - for some reason will not work.
Autofill worked fine on a test form with no database connection
and in standard HTML and javascript, however, once the PHP
is added to the page neither method works.
Could anyone please point me in the direction of how to get the
autofill to work?

Populating A Select Box From A Database
I have a subscription database that allows you to edit a subscribers data. For example, you enter a search term like "Bob" and it returns a list of everyone named Bob. You click the one you want and it goes to a subscriber detail page, where all of his data is populated to a form. You can directly edit this form and click save to overwrite it.

The only issue is the select boxes (drop downs) - say I have four options in the drop down box, red, blue, green and black. On my details page for bob I end up with five, I have those four PLUS whatever was saved for his color, so it shows up twice. If Bob is green, my select box looks like:

Green
Red
Blue
Green
Black

How can I make it so that Green only shows up once?

Populating Drop Down And Table
I have a database with the following fields.
Name | Company | Date

values in each column could be repeated, or not. as in there could be several same names with the same company with different dates, or different names with same company.

How do I populate a table with this info and have drop down boxes, so that I can narrow down the search? For example:
Name | Company | Date
12     | 1           | 1929
13     | 1           | 1929
14     | 1           | 1929
12     | 2           | 1929
12     | 4           | 1929
13     | 1           | 1941
12     | 6           | 1929

So if in the drop down I select '12' under name, only those entries with 12 are shown, and then I can further sort it by selecting only '1' under Company.
Hope I'm clear, I manage to complicate things when I post them.

Populating An Auto_increament Attribute
I have just designed a BD. there are companies with auto increament which are integer. When I try to populate it after i tool value from another form and try to insert it into a table i recieve an error! I don't ask the companyID value from user as it is auto increament. Don't tell me to put NULL for that entry as it didn't work as well! Code:

Populating Table Information
I am trying to dynamically generate bgcolors with to help populate some information for a site. Here is the code:

Auto Populating A Drop Down Box
Basically I'm setting up a website which needs an populated drop down box made up from all fields in a specific column of a table in a mysql db....

Here's the code I've made up using various tutorials....

<?php 
$user = "";  
$host = "" 
$password = "" 
$dbName =  "" 

/* make connection to database */  
mysql_connect($host, $user, $password) OR DIE( "Unable to connect 
to database"); 
mysql_select_db($dbName); //did you forget this line? 

$sql = "SELECT model FROM usedVehicles"; 
$query = mysql_query($sql) or die(mysql_error() . "<br>$sql"); //use the or die(...) part ONLY IN DEVELOPMENT 
?>

<form action="action" method="post"> 
<select name="option"> 

<?php  
while ($row = mysql_fetch_array($result)) {  
    echo "<option value="" . $row['model'] . "">" . $row['model'] . "</option>
";  
}  
?> 
</select> 
<input type="submit"> 
</form>

I've left out the connection details for obvious reasons... When I upload and try to test this, jus a blank drop down appears... there are definately fields in the column as I have tried the query on phpMyAdmin.

Populating Fresh Data
Im building a live web chat using php, mysql, javascript, ajax I am fine with sending and retreiving data in real time using ajax as the transfer protocol However, my problem, which is becoming a nightmare, is how to I display it !! Lets say the below is the chat screen,

<div id="messages">
Jamie - Hello
Peter = Hi
Jamie = Nice Day
Peter = I know
</div>

Lets say Jamie's next message is "What are you doing today". I can send that off to the database no problem and I can get peters live chat to pull that message in, however, how do I get it to display underneath Peter = I know

As a practice I was using

document.getelementbyid('messages').innerHTML = document.getelementbyid('messages').innerHTML + "<BR>What are you doing today"

That works, but, lets just say the chat gets to 1000 lines, for each new message those 1000 lines have to be pulled out via javascript, a new line written to it and then printed back in the div

Im not sure but I'd take a good guess at this not being optimal and will cause CPU load on the users machine

What is the best way to do this! Chat messages are deleted after 1 minute, but that doesnt matter because by then they have already been sent the the users chat. Just incase you are thinking of completely repopulating there chat with every message they have sent since the chat started..

Reading Directories, Populating Select Box
Can anybody tell me how to read through a directory, get the file names and populate a select box(pulldown menu) with these names? I know how to loop through a directory using something like this:

while ($files = readdir($handle)) {

$ext=substr($file,-4);

if ($files != "." && $files != ".." && $ext == ".php") {

do some wild and crazy stuff here;

}

}

It's the populating the select box (pulldown menu) while doing this that I need the help on.

Populating Form Item From SQL Enum Set Rev#2
$sql = "SHOW COLUMNS FROM table LIKE 'subject' ";
$qry = mysql_query($sql) or die("Query not valid: " . mysql_error());
$res = mysql_fetch_object($qry);
// This returns a row with a field 'Type' containing 'enum(...)'

$res->Type = str_replace('enum('', '', $res->Type);
$res->Type = str_replace('')', '', $res->Type);
//now the string is something like this: one','two','three

$temp = explode('','',$res->Type);
//temp is an array with as much elements as the enum

while ($temp)
print array_pop($temp);


This way is much more easier using the elements since they are elements
of an array. Cleaver isn't it?

Populating Array With Mysql Results
I'm returning a result set of one field in a table, and want to populate an array with the results. I can't for the life of me figure out a simple way to do this without using mysql_fetch_array() to cycle through the results, append that to a var, then explode that into a var and pass that. PHP Code:

Populating A Form Wth Database Info
I've coded a piece of code which populates a form with data read from the database:

$connection=mysql_connec ("localhost", "f2821842", "f2821842");
$result=mysql_select_db("QUERIES");
$query=mysql_query("Select * from Emp_Details where emp_num = '$employnum'");
while($row=mysql_fetch_array($query))
{$empname=$row['emp_name'];}

<form name="webregform" action="webadmin2.php" method="post">
<input name="requiredname" type="text" size="30" value="<?php echo "$empname"; ?>">
</form>

When I echo the $requiredname, I get spaces and no data, and I know that $empname is not a space-it does read a value in a database. 1. How can I get $requiredname to print a value?

Populating Dynamically Generated TextFields
If one assigns something to the value iattribute off an input /text field, that value will be displayed when the form is loaded. My problem is, when building a form dynamically, the only way I can get the text to show is by doing the above, however, as this is an update form, when the form POSTS to processUpdate.php,
both the data entered by the user AND the data in the value attribute are inserted/updated.

So, how does one dynamically build a form where the data is displayed in the text fields but value atttribute is not set. PHP Code:

Populating A Drop Down List With The Year
i'm trying to loop the years from 1960 - 2010 with the function get_year() below:
PHP Code:

Populating Form Fields With Variables
The script itself works fine: mail gets sent. If there are any missing fields the form displays again with a list of the missing fields, but I can't get the form fields of the reloaded form to be populated with teh existing values. PHP Code:

Populating DHTML Menu From MySQL
I have a client that would like to have drop down menus added to a nav
bar that is generated from MySQL. Is it possible to have a dynamically
driven DHTML menu from MySQL?

Populating Arrays From MySQL Query
I have the following code: http://pastebin.com/746601

The field 'material' in 'is_material' contains multiple values for each
record in 'is_details'. Because of this I have used
'is_material_lookup' as a reference lookup table containing the
'style_code' and 'material_code' which refer to their full details in
the respective tables.

Currently I have got the script outputting all the details and one
material then in the next block of data, repeating the details with a
different material. What I would like to achieve is having 1 block of
data with a list of all materials in that, instead of the repeat, but
sadly I can't know exactly how to do it.

Populating Dropdown With Mysql Entries
I would like to create a combobox in Flash which is populated with mysql data and programmed with php. For example: There are 3 entries in database .ie. apple, bannana, peach. Now these I want in combobox in Flash MX/flash5.

Populating A Drop Box With Results From Database
I have a MySQL database with a table (category) with two fields, catId (int) and category (char(50)). What I want to do is to get all category names in this database and place all of them into a dropdown box on a web page so that the user can choose from the list of available categories.

Populating Table With Text File
My web hosting service uses phpMyAdmin and at the bottom of the screen
iis an area where I can upload a text file to populate a table.

I have a table named groups with two fields:
groups_idauto-increment primary
groups_name

So how do I create my text file to populate this table?

I'm going to use MS Notepad.

If it's set to auto-increment, do I need to include the number? If
so, does it start at 0 (zero)?

Would the file look like:

0,students
1,faculty
2, staff

or just

students
faculty
staff



PHP Not Populating Form Variables Passed Through POST Or GET
I"m running:

Windows Xp SP2
Apache2
PHP5
MySQL4

Everything seems fine and dandy, and I can do scripting on server side, but for some reason I cannot get data from a form to be put into a variable.

I have a simple form in an html page which submits, and in the php script that handles the input, none of the data in the form is going into the variables.

My php.ini file does have all the GPC's in place(ie variable_order, the way they get processed).

Auto Populating Multiple Drop Downs.
im trying to create two dropdowns, i need the first one to be the category and the second one to be the subcategory.  The category drop down autopopulates with the correct info from the database. and uses the table "category", the value of each drop down is represented by the "cat" field in the table (cat is basically and integer id number) and "Category" is used as what the user actually sees in the drop down (category is the actual word of the category).

Once the category is selected i would like to have the sub category auto populate with everything that has the same values as the selected category (cat)

Here is a break down of how the tables work.

Table 1 Name: "category"
Fields for Table 1:  "cat" (the id number), "category" ( the actual name of the category)

Table 2 Name: "subcategory"
Fields for Table 2: "cat" (corresponds with the cat id from table 1 to pull the correct data), "subc" (the basic id of the subcategory), "subcat" the actual name of the subcategory.

so the way i see it, have a normal drop down populated by a php query. then on change, populate subcategory drop down where cat = cat and display sub category.

Populating The Drop Down And Pressing The Submit Button
1. The first is I have two drop down menus. The first is "year" and the second is "mfr". When a user selects a year from the drop down it then populates the second drop down, mfr, from the MySQL database. Theat is working fine. But the problem I am having is the "submit" button (which I have labeled as "browse"). When I click it. Nothing happens, no action tacks place. I have looked over the code and I can't figure it out. (See Code Box 1 Below).

2. Right now the "mfr" drop down is populated by the MySQL database and reads with a list like "Acr", "Alp", etc. These are abreviations. I need to set up an array to have them instead read the entire mfr name. Example: Instead of "Acr" it needs to be "Acura". Instead of "Alp" it needs to be "Alpine". I need these full names to appear in the drop down. I know I need to do something like this (See Code Box 2 Below) but I can't get my finger on it. Code:

Populating City,state,country Drop Down Menu
In the registration form I have city, state, country fields. I was
wondering if there was a database available on the net which has the
list of states in each of the countries. That way when a user selects
a country I could automatically populate the state drop down menu ...

Populating Form From Database, Then Passing Results To Next Page
I have a multiple select input in a form that's being populated by a row
from my database as such:
<input type="checkbox" name="subm[]" value="$row[ID]">

That part is working fine as I can check the displayed page using View
Source and see that the value is the correct row number from the
database. It is then being submitted on a form by $_POST method to
another page where I want to evaluate the checkboxes and display the
contents of the entire row that corresponds to each value="$row[ID]"
that have been checked. But I can't seem to get it to work. I'm having a
problem passing the selected value. Can someone point me in the right
direction?

$query = ("SELECT * FROM `table`");
$result = mysql_query($query);

print "<p>Data for Selections:";
print "<table border=2><tr><th>You chose:";

foreach ($_POST['subm'] as $value) {
print "<tr><td>";
print "$row[ID];
";
print mysql_field_name($result, 1) . ": " . $row[name]."<br>";
print mysql_field_name($result, 2) . ": " . $row[address]."<br>";
print mysql_field_name($result, 3) . ": " . $row[city]."<br>";
print "</td></tr>";
print "</table>
";
}

if (!isset($_POST['subm'])){
print "<p>No matching entry ";
}

mysql_close();

Auto-populating Multiple Boxes... Php And Pg_fetch_array Problem?
There is a nice tool using jquery/php to populate multiple select boxes out
there, it must be a very stupid question but I?m trying to apply this tool to get data from postgreSQL, but I always get an empty [] value. It means that the...

Populating SELECT Multiple Form Field And Inserting Into Db
I have an update form where I'm trying to populate a SELECT multiple field with a list of 48 categories, from tbl work_cat. And show, as SELECTED, the one or many choices that the user had previously selected from the 48 categories which are stored in tbl cat_relations as $relation_cat.

Then allow the user to update their selections and update the database. But I can't get my form to work. First problem, I can't get the SELECT field on the form to show the categories, and then I don't know where to go from there. Below are my form page and my processing page. Code:

Dynamically Populating Listboxes Based On Previous Selection
How do I populate the second listbox in this form based on the selection of the first listbox?

The first listbox is populated by this query:
$year_query = "SELECT distinct year FROM bench_data";
The second listbox should essentially be populated by this:
$industry_query = "SELECT distinct comp_desc FROM comp_desc, benc_data where $_POST['year']=bench_data.year and bench_data.comp_key=comp_desc.comp_key";

I know this is alot to ask, but please EXPLAIN the code.  I am new and need the explanation elucidated and not just supplied code that will accomplish the goal. Code:

Checkboxes
I've got a form with multiple checkboxes (1-1000 depending what you get from database), and all of those checkboxes are named with an unique id: $Id. What I wanna do is when the form is submitted, all of the rows where checkbox is selected will be updated.

I know that it's done by UPDATE TABLE SET Field = 'New Value' WHERE Id IN (1,2,4,8...)

But how can I read what checkboxes are checked, when the name of the checkboxes are changing?

Checkboxes
I have a form with 3 checkboxes wich have all the same name:

<input type=checkbox name=test value=val1>
<input type=checkbox name=test value=val2>
<input type=checkbox name=test value=val3>

now on the target page i need all values that are checked, so if they are all 3 ckecked i need to get val1, val2 and val3 on the target page. With ASP you get the varaible test = val1;val2;val3 (the values are all put in one variable, separated with a ";"

But when i use PhP i only get the last value in this case "val3". What do i need to do to get all values? I have named them all the same because those checkboxes are dynamicly generated. I dont know how many there will be.

Checkboxes
I have a two checkboxes in HTML:

<input TYPE="checkbox" NAME="cc" VALUE="true"></td><td><b>Credit
Card</b></td></tr>

<input TYPE="checkbox" NAME="cash" VALUE="true"></td><td><b>Company
Check</b>

<input type=button onClick='<?php reviewpayment()?>' value='Continue'
style='font: 10pt Arial;

The function works if I type into the function
$cc = true;
$cash = false;

<?php
function reviewpayment() {
$validity = TRUE;
if ($cc && cash) {
echo 'javascript:alert(" Please select ONLY ONE type of payment ");'
$validity = FALSE; }
.................... ?.

Therefore the function is not receiving the input from the check boxes.

How do I structure the script and HTML to send the input cc and cash in HTML
to $cc and $cash in PHP?

PHP Checkboxes
How do I send CHECKBOXES via email through the mail() function in PHP?

Example: You have 67 checkboxes, all with unique names, but only want
to send the ones that were checked.

Mailer: Verifies only 2 of those 67 were checked, so the email only
has 2 checkboxes checked.

Checkboxes
I have it so a user ticks checkboxes with what 6 numbers they chose, and i need it to check it with a list of 12 numbers and when they press submit, if they got any correct, its says how many they got right.

I laso need it to say if someone has selected more than six options. The checkboxes id are the numbers, ie checkbox1, checkbox2, checkbox3 etc up to checkbox20 Code:

Allow Only 3 Checkboxes ?
How can I limit number of maximum selected checkboxes to only 3 if I have total of 10 checkboxes? I need to limit to 3 answers in poll that have 10 answers. I use the following to print checkboxes: PHP Code:

Checkboxes
I'm trying to construct a checkbox array in a survey form where one
of the choices is "No Preference" which is checked by default.

If the victim chooses other than "No Preference", I'd like to uncheck
the "No Preferences" box and submit the other choices to the rest of the
form as an array.

I have most of it worked out, but I'm stuck on an apparent disconnect
between php and javascript.

When I use this code:

Checkboxes ...
I was wondering how to run a query for every check box checked, Ive looked around the net and nothing I've come accross is too usefull.

PHP And Checkboxes
<input type="checkbox" name="approved" id="approved" <?php if($f['enabled'] == "1") echo "checked="checked""; ?>" />

it saves it as a boolean in the Db.. how do I set the bool in the DB?

Checkboxes
I have been trying to learn checkboxes and arrays, and I've finally figured out how to add the checkboxes to the database.

I currently have two forms  addlinks.php and modifylinks.php and I have a dolinks.php that submits my data to the database.

What I would like to do now is on my modifylinks page show a tick in the boxes to show that they have already been added.

At the moment if I dont tick any boxes on modifylinks.php it deletes my previous data, and I have to retick them everytime I do an update. Code:

Checkboxes
I have a contact form that has about 15 checkboxes on it for different interest. I am curious on the best practice for setting up my mysql table to store the info from the form and how to check which one is selected /checked

Checkboxes From A Mysql DB
I'm creating a page that includes check boxes that are dynamically pulled from a MySQL database. I have gotten it to correctly pull up the boxes and name them, but when I make a change and submit, all of the values that were checked are set to 0 instead of 1.

This should print out a checkbox, checked if it is supposed to be, and take an argument to be passed when the user chooses to update the page.

When I submit my form, all of the checkboxes pass a value of zero even when they are checked.
Can you tell me if there is an error in this statement?

print "<td valign='top'>";
print "<input type=checkbox name=checkbox_$cat_name value='checked' $checked[$j]></td>";
print ${"checkbox_".$field_name}." !!!";
print "<td valign='top'>$list_cat_name</td>";

$checked[$j] - contains the value 'checked' or nothing set (correctly) earlier in the file
the checkboxes are named checkbox_(fieldname) [ex: checkbox_food]

The value 'checked' is passed to another file that updates the db.

Cycle Through Checkboxes
I am fairly new to PHP and ran into a problem that I am sure someone can help me out with. I have a list of email addresses that I am pulling from mySQL, and printing them in table rows with checkboxes in front of each row so that the user can select the address to be deleted from the DB when the user clicks submit button.

I am naming each checkbox "c_<email address>". The output works fine.

The problem that I am having is, how do I make PHP cycle through each of the checkboxes to check to see which one or ones are checked?

Checkboxes, Arrays And SQL
I am very new with PHP, so I hope someone can help me: With the help of JPJones, I've managed to write a basic search script querying a MySQL database.

I would like my users to choose which fields they search from, eg search for "red" in field1, field2 and field7 only.

I would use checkboxes for this, using [], eg:
<input type="checkbox" id="field[]" value="field1">Field 1

I understand I would have to split the $field array (on the comma delimiter?) and then use it in my SQL statement. Would it be something like this?

foreach($fieldarray as $key=>$value)
{
$sql = "SELECT * FROM table WHERE $fieldarray[i] LIKE '%$searchword%'";
}

I have no idea of the correct syntax.

Setting Checkboxes
I have a script which iwant to use to check some check boxes based on a query. It does not work partly because some of the code is borrowed and because I'm abit of my depth.
PHP Code:

Checkboxes - Implode
This is my situation: I have an html form that has 4 checkboxes.

<p><input type="checkbox" name="area[]" value="1" checked> Area1<br>
<input type="checkbox" name="area[]" value="2" checked> Area2<br>
<input type="checkbox" name="area[]" value="3" checked> Area3<br>
<input type="checkbox" name="area[]" value="4" checked> All other areas</p>

This array is passed to a php page that runs a query on a mySQL table. The possible values for area in the mySQL table are 1, 2, 3, 4, 5, 6. So, I want to display records that match the appropriate checkboxes except if checkbox 4 is checked I want the value to be 4, 5, and 6. (>=4). I just can't get the implode to do this. The problem is the last. If checkbox 4 is checked it displays records with area=4 and doesn't display records with area =5 and area=6. How could I do this?


Copyright © 2005-08 www.BigResource.com, All rights reserved