Results 76 to 99 of 99
-
09-09-2006, 09:48 AM #76Aspiring Evangelist
- Join Date
- Aug 2004
- Location
- Colorado, US
- Posts
- 427
Originally Posted by horizon
Now show us the rest of the PHP you are currently trying and we can most likely wrap this up.
-
09-09-2006, 09:57 AM #77Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
PHP Code:if ($action == "send_form") {
if (isset($HTTP_POST_VARS['user_id'])) {
$user_id = (isset($HTTP_POST_VARS['user_id'])) ? $HTTP_POST_VARS['user_id'] : NULL;
} else {
$user_id = NULL;
}
if (!is_array($user_id)) {
die ('No permission.');
} elseif (is_array($user_id)) {
$date = date("Y-m-d");
$time = date("H:i:s");
$user_ids = implode(",", $user_id);
$user_ids_array = explode(",", $user_ids);
$remaining_array = array_diff($user_ids_array, $user_id);
$remaining_string = implode(",", $remaining_array);
/*var_dump($user_ids_array)."<br />";
var_dump($user_id);*/
$sql_update = "
UPDATE table
SET user_id = '".$remaining_string."'
WHERE id = ".$_SESSION['user_id'];
$result = mysql_query($sql_update);
}
if ($result) {
header("Location: myform.php");
}
}
-
09-09-2006, 10:19 AM #78Aspiring Evangelist
- Join Date
- Aug 2004
- Location
- Colorado, US
- Posts
- 427
OK, the trouble here is that my original code snippet was based on your post #9 where you were querying the database to get the current list of numbers, and then updating it. In post #77, your code only updates the database, but never finds out what the current list of numbers is, so it's not going to do what you want.
Bringing back in a little bit of your original post #9 gives the following, which is more or less what you want. The important thing is not that this code works, but that you understand what it is doing. Then you know how to debug it if it isn't doing what you expect.
PHP Code:if ($action == "send_form") {
if (isset($HTTP_POST_VARS[URL_USER_ID])) {
$user_id = (isset($HTTP_POST_VARS[URL_USER_ID])) ? $HTTP_POST_VARS[URL_USER_ID] : NULL;
} else {
$user_id = NULL;
}
if (!is_array($user_id)) {
die ('No permission.');
} elseif (is_array($user_id)) {
$date = date("Y-m-d");
$time = date("H:i:s");
$user_ids = implode(",", $user_id);
$sql = "SELECT user_id FROM table WHERE id = '" . $_SESSION['user_id'] . "'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result))
$user_id_field = $row['user_id'];
$current_user_ids = explode(",", $user_id_field);
$remaining_array = array_diff($current_user_ids, $user_id);
$remaining_string = implode(",", $remaining_array);
/*var_dump($user_ids_array)."<br />";
var_dump($user_id);*/
$sql_update = "
UPDATE table
SET user_id = '".$remaining_string."'
WHERE id = ".$_SESSION['user_id'];
$result = mysql_query($sql_update);
}
if ($result) {
//header("Location: myform.php"); //comment this out until you get the code you already have to work.
}
}
Last edited by inimino; 09-09-2006 at 10:24 AM.
-
09-09-2006, 10:31 AM #79Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
Ok. Just tried your version and same results. It returns to it's original page after updating nothing (or perhaps it does update but keeps the exact same readings - can't say).
Althought, this time, I have re-used the var_dump and here it is:
PHP Code:NULL array(2) { [0]=> string(2) "on" [1]=> string(2) "on" }
-
09-09-2006, 10:51 AM #80Aspiring Evangelist
- Join Date
- Aug 2004
- Location
- Colorado, US
- Posts
- 427
OK, but the most critical line of my post was this:
The important thing is not that this code works, but that you understand what it is doing.
Next, break the problem down into manageable chunks. Instead of trying to make everything work at once, just try to do this: create two arrays, $current_user_ids and $user_ids_to_delete. Put the values from the current row in the database into $current_user_ids, and the POST values into $user_ids_to_delete. You've had both of these parts working in the past, in other parts of your code. Use var_dump to figure it out.
Currently it looks like there is a problem with the way you are interpreting the form data, and perhas you var_dumped the wrong variable in the case of the first NULL, else your SQL query is failing.
Try to understand carefully what your code is doing, and take a break if you are feeling frustrated. Debugging is an acquired taste, and the less experience you have with it, the tougher it is.
I will be otherwise occupied for the next 12-24 hours but sometime after that I will try to stop by this thread again. Perhaps you can solve this in the meantime.
-
09-09-2006, 10:58 AM #81Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
Do you understand what the code I suggested is supposed to do, and how that's the same as what you are trying to do? If not, ask questions. Perhaps I misunderstood what exactly you are trying to do, or perhaps you didn't fully understand the code I suggested.
just try to do this: create two arrays, $current_user_ids and $user_ids_to_delete.
Currently it looks like there is a problem with the way you are interpreting the form data, and perhas you var_dumped the wrong variable in the case of the first NULL, else your SQL query is failing.
-
09-09-2006, 11:08 AM #82Aspiring Evangelist
- Join Date
- Aug 2004
- Location
- Colorado, US
- Posts
- 427
Originally Posted by horizon
Unfortunitely, I cannot see where NULL is coming from. However, what I can say is that the form looks pretty fine since each values are being captured properly. What's only missing is the proper way to call the SQL server properly and make the changes the right way. Otherwise, all seem to work fine (except for that NULL).
-
09-09-2006, 12:06 PM #83Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
you must admit that your process of writing this code will not be instantaneous.
-
09-09-2006, 12:14 PM #84Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
IT WORKS !!!!!!!
@inimino:
Thanks very much for your help. Your code responds perfectly well from the targeted action. All is deleting for each IDs from the same row !!!
This is quite different from the previous var_dump() output you posted.
Meaning,
PHP Code:<input type="checkbox" name="user_id[]">
PHP Code:<input type="checkbox" name="user_id[]" value="<?php echo $_SESSION['other_id']; ?>">
-
09-09-2006, 12:51 PM #85Aspiring Evangelist
- Join Date
- Aug 2004
- Location
- Colorado, US
- Posts
- 427
Great! Congratulations on finding a solution, I am glad I could help.
-
09-09-2006, 06:35 PM #86Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
I guess I spoke a little too fast. Before I left my computer, I made one last test. Everything was fine. Althought, when I went back, the same behavior came back - two fields deleted for one selection for an unknown reason. It has changed behavior without knowing why ...
Any inputs on why it does so ? I haven't modified scratch since I last reported here . . .
-
09-09-2006, 07:47 PM #87Web Hosting Evangelist
- Join Date
- Apr 2005
- Posts
- 522
A bit offtopic: horizon, did you read posts that referred to disfunctional database design and possibilities of innacurate row affection if you were to stay with your current db design or you just looked at posts with allready finished codes?
I'd like to know since it seems like a waste of time trying to explain the importance of proper db design if you're not interrested.
Edit: you are also eager to fix syntax errors of code(s) I provided, but it seems you didn't even try them out, nor did you fully understand what I was reffering to in my post. I'd like to know your standing on this, since this is the second thread you've made and you're again dealing with trivial problem and the thread has expanded to 5 pages due to your disinterrest in actually reading, understanding and giving feedback to people who are putting effort into helping you.
-
09-09-2006, 08:31 PM #88Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
@maxymizer:
I totally beg to differ on all your last sentense. The reason why your solution was put aside, even though it was tried out, inimino did post an alternative solution which, first, responded to my needs. Since, I thought it would of remained a stable solution but would seem to have encountered, as mentionned from my last post, some unknown issues along the process. Hopefully, alternative solutions will be posted since I'm not discarding the fact that all of you are adding your inputs into this topic in order justify the best common solution to resolve this problem.
With that all said, your solutions has not been rejected, as you believe it was from above, but simply reconsidered for alternative solutions, since your suggestions is not quite the solution I'm currently looking for and I have already mentionned it before. It is true to say that more than several posts under topics might be unexpected but, no matter which mount of posts a topic might have, it is always important to follow each posts in order to understand the topic creator's objective.
Finally, I'm only considering the best solution to what I seek, like all other requesters on this forum. Meaning, even if you believe you're posting the best inputs, doesn't necessary means that the requester wishes to accept your recommendation directly. Decisions has to be considered first as evaluations needs to be made for each posted codes on this topic.
In the mean time, I believe it is quite the case here - to state that you aren't the only one recommending strategies in order to finalize this subject.
In other words, even if your inputs are still appreciated, it would be also helpful if you could recommend other subjects than single IDs from each rows, since I know my solution is typically possible to be achieved as I intend to maintain that objective. To be honnest, even if you post your inputs, it doesn't mean that the requester will use it - not because it might be a bad input but simply because it isn't the kind of answer she / he expecting for.
Rather than arguing longer over this, I'd rather wish to wait for inimino's inputs on this. Of course, if no inputs has been posted for a while, it would still be great to receive answers to what I'm trying to accomplish - on the right track.Last edited by horizon; 09-09-2006 at 08:34 PM.
-
09-09-2006, 09:16 PM #89Web Hosting Evangelist
- Join Date
- Apr 2005
- Posts
- 522
You are jumping to conclusions. I never stated that my solution was the best and the only one, as you have concluded.
I know what's your objective but you are just too stubborn to read + understand. I could have argumented the solution I proposed by explaning what normal forms are and why is it necessary and only right to use a lookup table the way I told you, since you are using the RDBMS in the wrong way and your software is misfiring and targeting wrong rows. On top of that, it's also slow (when it reaches a big row count your query will execute for a long time).
It's just your attitude that's making me insulted. I am putting my effort and spending my time explaining the basics of good database design to you, who didin't even try to ASK why this system and not the one you tried / are trying to use.
In the end, if you believe your approach to database design is within the aspect of good (proper) db design - why are you even trying to get answers from more experienced people?
Finally, I'm only considering the best solution to what I seek
That puts you in a different position - you're not a coder in the process of learning as you don't enquire about anything, you are just a person who wants to get premade codes without paying the price for the job.
This is the first time I am actually insulted by someone who I tried to help to. You are inexperienced coder with a bad attitude and frankly, I suggest that you start reading and solving problems on your own. It's a trivial problem, your approach is wrong and start by reading up on what's database normalization, what are arrays and what are strings as you lack knowledge in those fields.
-
09-09-2006, 09:26 PM #90Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
No insults was intended. What's been said was simply about personal choices that I would rather make rather than reading multiples choices of yours which suggest to use 1 IDs per rows. Again, that is not to be considered. Sorry.
I will wait for Inimino's codings since it seem to respond pretty well as I'm sure these last encountered issues were simply slight codings mistake which could be easily arranged.
Thanks again for your concern maxymizer.
-
09-10-2006, 07:01 AM #91Junior Guru Wannabe
- Join Date
- Apr 2004
- Location
- Fullerton, CA
- Posts
- 97
Wow, is all I have to say, well, I'm glad I stepped out a while ago, anyways best of luck Horizon, but next time, come here with your ears open and ready to listen, we only are trying to give you tested and proven methods, and why not to do this, and why to do this, and so on and so forth, why? Because we have been there, we have done 'beginner' coding, everyone is a beginner, and the only way you will get better is by reading, studying, listening, and keep on writing code...
Anyways best of wishes to everyone, good luck finding your solution.
P.S. wow, you guys have patience.... 90 posts in, wow....
-
09-10-2006, 07:34 AM #92Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
Could you please stop posting your opinions ? It will only increase postings on this topic and this is NOT what I intend to receive. All I'm looking forward to read is the right technical answer to resolve this problem - period. It used to work and now it doesn't. It should be very easy to understand and hope to fix this issue pretty soon.
-
09-10-2006, 10:27 AM #93Web Hosting Evangelist
- Join Date
- Apr 2005
- Posts
- 522
Originally Posted by horizon
Originally Posted by horizon
-
09-10-2006, 11:26 AM #94Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
Your decision is totally respected. If you do not wish to post here and let someone totally qualified in order to resolve this issue, the choice is totally yours.
-
09-10-2006, 12:49 PM #95Aspiring Evangelist
- Join Date
- Aug 2004
- Location
- Colorado, US
- Posts
- 427
Originally Posted by horizon
-
09-10-2006, 01:25 PM #96Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
I'm totally sorry inimino. I have put the last var_dump results aside but forgot to post it to you. I will do so this afternoon.
-
09-10-2006, 02:55 PM #97Web Hosting Evangelist
- Join Date
- Apr 2005
- Posts
- 522
Originally Posted by horizon
-
09-10-2006, 03:30 PM #98Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
@inimino:
I found it !!! I have reput the var_dump function and found a very slight issue. It was so small that I couldn't see it instantly.
Thanks for your outstanding assistance. Everything's in order now !!
-
09-10-2006, 03:59 PM #99Aspiring Evangelist
- Join Date
- Aug 2004
- Location
- Colorado, US
- Posts
- 427
Great!