SV: [PHP-DB] checkboxes and loops
Hi, Try: $counter = 1; while (whatever) { $varname = 'box'.$counter; if ($$varname == 'delete') do whatever $counter++; } Hth Henrik Hornemann -Oprindelig meddelelse- Fra: matthew perry [mailto:[EMAIL PROTECTED] Sendt: 29. marts 2004 07:45 Til: [EMAIL PROTECTED] Emne: [PHP-DB] checkboxes and loops OK lets see if I can figure out how to ask this: I am setting up a system for my company to filter through employee applications. Most of the applications do not fit the criteria and I want to allow my bosses a checkbox to the right of them which they can check or uncheck to remove an applicant. So I run a loop that generates a bunch of check boxes with the name box1, box2, box3... by running a loop that runs this and increments counter every time: { input type = checkbox name = box?echo $counter;? value = delete $counter++; } But when I try to create my query that updates the table I have a problem generating these variable again by referring to them indirectly: *Bad solution 1 (to much work)*** if ($box1 == 'delete') do whatever if ($box2 == 'delete') do whatever if ($box3 == 'delete') do whatever if ($box4 == 'delete') do whatever if ($box5 == 'delete') do whatever if ($box6 == 'delete') do whatever *** *Bad solution 2 (doesn't work)*** $counter = 1; while (whatever) { if ($box . $counter == 'delete') do whatever $counter++; } *** How do I get around this problem? Hopefully someone understands what I am trying to say. Matt -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] checkboxes and loops
I am relatively new with PHP, but have done this many times with ASP. First, I would not assign the counter value to the checkbox as you are now. Use the ID (identity) value from the database for the applicant record instead. Since ONLY the checkboxes that are checked will be submitted, you can just loop through the submitted checkbox values and perform a 'delete', or 'whatever' on each submitted record. Or, use: ...WHERE IN (id1, id2, ..., idN) in your DELETE statement. Duane -Original Message- From: matthew perry [mailto:[EMAIL PROTECTED] Sent: Sunday, March 28, 2004 11:45 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] checkboxes and loops OK lets see if I can figure out how to ask this: I am setting up a system for my company to filter through employee applications. Most of the applications do not fit the criteria and I want to allow my bosses a checkbox to the right of them which they can check or uncheck to remove an applicant. So I run a loop that generates a bunch of check boxes with the name box1, box2, box3... by running a loop that runs this and increments counter every time: { input type = checkbox name = box?echo $counter;? value = delete $counter++; } But when I try to create my query that updates the table I have a problem generating these variable again by referring to them indirectly: *Bad solution 1 (to much work)*** if ($box1 == 'delete') do whatever if ($box2 == 'delete') do whatever if ($box3 == 'delete') do whatever if ($box4 == 'delete') do whatever if ($box5 == 'delete') do whatever if ($box6 == 'delete') do whatever *** *Bad solution 2 (doesn't work)*** $counter = 1; while (whatever) { if ($box . $counter == 'delete') do whatever $counter++; } *** How do I get around this problem? Hopefully someone understands what I am trying to say. Matt -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] checkboxes and loops
matthew perry wrote: input type = checkbox name = box?echo $counter;? value = delete $counter++; *Bad solution 2 (doesn't work)*** $counter = 1; while (whatever) { if ($box . $counter == 'delete') do whatever $counter++; } *** if(${$box . $counter} == 'delete') However, like someone else said, if you named your checkboxes as box[1], box[2], etc, then you'd have a nice $_POST['box'] array that you could loop through. foreach($_POST['box'] as $count = $value) { do_whatever($count); } -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysqli - using PREPARED STATEMENTS - worth it?
PHP freak wrote: Looking at this page: http://us2.php.net/manual/en/function.mysqli-prepare.php Also the new book ADVANCED PHP PROGRAMMING uses the new MySQLi Prepared Statements for all queries. Wondering if that extra code, trouble, and lack of flexibility is worth it? Will it be a HUGE performance increase that will be worth those added lines of code for every single query? I don't know if the queries are compiled when you prepare them or not, but if they are, that could be a large performance increase. Also, I believe the point to prepared statements is for security. The parameters you bind to the query will be escaped and validated (?) to be the correct type. Can anyone back this up? -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysqli - using PREPARED STATEMENTS - worth it?
PHP freak wrote: Looking at this page: http://us2.php.net/manual/en/function.mysqli-prepare.php Read this, too: http://www.zend.com/php5/articles/php5-mysqli.php -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] DATE_SUB Issues
Hi There, Perhaps someone could lend me a hand here on this query. I have a query where I would like it to SUM up the last 7 days of records further, It needs to start a new week on Monday. The 'time_upload' field is a datetime field. What am I doing wrong or not doing here ? SELECT SUM(distance), DATE_FORMAT('time_upload', '%u'), WEEK('time_upload', '7') FROM TRAININGLOG WHERE DATE_SUB(NOW(),INTERVAL 7 DAY ) =time_upload Thanks, Craig H. __ Craig Hoffman - eClimb Media v: (847) 644 - 8914 f: (847) 866 - 1946 e: [EMAIL PROTECTED] w: www.eclimb.net _ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] DATE_SUB Issues
still no luck - any other suggestions? __ Craig Hoffman - eClimb Media v: (847) 644 - 8914 f: (847) 866 - 1946 e: [EMAIL PROTECTED] w: www.eclimb.net _ On Mar 29, 2004, at 8:18 AM, John W. Holmes wrote: From: Craig Hoffman [EMAIL PROTECTED] Perhaps someone could lend me a hand here on this query. I have a query where I would like it to SUM up the last 7 days of records further, It needs to start a new week on Monday. The 'time_upload' field is a datetime field. What am I doing wrong or not doing here ? SELECT SUM(distance), DATE_FORMAT('time_upload', '%u'), WEEK('time_upload', '7') FROM TRAININGLOG WHERE DATE_SUB(NOW(),INTERVAL 7 DAY ) =time_upload If time_upload is a column, it should not be between single quotes in the WEEK() function. ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] DATE_SUB Issues
From: Craig Hoffman [EMAIL PROTECTED] still no luck - any other suggestions? Please define no luck ---John Holmes... On Mar 29, 2004, at 8:18 AM, John W. Holmes wrote: From: Craig Hoffman [EMAIL PROTECTED] Perhaps someone could lend me a hand here on this query. I have a query where I would like it to SUM up the last 7 days of records further, It needs to start a new week on Monday. The 'time_upload' field is a datetime field. What am I doing wrong or not doing here ? SELECT SUM(distance), DATE_FORMAT('time_upload', '%u'), WEEK('time_upload', '7') FROM TRAININGLOG WHERE DATE_SUB(NOW(),INTERVAL 7 DAY ) =time_upload If time_upload is a column, it should not be between single quotes in the WEEK() function. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] DATE_SUB Issues
What is should doing is grabbing all entries of this week and return a total. Its returning the wrong results. SELECT SUM(distance), DATE_FORMAT(time_upload, '%u'), WEEK(time_upload, 1) FROM TRAININGLOG WHERE DATE_SUB( NOW(),INTERVAL 7 DAY ) = time_upload GROUP BY time_upload LIMIT 1 = Results: (This is wrong) = Weekly Miles: (Week starts on Monday) 5.34 Correct Results should be this: Weekly Miles: 30.5 __ Craig Hoffman - eClimb Media v: (847) 644 - 8914 f: (847) 866 - 1946 e: [EMAIL PROTECTED] w: www.eclimb.net _ On Mar 29, 2004, at 10:29 AM, John W. Holmes wrote: From: Craig Hoffman [EMAIL PROTECTED] On Mar 29, 2004, at 10:06 AM, John W. Holmes wrote: From: Craig Hoffman [EMAIL PROTECTED] still no luck - any other suggestions? Please define no luck Yes of course. Here is my new query. SELECT SUM(distance), DATE_FORMAT(time_upload, '%u'), WEEK(time_upload, '7') FROM TRAININGLOG WHERE DATE_SUB( NOW(),INTERVAL 7 DAY ) = time_upload GROUP BY time_upload LIMIT 1 So how does it not work? What are you expecting? What is returned? Is an error occuring or the wrong results or no results?? ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] DATE_SUB Issues
WooHoo! I got it working! Basically what I did is I changed this DATE_SUB( NOW(),INTERVAL 7 DAY ) to DATE_SUB( NOW(),INTERVAL 1 DAY ) and it worked. I am not entirely sure why. Anyone know? __ Craig Hoffman - eClimb Media v: (847) 644 - 8914 f: (847) 866 - 1946 e: [EMAIL PROTECTED] w: www.eclimb.net _ On Mar 29, 2004, at 10:56 AM, Craig Hoffman wrote: What is should doing is grabbing all entries of this week and return a total. Its returning the wrong results. SELECT SUM(distance), DATE_FORMAT(time_upload, '%u'), WEEK(time_upload, 1) FROM TRAININGLOG WHERE DATE_SUB( NOW(),INTERVAL 7 DAY ) = time_upload GROUP BY time_upload LIMIT 1 = Results: (This is wrong) = Weekly Miles: (Week starts on Monday) 5.34 Correct Results should be this: Weekly Miles: 30.5 __ Craig Hoffman - eClimb Media v: (847) 644 - 8914 f: (847) 866 - 1946 e: [EMAIL PROTECTED] w: www.eclimb.net _ On Mar 29, 2004, at 10:29 AM, John W. Holmes wrote: From: Craig Hoffman [EMAIL PROTECTED] On Mar 29, 2004, at 10:06 AM, John W. Holmes wrote: From: Craig Hoffman [EMAIL PROTECTED] still no luck - any other suggestions? Please define no luck Yes of course. Here is my new query. SELECT SUM(distance), DATE_FORMAT(time_upload, '%u'), WEEK(time_upload, '7') FROM TRAININGLOG WHERE DATE_SUB( NOW(),INTERVAL 7 DAY ) = time_upload GROUP BY time_upload LIMIT 1 So how does it not work? What are you expecting? What is returned? Is an error occuring or the wrong results or no results?? ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] INSERT problem--Need help urgently
Hi all: I was having some problem with INSERT query here and do hope to get some help real soon. I have a form whereby once the form is submitted, the values entered shall be inserted into the database. Next I have also written a SELECT query to view the records which have just been inserted into the database. Data was able to insert into the database and I was also able to retrieve these data from database. However, my problem is, whenever a form was being submitted, it actually INSERT another row of null values into the database. And so, when I clicked to view my data, i can see the previously inserted values as well as an empty row of records. Why is this so? How can I prevent the row of null value to be inserted? I have included a snip of my code below and hope to get some help real soon. All help are greatly appreciated. Thanks in advance. snip $dsn = mysql://root:[EMAIL PROTECTED]/databaseName; $db = DB::connect ($dsn); if (DB::isError ($db)) die ($db-getMessage()); $tutor_name = $_POST[tutor_name]; $tutor_contact = $_POST[tutor_contact]; $tutor_email = $_POST[tutor_email]; $tutor_profile = $_POST[tutor_profile]; $sql =INSERT INTO tutor (tutor_name, tutor_contact, tutor_email, tutor_profile) VALUES('$tutor_name','$tutor_contact','$tutor_email','$tutor_profile'); $result = $db-query($sql); if( DB::isError($result) ) { die ($result-getMessage()); } ? /snip Is there anything wrong with my SELECT query ?? Thanks in advance. Regards, Irin -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php