Page 1 of 1

Help with php ...

Posted: Thu Jan 21, 2010 4:05 pm
by perik78
Hi!

I have a page built in php for different projects within culture and arts.
In one part of the page the members of the page can presentate their projects.
In this part I would like to have a userlist with the possibility to check which other
members you have collaborated with in different projects like in the picture below.
Image

The problem is when I check several checkboxes there will still just show up one collaboration on the page.

Heres an more detailed explanation:


I get the this userlist with the code:

Code: Select all

 
// FROM        
        $projectmenu_selcatNY = '';
            if ($sql->db_Select('user', 'user_id, user_name', ' GROUP BY user_id', 'nowhere', false))
            {
                while ($projectmenu_row = $sql->db_Fetch())
                {
                    extract($projectmenu_row);
                    $projectmenu_selcatNY .= "$user_name<input type='checkbox' name='project_body' value='$user_name $user_id'<br ";
                    if ($user_id == $projectmenu_projectcat)
                    {
                    }
                    $projectmenu_selcatNY .= '>' . $tp->toFORM($projectmenu_bortmedborjan2[2], false) . '</option>';
                } 
            }
            $projectmenu_selcatNY .= '</select>';
// TO
 
2) And this results in a page like below with lists of the collaborations that are checked in the list:
Image

With the code:

Code: Select all

SC_BEGIN project_VIEW_BODY
global $tp,$user_id_project,$project_body,$user_id_project,$project_author,$projectmenu_postername,$user,$user_name,$projectmenu_postername;
return "<a href='".e_BASE."user.php?id.$project_body'>$project_body</a>"; 
SC_END
Where project_VIEW_BODY is a shortcode for a templatefile. And $project_body is the value from the checkbox.

Heres is also a picture of the database:
Image

MY QUESTION:
The problem is when I check several checkboxes there will still just show up one collaboration on the page.

What shall I change in the code to be able to make several users to get registrated in the database?

So if I for example check:
Katapult V
Per3 V
It ends up with a database that looks like:
project_body:
Katapult, per3
Thanks a lot for help!!!

Perik

Re: Help with php ...

Posted: Thu Jan 21, 2010 4:47 pm
by AbraCadaver
Your checkboxes are all named project_body, so the second one overwrites the first one and the third one overwrites the second, etc... You need to use an array and then loop through it or implode it depending upon how you're inserting it:

Code: Select all

$projectmenu_selcatNY .= "$user_name<input type='checkbox' name='project_body[]' value='$user_name $user_id'<br ";

Re: Help with php ...

Posted: Fri Jan 22, 2010 7:35 am
by perik78
thanks for your reply

ok I have now changed the code to:

Code: Select all

// FROM        
        $projectmenu_selcatNY = '';
            if ($sql->db_Select('user', 'user_id, user_name', ' GROUP BY user_id', 'nowhere', false))
            {
                while ($projectmenu_row = $sql->db_Fetch())
                {
                    extract($projectmenu_row);
                    [b]$projectmenu_selcatNY .= "$user_name<input type='checkbox' name='project_body[]' value='$user_name'<br ";[/b]
                    if ($user_id == $projectmenu_projectcat)
                    {
                    }
                    $projectmenu_selcatNY .= '>' . $tp->toFORM($projectmenu_bortmedborjan2[2], false) . '</option>';
                }
            }
            $projectmenu_selcatNY .= '</select>';
// TO
when Im checking a name in the user list it will now registrate the word "Array" in the database instead.

how do I write the code so it writes several names like:
project_body:
Katapult, per3
in the database instead of Array or overwriting the names?
as you probably understand Im a newbie in php

Thanks for your help!

Re: Help with php ...

Posted: Fri Jan 22, 2010 8:43 am
by perik78
i think the script where Im writing into the database is somewhere here?

Code: Select all

       // New record so add it
        // check for duplicate
        if (!$sql->db_Select("projectmenu_projects", "project_id", "where project_name='" . $tp->toDB($_POST['project_name']) . "'", "", false))
        {
            $projectmenu_args = "'0',
        '" . $tp->toDB($_POST['project_name']) . "',
        '" . USERID . "." . USERNAME . "',
        '" . $tp->toDB($_POST['project_servings']) . "',
        '" . $tp->toDB($_POST['project_preptime']) . "',
        '" . $tp->toDB($_POST['project_ingredients']) . "',
        '" . $tp->toDB($_POST['project_body']) . "',
        '" . $tp->toDB($_POST['project_source']) . "',
        '" . $tp->toDB($_POST['project_nutrition']) . "',
 
//
// some code 
// some code 
// some code 
//
 
    else
    {
        // Update existing
        $projectmenu_args = "
        project_name='" . $tp->toDB($_POST['project_name']) . "',
 
        project_servings='" . $tp->toDB($_POST['project_servings']) . "',
        project_preptime='" . $tp->toDB($_POST['project_preptime']) . "',
        project_ingredients='" . $tp->toDB($_POST['project_ingredients']) . "',
        project_body='" . $tp->toDB($_POST['project_body']) . "',
        project_source='" . $tp->toDB($_POST['project_source']) . "',
        project_nutrition='" . $tp->toDB($_POST['project_nutrition']) . "',
        project_category='" . intval($_POST['projectmenu_select']) . "',
        project_approved='" . $project_approved . "',
can that be? what shall I change?

as it is Ive got this code in user_project.php:

Code: Select all

// FROM
$projectmenu_selcatNY = '';
if ($sql->db_Select('user', 'user_id, user_name', ' GROUP BY user_id', 'nowhere', false))
{
while ($projectmenu_row = $sql->db_Fetch())
{
extract($projectmenu_row);
$projectmenu_selcatNY .= "$user_name<input type='checkbox' name='project_body[]' value='$user_name'<br ";
if ($user_id == $projectmenu_projectcat)
{
}
$projectmenu_selcatNY .= '>' . $tp->toFORM($projectmenu_bortmedborjan2[2], false) . '</option>';
}
}
$projectmenu_selcatNY .= '</select>';
// TO
this code in an file for shortcodes called project_shortcodes.php

Code: Select all

SC_BEGIN project_VIEW_BODY
global $tp,$user_id_project,$project_body,$user_id_project,$project_author,$projectmenu_postername,$user,$user_name,$projectmenu_postername;
return "<a href='".e_BASE."user.php?id.$project_body'>$project_body</a>"; 
SC_END

and then this project_VIEW_BODY in an template file called project_template.php

Code: Select all

   $project_VIEW_DETAIL .= '
    <tr>
        <td class="forumheader3" colspan="4"><br><b>' . RCPEMENU_A73 . '&nbsp;{project_VIEW_NAME}</b><br>{project_VIEW_INGREDIENTS}&nbsp;</td>
    </tr>
    <tr>
        <td class="forumheader3" style="width:30%;vertical-align:top;">' . RCPEMENU_13 . '</td>
        <td class="forumheader3" colspan="3">{project_VIEW_BODY}&nbsp;
        <br>
        {project_VIEW_NUTRITION}
        </td>
    </tr>';

Re: Help with php ...

Posted: Fri Jan 22, 2010 9:03 am
by AbraCadaver
Normally for this type of thing you would have a separate table to store each 'project_body' in its own row with a foreign key pointing back to the main record. If you are storing all of the values for 'project_body' in one record then this should work (change the implode ',' to whatever you want):

Code: Select all

'" . implode(',', $tp->toDB($_POST['project_body'])) . "',

Re: Help with php ...

Posted: Sat Jan 23, 2010 3:43 pm
by perik
worked!! thanks a lot for your help!