WaveRebel
|
Posted: 05/19/2004, 9:48 PM |
|
This is what i have and no matter if i send 20 values it will only insert 1 or 2 very weird stuff. What could be happening?
global $orderby;
global $Redirect;
$orderby = CCGetParam("orderby", "");
if ($orderby == "") {
$Redirect = "agenda.php?orderby=categoria";
}
foreach($_POST as $key => $value) {
//Custom Insert done todo's
if ($key == 'todo_id') {
$SQL = "INSERT INTO todolist_users (todo_id, user_id) ".
"VALUES (". $value .",". CCToSQL(CCGetUserID(),ccsInteger) .")";
$db = new clsDBnpdb();
$db->query($SQL);
unset($db);
}
}
|
|
|
peterr
Posts: 5971
|
Posted: 05/20/2004, 12:11 AM |
|
I don't program in PHP and someone else may find an error in your code, but I'd like to point that we have a similar custom code example in the "ManyToManyListbox" page in CCS Example Pack. Possibly it will help.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
|
|
WaveRebel
|
Posted: 05/20/2004, 6:10 AM |
|
Thanks Peterr, Ill chk that out . In the mean time if someone finds a glitch in that code or has had a similar program please reply.
Thanks
|
|
|
hidran
Posts: 29
|
Posted: 05/20/2004, 6:45 AM |
|
$_POST is an array and it will only have one todo_id so your query will only execute once.
Another advice is not instantiating the class inside the loop, do it outside, there is no need to do it for every loop.
Hope it helps
|
|
|
Sixto Luis Santos
|
Posted: 05/20/2004, 7:59 AM |
|
Is todo_id a param array? like todo_id[]=3&todo_id[]=4 etc...
If that is the case then the code should be something like this:
// Get the user id
$user_id=CCGetUserID();
// Instantiate the DB object
$db = new clsDBnpdb();
// Do some sanity check....
// Verify that we are passing $user_id and that $_POST["todo_id"] exists and
is an array
if($user_id && isset($_POST["todo_id"]) && is_array($_POST["todo_id"])
foreach($_POST["todo_id"] as $key=>$value){
$SQL = "INSERT INTO todolist_users (todo_id, user_id) VALUES
($value,$user_id)";
$db->query($SQL);
}
unset($db);
|
|
|
WaveRebel
|
Posted: 05/20/2004, 9:35 AM |
|
Sixto Thank You!!
I think that code will work, Im not in my office right now to chk it out but ill let you know as soon as i run it.
|
|
|
WaveRebel
|
Posted: 05/20/2004, 10:10 PM |
|
Sixto it worked!!!! Thank you so much...
I had to do some minor changes to make it work heres the working code. Hopes this helps anybody in a future.
//Before show label as HTML
global $todolist;
$todolist->todo_id->SetValue("<input name=todo_id[] type=checkbox value=". $todolist->todo_id->GetValue() .">");
//Before Show Page
// Get the user id
$user_id = CCGetUserID();
// Instantiate the DB object
$db = new clsDBnpdb();
// Do some sanity check....
// Verify that we are passing $user_id and that $_POST["todo_id"] exists and
// is an array
if($user_id && isset($_POST["todo_id"]) && is_array($_POST["todo_id"])) {
foreach($_POST["todo_id"] as $key=>$value){
$SQL = "INSERT INTO todolist_users (todo_id, user_id) VALUES ($value,$user_id)";
$db->query($SQL);
}
}
unset($db);
|
|
|