Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    May 2005
    Posts
    39
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Help with php ...

    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.


    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:
    // 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:


    With the code:
    Code:
    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:


    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

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,549
    Thanks
    8
    Thanked 1,095 Times in 1,086 Posts
    I think your checkbox problem starts here ...
    <input type='checkbox' name='project_body' .....

    Each checkbox needs a unique name, so you'll have to create an array:
    <input type='checkbox' name='project_body[]' ....

    Then, when you process the form, you grab the checkbox array values.
    You will only see the one's that are checked.

    This is a way to test your form and see what happens with the checkbox values:
    PHP Code:
    <?php

    $proj
    =$_POST['project_body'];
    for(
    $i=0$i count($proj); $i++){
    echo 
    $proj[$i]."<br>";
    }

    ?>
    So, further in your script, you will loop through the array of checkboxes.
    Not knowing how many were checked, you can find out using "count($proj)".

    Maybe that's enough to get you going?

  • #3
    New Coder
    Join Date
    May 2005
    Posts
    39
    Thanks
    2
    Thanked 0 Times in 0 Posts
    thanks for your reply

    ok I have now changed the code to:
    Code:
    // 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
    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

    where and how do I implement this:
    <?php

    $proj=$_POST['project_body'];
    for($i=0; $i < count($proj); $i++){
    echo $proj[$i]."<br>";
    }

    ?>
    Thanks for your help!

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,549
    Thanks
    8
    Thanked 1,095 Times in 1,086 Posts
    We need to see the script where your form is processed ...
    the script where you are writing into the database.

    The script you show above with the checkbox array looks correct.

  • #5
    New Coder
    Join Date
    May 2005
    Posts
    39
    Thanks
    2
    Thanked 0 Times in 0 Posts
    as it is Ive got this code in user_project.php:
    Code:
    // 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:
    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:
        $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>';
    is it something of above? or anything else i shall look for?

  • #6
    New Coder
    Join Date
    May 2005
    Posts
    39
    Thanks
    2
    Thanked 0 Times in 0 Posts
    i think its somewhere here?
    PHP Code:
            // 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?
    Last edited by perik; 01-22-2010 at 03:37 PM.

  • #7
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,549
    Thanks
    8
    Thanked 1,095 Times in 1,086 Posts
    So, the final goal of this is to put all of the names into "project_body"
    with name separated by commas?

    Example:
    one particular project_body would contain: john,bill,sally,nancy
    another one might be: bill,nancy

    Is that correct?

    If so, it would be something like this ... but I can't test anything of course ...
    PHP Code:

    blah blah blah

    else
        {
            
    // Update existing

    // build name list
    $proj=$_POST['project_body'];
    for(
    $i=0$i count($proj); $i++){
    $names .= $proj[$i];
      
    //add comma unless it's the last one
      
    if($i count($proj)){
      
    $names .= ",";
      }
    }
            
    $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($names) . "',
            project_source='" 
    $tp->toDB($_POST['project_source']) . "',
            project_nutrition='" 
    $tp->toDB($_POST['project_nutrition']) . "',
            project_category='" 
    intval($_POST['projectmenu_select']) . "',
            project_approved='" 
    $project_approved "',  


    blah blah blah 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •