Page 2 of 4 FirstFirst 1234 LastLast
Results 26 to 50 of 99
  1. #26
    Join Date
    Mar 2006
    Posts
    984
    I simply used the same name as you did. I even tested with mine as I have the same error result unfortunitely.

  2. #27
    Join Date
    Aug 2002
    Location
    Canada
    Posts
    667
    then your $arr doesn't contain an array. Work on your collection..
    circlical - hosting software development
    forums * blog

  3. #28
    Join Date
    Mar 2006
    Posts
    984
    As you can see from this post:

    http://www.webhostingtalk.com/showpo...74&postcount=9

    I'm, first, checking if the variable is, indeed, an array. If not, it fails.

    Any other idea ?

  4. #29
    Join Date
    Aug 2002
    Location
    Canada
    Posts
    667
    That's a poorly scoped block of code.. Consider replacing it with these few lines:

    Code:
    if( isset( $_POST['user_id'] ) && is_array( $_POST['user_id'] ) ){
    
        $user_ids = implode( ",", $_POST['user_id'] );
    
        $result = mysql_query( "SELECT user_id 
                                               FROM table
                                               WHERE id = '{$_SESSION['user_id']}'", $connection );
    
        if( $row = mysql_fetch_assoc( $res ) ){
    
            if( $row['user_id'] && count( $user_ids ) ){
    
                $idstr = "";
                foreach( $user_ids as $id )
                    $idstr = "'{$id}',";
                $idstr = substr( $idstr, 0, strlen( $idstr ) -1 );
    
                mysql_query( "UPDATE table SET user_id = '{$row['user_id']}'
                                       WHERE user_id IN ($idstr) AND id = '{$_SESSION['user_id']}'" ) or die( mysql_error() );
                header("Location: index.php");
    
            }
        }
    }
    else{
       die ('No permission');
    }

    There's some wierd stuff in your code that I assumed was a sematic mistake.
    Code:
    $sql = "
    
    SELECT user_id
    FROM table
    WHERE id = ".$_SESSION['user_id'];
    
    $result = mysql_query($sql);
    
    while ($row = mysql_fetch_array($result)) {
    $user_id_field = $row['user_id'];
    }
    Why loop through a set of records if only one result is returned, or constantly overwrite them if many results are returned? I assume that 'id' is a primary key on that table?

    Nonetheless, this has nothing to do with an array error...you're probably not catching your array, or screening it properly. Get an IDE like Zend Studio, it can help you when you are learning with its "Analyze Code" feature.
    Last edited by Saeven; 09-06-2006 at 11:02 AM.
    circlical - hosting software development
    forums * blog

  5. #30
    Join Date
    Mar 2006
    Posts
    984
    Ok thanks. I will try this up later today. As for the while loop statement, good question for the single field. I was so into it that I forgot to tell myself to simply set a single variable without a loop. It would, indeed, of been enough. As for the user_id field as a primary - no - it isn't. It's being placed under the 2nd row in the table.

    More inputs to come later . . .

  6. #31
    Join Date
    Mar 2006
    Posts
    984
    This is, now, the error I got:

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND ...
    I followed all the steps you posted. Any other suggestions ?

  7. #32
    Join Date
    Aug 2002
    Location
    Canada
    Posts
    667
    Good luck! Hope this has jogged a solution for you.
    circlical - hosting software development
    forums * blog

  8. #33
    Join Date
    Mar 2006
    Posts
    984
    Hope this has jogged a solution for you.
    It ... didn't. Which is why, I posted back.

    Ah ! well, I guess I will have to wait for an experienced PHP coder to post but I thank you for your time and try-outs anyway.

  9. #34
    Join Date
    Aug 2002
    Location
    Canada
    Posts
    667
    I think if you looked into my portfolio you wouldn't have resorted to such an insult. I could write quite a bit, but I'll desist here. What I posted were not 'try-outs' they were solutions. Your inability to apply them hardly constitutes a 'lack of experience' on my behalf.

    Good luck, to anyone that adds to this thread!
    circlical - hosting software development
    forums * blog

  10. #35
    Join Date
    Mar 2006
    Posts
    984
    Your inability to apply them hardly constitutes a 'lack of experience' on my behalf.
    Then, perhaps, from the great experience you own already, perhaps you could post a definite solution, on this one, due to two server errors (since errors from server are rarely wrong) ?

  11. #36
    Join Date
    Aug 2002
    Location
    Canada
    Posts
    667
    My snippets cannot generate the error you've noted. In candor horizon, I'd write that this isn't a popularity contest, I'm just here to lend a hand (it's my relaxation). You've been second guessing everything myself and anyone else has posted, down to an original finger pointing about parenthesization.

    Post your entire .php file, and myself or someone else here will take a look I'm certain.
    circlical - hosting software development
    forums * blog

  12. #37
    Join Date
    Mar 2006
    Posts
    984
    I'd write that this isn't a popularity contest
    Yes, I'd have to agree on this one. In fact, it was quite expected this way but I was really looking for an answer.

    I'm just here to lend a hand (it's my relaxation).
    I'm not denying the fact that you're trying to assist towards an issue that seem to be harder than I thought to resolve. However, it has almost been three pages - instructed from the first post on what I was trying to accomplish but, unfortunitely, without success so far.

    The entire PHP 'has' been posted entirely already. All I'm doing is renaming those variables into their appropriate names (to avoid copyrighting issues).

    In addition to what has been technicly posted before, I have added an extra line with explode (to avoid further errors from the foreach statement - as posted above). Then, I used your foreach statement from the explode variable, rather than the implode variable, and the error doesn't show up anymore.

    Althought, it still fails to update the info from the SQL statement. No errors are showing either. It simply returns to it's original page without any modifications over the fields. Everything simply remains as it is.

    The good news is, when I uncomment the SQL UPDATE statement, and replace it with echo, (over the imploded variable), the selected IDs are showing up correctly.

  13. #38
    Join Date
    May 2004
    Location
    NYC
    Posts
    793
    There might be a problem here:
    Code:
    if( count( $arr ) ){
    foreach( $arr as $id )
    $idstr = "'{$id}',";
    }
    
    $idstr = substr( $idstr, 0, strlen( $idstr ) -1 );
    In that

    $idstr = "'{$id}';";

    Needs a . concatenator character, and should be initialized:

    Code:
    if( count( $arr ) )
    {
         $idstr = '';
         foreach( $arr as $id )
              $idstr .= "'{$id}',";
    }
    
    $idstr = substr( $idstr, 0, strlen( $idstr ) -1 );
    That said, we can shorten all the code in the above block to:

    Code:
    $idstr = implode(',',$arr);

  14. #39
    Join Date
    Mar 2006
    Posts
    984
    That said, we can shorten all the code in the above block to:
    Yes. That's what I told myself the first time. Althought, the action is deleting more than the selected values. For instance, from the way you posted above, (if we replace all of it with implode as a simplification), if you select 1 ID - it will delete two of them (and one left (supposing you have three IDs in the field). If you select 2 of them, it will delete all of them. That's what I can't quite understand ...

  15. #40
    Join Date
    Mar 2005
    Location
    Amboy WA
    Posts
    2
    Some thing you could try is put a line in like echo("My query is: $sql"); just before your query is sent to mysql or some where it will be printed on screen. Then copy that and log in to mysql on the command line and past it in direct query and see what returns. It helps to know if what you think you ar sending is what you think it is.

  16. #41
    Join Date
    Aug 2002
    Location
    Canada
    Posts
    667
    Good eye seaotter, serves me for typing code on my pda. You are correct. The original code block:

    Code:
    if( $row['user_id'] && count( $user_ids ) ){
    
                $idstr = "";
                foreach( $user_ids as $id )
                    $idstr = "'{$id}',";
                $idstr = substr( $idstr, 0, strlen( $idstr ) -1 );
    
    //...
    should be changed to:

    Code:
    if( $row['user_id'] && count( $user_ids ) ){
    
                $idstr = "";
                foreach( $user_ids as $id )
                    $idstr .= "'{$id}',";
                $idstr = substr( $idstr, 0, strlen( $idstr ) -1 );
    This writ, that wouldn't have invalidated the SQL, it would have simply used only the last ID in the IN ( ) clause.

    Good eye again though - thanks for that correction.

    Horizon:

    However, it has almost been three pages - instructed from the first post on what I was trying to accomplish but, unfortunitely, without success so far.
    Maybe if you posted that php page everyone preceding and including myself have requested, you would get an answer. Til you do, I desist!
    circlical - hosting software development
    forums * blog

  17. #42
    Join Date
    Mar 2006
    Posts
    984
    PHP Code:
    if( $row['user_id'] && count$user_ids ) ){

                
    $idstr "";
                foreach( 
    $user_ids as $id )
                    
    $idstr .= "'{$id}',";

                
    $idstr substr$idstr0strlen$idstr ) -); 
    I will try that little dot addon later today and keep you posted.

    However, wouldn't this line need to be changed into:

    PHP Code:
    $idstr .= substr$idstr0strlen$idstr ) -); 
    too ?

  18. #43
    Join Date
    Apr 2004
    Location
    Fullerton, CA
    Posts
    97
    I'll hop back in here really quick. From the knowledge I have gained, it appears that you are storing multiple id's in a string, that is pulled from a mysql database, correct me if I am wrong? This is not a coding issue, it is a design issue, as far as the database goes, I would restructure the database, so each row has it's own controller id.

  19. #44
    Join Date
    Mar 2006
    Posts
    984
    - it appears that you are storing multiple id's in a string, that is pulled from a mysql database, correct me if I am wrong?

    Yes. Correct. This is what has been demonstrated since the first post.

    - This is not a coding issue, it is a design issue, as far as the database goes, I would restructure the database, so each row has it's own controller id.

    This is what I'm trying to avoid actually. I'd like to create multiple IDs through each ID rows and gain them once required.

    P.S: Sorry for the quotes, I'm not actually at my computer and this keyboard is french so it looks kind of bad I know.

  20. #45
    Join Date
    Apr 2004
    Location
    Fullerton, CA
    Posts
    97
    What reasoning do you have to do it like this? This is bad design, for various reasons.

  21. #46
    Join Date
    Mar 2006
    Posts
    984
    I'm still wondering some topics contains some 'whys' on it. The reason that needs to be done is because of what I'm looking for to accomplish. Simple as that.

  22. #47
    Join Date
    Mar 2006
    Posts
    984
    I have just tried the latest corrections. The good news is, the foreach error is no longer showing up. The bad bews is, it's not updating the fields at all (or may be it does), the array remains the same in the targeted row and the HTML form is redirecting without affecting the rows.

  23. #48
    You are trying to accomplish your task by using the wrong logic and wrong design. Since you don't like to be criticised, what's the point in asking for help?

    You could have posted your database schema which would help others to help you. And your topic wouldn't expand to 3 pages because you are unable to form a string from an array.

    Just a friendly criticism, no hard feelings.

  24. #49
    Join Date
    Mar 2006
    Posts
    984
    You could have posted your database schema which would help others to help you. And your topic wouldn't expand to 3 pages because you are unable to form a string from an array.
    That's a good point of vue though. This isn't a critism but a more common sence solution ...

    I guess it just didn't came to mind. Sorry about that. Next time, I will post my database schema. It is, indeed, more easier to understand.

  25. #50
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    3,103
    Heh, I went through 4 pages and I am still not sure what are you trying to accomplish. It would be good idea to post:
    1. HTML form where checkboxes are being checked
    2. php code handling that
    3. table structure
    4. sample data for couple rows you are trying to update
    5. echo $query to see what the actual query is

    I will not go into design issue.

    You are approaching this problem in a wrong way. First thing you should do is manually construct actual mysql query that will update sample row and see if that will work on it's own. Once you have the query working it should be simple thing to have your PHP construct it dynamically.

Page 2 of 4 FirstFirst 1234 LastLast

Posting Permissions

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