473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

dymanic populating checkboxes

HI,

First of all im vry new to PHP, 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????
Can anyone help, plzzzzzzz!!!
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_a ction</a></td></tr>";

$i++;
}
?>
thanks

Aug 29 '06 #1
2 1961
"calms" <ca*********@gmail.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
HI,

First of all im vry new to PHP, 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????
Can anyone help, plzzzzzzz!!!
the Code i used to display as follows,
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' ?></td>
<td class='navText'
align='center' class=$c><a
href='delete_event.php?event_id=$event_id'>$take_a ction</a></td></tr>";
IF-statements don't work like that, inside a string. You've chosen a very
peculiar way of studying php if you've managed to get all the way to
retrieving information from a databases but have no idea how if's and
strings work or don't work.

Okay, so you have this really big string and inside it you have an if
statement. That won't do. You have to perform the if-test outside the
string. Try this. Before echoing the string, write the following code:

if($event_publish==1){
$checked_state = 'checked="checked"';
} else {
$checked_state = '';
}

And then, inside the string:
echo "...<input type='checkbox'name='publish' $checked_state >...";

And see how it works.

And then the lecture from a seasoned and old php veteran....

I started "coding" by looking into source codes of other websites, studied
the html structures, javascript etc. several years ago. It was in the 90's,
when this thing called "the internet" got big. It was a fun way of learning
and kept me interested, but also very frustrating. Since then I've taken
courses and studied programming really hard and finally stopped copy-pasting
other peoples codes and write everything myself, now that I know how. I
admire your enthusiasm and I strongly encourage you to study php, but start
from the basic stuff. It's very simple and boring first, I mean how exciting
can 1+2 be? I know, boring as hell, but you gotta learn the ground rules of
the language before you can really get into this programming stuff. Keep up
the good work!

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net || Gedoon-S @ IRCnet || rot13(xv***@bhgbyrzcv.arg)
Aug 29 '06 #2
thks a lot.Yes it worked. Also thks for pointing my mistakes tht i
didnt learn in order. Yes i didnt follow any course or book....i learn
through Internet.

calms

Kimmo Laine wrote:
"calms" <ca*********@gmail.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
HI,

First of all im vry new to PHP, 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????
Can anyone help, plzzzzzzz!!!
the Code i used to display as follows,

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' ?></td>
<td class='navText'
align='center' class=$c><a
href='delete_event.php?event_id=$event_id'>$take_a ction</a></td></tr>";

IF-statements don't work like that, inside a string. You've chosen a very
peculiar way of studying php if you've managed to get all the way to
retrieving information from a databases but have no idea how if's and
strings work or don't work.

Okay, so you have this really big string and inside it you have an if
statement. That won't do. You have to perform the if-test outside the
string. Try this. Before echoing the string, write the following code:

if($event_publish==1){
$checked_state = 'checked="checked"';
} else {
$checked_state = '';
}

And then, inside the string:
echo "...<input type='checkbox'name='publish' $checked_state >...";

And see how it works.

And then the lecture from a seasoned and old php veteran....

I started "coding" by looking into source codes of other websites, studied
the html structures, javascript etc. several years ago. It was in the 90's,
when this thing called "the internet" got big. It was a fun way of learning
and kept me interested, but also very frustrating. Since then I've taken
courses and studied programming really hard and finally stopped copy-pasting
other peoples codes and write everything myself, now that I know how. I
admire your enthusiasm and I strongly encourage you to study php, but start
from the basic stuff. It's very simple and boring first, I mean how exciting
can 1+2 be? I know, boring as hell, but you gotta learn the ground rules of
the language before you can really get into this programming stuff. Keep up
the good work!

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net || Gedoon-S @ IRCnet || rot13(xv***@bhgbyrzcv.arg)
Aug 29 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Suzanne | last post by:
Hi, I have a form which our clients can fill in with their personal details. As part of the information we store there is a section - areas of interest - this is a number of radio buttons. ...
3
by: Robert | last post by:
Developing a form that has multiple controls; TextBoxes, RadioButtons, CheckBoxes, etc. I want to dynamically populate all the controls from the database and scroll through the data row by row. ...
4
by: Lumpierbritches | last post by:
Thank you once again for any and all assistance. I'm building an application that's getting quite bulky due to the number of forms, macros and procedures. I was wondering if there's a way to use 1...
2
by: Tomas Vera | last post by:
Hello All, I'm having problems creating a page with dynamic checkboxes in a WebApp. In my app, I need to query a database, then (based on results) add checkboxes to my form and set their...
3
by: Jay | last post by:
I have an asp.net application that needs to fill a series of checkboxes with usernames from a particular group in Active Directory. Could someone please point me in the right direction in regards...
3
by: RFS666 | last post by:
Hello together, I tried to find out about populating an asp.net server control (a dropdownlist) from the clientside jscript, but I didn't find a solution up to now. I cannot use a html...
6
by: JackM | last post by:
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\"> That part is working fine as I can check...
1
by: Archuaakash23 | last post by:
I have a form with a list of checkboxes. The form is created dynamically from a database and the checkboxes are assigned to each item that is returned in the database (each item has a unique ID). I...
3
by: parkergirl | last post by:
Hi, I have an msflexgrid that I need to select with checkboxes (I'm currently using WingDings font). The selection of rows cannot be anymore than three rows (randomly). Then, I need to take the...
1
by: =?Utf-8?B?VGFtbXk=?= | last post by:
Hi! I am using VB 2008 with SQL Server 2000 and SQL Server 2005 (depending which server the user selects to connect to). I have a combox in which the user types the server to connect to. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.