[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.5

php loop, multiple sql updates

Asked by bschwarting in PHP Scripting Language, PHP and Databases, MySQL Server

Tags: php, loop, sql update

Ok, I'm open to suggestions, angel :), on my project.  I've hit another roadblock and might be approaching this whole thing the wrong way.  I was trying to create a small footprint of code and loop it all, but can't seem to get everything to work.

I want to print out 365 checkboxes (see attached image), then update a table in the database with the answer for 1(yes) or 0(no).  I'm not sure if doing 365 updates all at once is the best idea or not, for each of my users.

My end game is this:
#1) print out 365 checkboxes
#2) check the individual users table to see which checkbox is already a yes, and check it for them (maybe with a value=$checked ?)
#3) allow my users to select/deselect one, or all at the same time and click submit, and update accordingly

Here is the code I have so far, which will print the table, create all the answer variables, then it will update the 1st box that is checked and nothing more for some reason.

any ideas would be appreciated!
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
<?php
 
//GET VARIABLES FROM SUBMISSION ON SAME PAGE
$answer1 = $_POST['answer1']; 
$answer2 = $_POST['answer2']; 
$answer3 = $_POST['answer3']; 
$answer4 = $_POST['answer4']; 
$answer5 = $_POST['answer5'];
$answer6 = $_POST['answer6']; 
$answer7 = $_POST['answer7']; 
$answer8 = $_POST['answer8']; 
$answer9 = $_POST['answer9']; 
$answer10 = $_POST['answer10'];
 
 
//DAILY READINGS
$daily1reading = ', example, read page 1';
$daily2reading = ', example, read page 2';
$daily3reading = ', example, read page 3';
$daily4reading = ', example, read page 4';
$daily5reading = ', example, read page 5';
$daily6reading = ', example, read page 6';
$daily7reading = ', example, read page 7';
$daily8reading = ', example, read page 8';
$daily9reading = ', example, read page 9';
$daily10reading = ', example, read page 10';
 
$date365t = mktime(0, 0, 0, 1, 0, date(Y));
$date365 = date("Y-m-d", $date365t);
 
?>
 
<form method="post" action="365-days">
 
<?php
 
echo '<table width=650><tr>';
for($loop365=1;$loop365<=365;$loop365++) {
  if(($loop365-1)%15==0) echo '</tr><tr>'; ?>
  <td align="center"><span title="<?php 
  echo "Daily reading for ".date('F jS',mktime(0,0,0,1,$loop365)); $dailyreading = "daily{$loop365}reading"; echo $$dailyreading; echo " (Day $loop365)";
$date365t += 86400;
$date365 = date("Y-m-d", $date365t);
 
echo "#"; echo ${$answerloop365}; echo "#"; 
?>"><?php echo $loop365; ?></span></td>
<td align="center">
<input type='checkbox' value="0" title="<?php 
  echo "Daily reading for ".date('F jS',mktime(0,0,0,1,$loop365)); $dailyreading = "daily{$loop365}reading"; echo $$dailyreading; echo " (Day $loop365)"; ?>" value='1' name="answer<?php echo ($loop365+1); ?>" />
</td><?php
 
$answerloop365 = ${'answer'.$loop365};
 
if ( $answerloop365 == '1' ) {
$date1 = date('Y-m-d');
$sql1 = "UPDATE $createtablename SET date='$date1', answer='$answerloop365' WHERE id = ( '$loop365' );";
mysql_query($sql1) or die ("Error in query: $sql1. ".mysql_error());
echo "<b>INSERTED</b>";
} else {
echo "NOT READY TO INSERT";
}
 
}
echo '</tr></table>';
 
?>
 
<table width="650" border="0">
<tr>
<td>
<br>
<input type="submit" value="Update All 365 Days Now!"><input type="Reset">
</form>
</td>
</tr>
</table>
Attachments:
 
loop of checkboxes
loop of checkboxes
 
[+][-]07/06/09 04:05 AM, ID: 24783997Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: PHP Scripting Language, PHP and Databases, MySQL Server
Tags: php, loop, sql update
Sign Up Now!
Solution Provided By: profya
Participating Experts: 1
Solution Grade: A
 
[+][-]07/06/09 02:56 AM, ID: 24783714Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/06/09 04:45 AM, ID: 24784197Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/06/09 04:57 AM, ID: 24784262Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07/06/09 06:15 AM, ID: 24784810Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/06/09 06:21 AM, ID: 24784858Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/06/09 06:43 AM, ID: 24785074Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07/06/09 07:04 AM, ID: 24785263Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/06/09 07:11 AM, ID: 24785338Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/06/09 12:36 PM, ID: 24788491Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/06/09 12:51 PM, ID: 24788633Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/07/09 12:31 AM, ID: 24792070Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07/07/09 07:19 AM, ID: 24794447Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/07/09 07:55 AM, ID: 24794771Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625