Advertisement

06.25.2008 at 08:14AM PDT, ID: 23514816
[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!

9.0

MySQL array results to _POST Variable does not work!

Asked by wauger in PHP and Databases

Tags:

Hi All,
I've looked all over for an answer to this, so if there is in one in this forum I apologize for the redundancy.

This is probably not the best way to do this, but, in any case, I am building a few admin pages for our site. In the "Delete Calendar Entry" page I am displaying all of the calendar events for a given week which come out of a MySQL DB into an array on the page. Next to each entry (through every iteration) I have a form that contains the array information for that entry and a form that posts back to the same page. The POST grabs the unique ID which runs a SQL statement to delete that row in the table.

Here is the problem. Let's say there are three entries being returned in the original SQL query, each with their own unique ID. No matter which one you select to delete, the POST variable always returns the last unique ID in the SQL array that was returned.

I'm sure there is a better way to do this, but I have given up - I need help. Start Free Trial
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:
///// This is the code that runs when that specific form is submitted
///// It deletes the select entry
if (!empty($_POST["del_usher_submit"])) { //Admin deleted Usher Schedule - make SQL statement
 
 
mysql_connect(DB_HOST, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME) or die(mysql_error());
 
$sql = "DELETE FROM usher_schedule WHERE date = '" . '{$_POST['del_usher_id']}' . "'";
$result = mysql_query($sql) or die(mysql_error());
 
mysql_close(mysql_connect(DB_HOST, DB_USER, DB_PASS));
 
}
 
 
///// This is the code that runs when the page is loaded natively
/////
<form id="del_usher_schedule" name="del_usher_schedule" method="post" action="main-del.php">
<table width="1236" border="1">
  <tr>
    <td colspan="7"><div align="center"><strong>Ushers' Schedule</strong></div></td>
  </tr>
  <tr>
    <td><div align="center"><strong>Date</strong></div></td>
    <td><div align="center"><strong>Usher 1</strong></div></td>
    <td><div align="center"><strong>Usher 2</strong></div></td>
    <td><div align="center"><strong>Usher 3</strong></div></td>
    <td><div align="center"><strong>Usher 4</strong></div></td>
    <td><div align="center"><strong>Usher 5</strong></div></td>
    <td><div align="center"><strong>Action</strong></div></td>
  </tr>
<?php  //Create SQL Query for exiting schedules
	mysql_connect(DB_HOST, DB_USER, DB_PASS) or die(mysql_error());
	mysql_select_db(DB_NAME) or die(mysql_error());
 
	$sql = "SELECT * FROM usher_schedule WHERE YEARweek(date) = YEARweek(CURRENT_DATE) OR date = '" . date("Y-m-d", strtotime("Next Sunday")) . "' ORDER BY date ASC";
	$result = mysql_query($sql) or die(mysql_error());
 
 	while ($row = mysql_fetch_array($result)) {
	$usher_date	= $row["date"];
	$usher_1		= $row["ush1"];
	$usher_2		= $row["ush2"];
	$usher_3		= $row["ush3"];
	$usher_4		= $row["ush4"];
	$usher_5		= $row["ush5"];
?>
  <tr>
    <td><div align="center"><?php echo $usher_date;?></div></td>
    <td><div align="center"><?php echo $usher_1;?></div></td>
    <td><div align="center"><?php echo $usher_2;?></div></td>
    <td><div align="center"><?php echo $usher_3;?></div></td>
    <td><div align="center"><?php echo $usher_4;?></div></td>
    <td><div align="center"><?php echo $usher_5;?></div></td>
    <td><div align="center">
            <input name="del_usher_id" type="hidden" value="<?php echo $usher_date;?>" />
      <input name="del_usher_submit" type="submit" value="Delete" onclick="javascript:return confirm('Are you sure you want to delete the usher schedule for <?php echo $usher_date;?>?')" />
    </div></td>
  </tr>
<?php
	}  //End While Loop
	mysql_close(mysql_connect(DB_HOST, DB_USER, DB_PASS));
?>
</table>
</form>
[+][-]06.25.2008 at 08:30AM PDT, ID: 21866749

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.25.2008 at 08:39AM PDT, ID: 21866854

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 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.25.2008 at 08:51AM PDT, ID: 21867011

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.25.2008 at 09:44AM PDT, ID: 21867568

View this solution now by starting your 7-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

Zone: PHP and Databases
Tags: PHP, MySql
Sign Up Now!
Solution Provided By: mmarth
Participating Experts: 4
Solution Grade: A
 
 
[+][-]06.25.2008 at 11:35AM PDT, ID: 21868548

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.27.2008 at 04:17AM PDT, ID: 21882476

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.27.2008 at 05:02AM PDT, ID: 21882723

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-42 / EE_QW_2_20070628