SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2005
    Location
    London, UK
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple Problem Urgent Hemp Needed

    Huys,

    My code below makes a checkbox as cheked if the condition is true, but it is as well echoing checked next to each checkbox, can someone help please?

    PHP Code:
    echo "<td class=\"formcheckbox2\">
                <input name='c_options[
    $i]' type=\"checkbox\" border=\"0\" style=\"border-style: solid; border:0px solid; border-color: #FFFFFF\" value=".$row['tag_desc_id']." ";  
                                                
    $query2 ="SELECT 
                                                    tag_options_id, 
                                                    tag_id,
                                                    tag_name,
                                                    user_id
                                            FROM 
                                                    tags_options"
    ;
                                                
    $result2 mysql_query($query2);
                                                if (!
    $result){
                                                        echo 
    mysql_error();
                                                    }
                                                while (
    $row2 mysql_fetch_array($result2)) {
                                                if(
    $row2['tag_id'] == $row['tag_desc_id']){
                                                    
    //global $checked;
                                                    
    $checked 'checked';
                                                
                            echo 
    $checked />";
                            }
                        } 

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Off Topic:

    i occasionally have "urgent hemp needed" moments too
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Evangelist
    Join Date
    Apr 2005
    Location
    London, UK
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    Off Topic:

    i occasionally have "urgent hemp needed" moments too

    haha lol...

    anyone any ideas?

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if condition is false, set $checked to empty string.

  5. #5
    SitePoint Evangelist
    Join Date
    Apr 2005
    Location
    London, UK
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by crmalibu View Post
    if condition is false, set $checked to empty string.
    i have this now resolved, but the problem now is that my insert statement does not insert the tag_name when on IE unless i submit it twice, but it works on firefox.

    any ideas
    PHP Code:
    function do_checkboxes($userid){
    global 
    $profile_info,  $setting$smarty_object$user_info;;

     if(isset(
    $_POST['set_options'])){
      
     if(!
    $_POST['c_options']==""){
      foreach(
    $_POST['c_options'] as $key=>$value) {
         
           
    $tag_name=mysql_real_escape_string($_POST['tag_name'][$key]);
          
    $id=mysql_real_escape_string($value);
                          
            
    $delete "DELETE FROM tags_options where user_id = '".$user_info[user_id]."' and tag_id <> '".$id."'";
            
    $deleteSQL mysql_query($delete) or die(mysql_error());
            
    //echo  $deleteSQL.'<br />';
    }

     foreach(
    $_POST['c_options'] as $key=>$value) {
              
    $tag_name=mysql_real_escape_string($_POST['tag_name'][$key]);
          
    $id=mysql_real_escape_string($value);
            
            
    $oaction "INSERT INTO tags_options (tag_id, tag_name, user_id) 
                        VALUES('
    $id', '".$tag_name."', '".$user_info[user_id]."')";
        
    //    echo $oaction.'<br />';
        
            
    $optionsSQL mysql_query($oaction) or die(mysql_error());
            
            }
            if(
    $optionsSQL){
                echo 
    '<font color=red>Your options have been saved</font>';
            }    
        }
    }

    $query ="SELECT 
                    tag_desc_id, 
                    tag_name,
                    parent_id
            FROM 
                    tags_description 
            ORDER BY tag_name ASC"
    ;
            
        
            

    $result mysql_query($query);

    if (!
    $result){
            echo 
    mysql_error();
        }
    elseif(
    mysql_num_rows($result)<=0){
            
    //echo "No entries";
        
    }else{
        
        echo 
    "<table  border=\"0\"  cellspacing=\"0\" cellpadding=\"10\">";
        echo 
    "<form method=post>";

    $i=0;

    while (
    $row mysql_fetch_array($result)) {

        
    $i++;
        
    $incr = ($incr == 3) ? $incr 1

        if(
    $incr == 1) echo "<tr>";
        
        echo 
    "<td class=\"formcheckbox2\">";
        echo
    "<input name=\"c_options[$i]\" style=\"border-style: solid; border:0px solid; border-color: #FFFFFF\" type=\"checkbox\" border=\"0\" value='".$row['tag_desc_id']."'";  
                                                
    $query2 ="SELECT 
                                                    tag_options_id, 
                                                    tag_id,
                                                    tag_name,
                                                    user_id
                                            FROM 
                                                    tags_options"
    ;
                                                
    $result2 mysql_query($query2);
                                                if (!
    $result){
                                                        echo 
    mysql_error();
                                                    }
                                                while (
    $row2 mysql_fetch_array($result2)) {
                                                if(
    $row2['tag_id'] == $row['tag_desc_id'] && $row2['user_id'] == $user_info[user_id]){
                                                    
    //global $checked;
                                                    
    $checked 'checked';
                                                
                            echo 
    $checked >";
                        }
                        }
                        
                            echo
    "<input type=\"hidden\" name=\"tag_name[$i]\"  value='".$row['tag_name']."'></input>";
                    
        echo 
    $row['tag_name'];
        echo 
    "</td>";
        if(
    $incr == 3) echo "</tr>";
    }

    echo 
    "<tr>";
    echo 
    "<td>
                                        
                <input type=\"hidden\" name=\"set_options\" value=\"set_options\">
                <input name=\"GO\" type=\"submit\" id=\"GO\" value=\"Save Changes\" class=\"button\">"
    ;
    echo
    "</td>";
    echo 
    "</tr>";
    echo 
    "</form>";
    echo 
    "</table>";

            }
        }
    /* 

  6. #6
    SitePoint Evangelist
    Join Date
    Apr 2005
    Location
    London, UK
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    really stuck on this lads...please does anyone see why the tag_name does not insert on submit on IE unless i submit it twice, this works fine on firefox.

    cheers


Bookmarks

Posting Permissions

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