SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast SlayMan's Avatar
    Join Date
    Oct 2004
    Location
    Germany/ Hamburg
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Array saves only 1 char instead of a whole string

    PHP Code:
    if (isset($bearbeiterarray))
                                {
                                    for(
    $i=0;$i<count($bearbeiterarray);$i++) 
                                        {
                                             
    $themaBID[$i]=key($bearbeiterarray);
                                             
    $bearbeiter=current($bearbeiterarray);
                                             
    $sql="UPDATE todo_status SET `bearbeiter`='".$bearbeiter."' WHERE `statusID`='".$themaSID[$i]."' LIMIT 1";
                                          
    //if (@mysql_query($sql) or die(mysql_error())) {echo "Status Nummer $statusID erfolgreich aktualisiert!";}
                                          
    echo "<br />---".$bearbeiter." ---<br />";
                                          echo 
    $sql;
                                          
    next($bearbeiterarray);
                                        }
                                } 
    As u can see above i have somehow weird structure, don't wonder 'bout that.
    It's german by the way so don't care bout that either, but the thing is:
    in this way it WORKS the way i want it to.

    But if i am using: $bearbeiter[$i]=current($bearbeiterarray); instead of $bearbeiter=current($bearbeiterarray);
    it doesn't work, in the output there is only 1 char visible (YES I DO OUTPOUT THE ACTUAL ARRAY content)
    PHP Code:
    if (isset($bearbeiterarray))
                                {
                                    for(
    $i=0;$i<count($bearbeiterarray);$i++) 
                                        {
                                             
    $themaBID[$i]=key($bearbeiterarray);
                                             
    $bearbeiter[$i]=current($bearbeiterarray);
                                             
    $sql="UPDATE todo_status SET `bearbeiter`='".$bearbeiter[$i]."' WHERE `statusID`='".$themaSID[$i]."' LIMIT 1";
                                          
    //if (@mysql_query($sql) or die(mysql_error())) {echo "Status Nummer $statusID erfolgreich aktualisiert!";}
                                          
    echo "<br />---".$bearbeiter[$i]." ---<br />";
                                          echo 
    $sql;
                                          
    next($bearbeiterarray);
                                        }
                                } 
    that way i do.
    Let's say bearbeiterarray[18] contains Klaus K.
    so bearbeiter outputs Klaus K.
    but bearbeiter[$i] outputs ONLY K (which pretty much is the FIRST char of that string)
    i tested it with multiple different strings, it always outputs the very first Char
    and i don't have a clue WHY it does.
    SlayMan,
    Your friendly neighbourhood trainee and webmaster
    go, see for yourself @ http://www.alpupp.de

  2. #2
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is because your "bearbeiter" variable is previously initialized as sting.

    PHP Code:
    $bearbeiterarray = array("lorem""ipsum""dolor""sit""amet");

    $bearbeiter "wurscht"// *** 

    for($i=0;$i<count($bearbeiterarray);$i++)
    {
        
    var_dump($bearbeiter);    echo "<br>";

        
    $themaBID[$i]=key($bearbeiterarray);
        
    $bearbeiter[$i]=current($bearbeiterarray);
        
    $sql="UPDATE todo_status SET `bearbeiter`='".$bearbeiter[$i]."' WHERE `statusID`='".$themaSID[$i]."' LIMIT 1";
        echo 
    $sql;echo "<br>";
        
    next($bearbeiterarray);

    Comment out the "***" line and see the difference.

  3. #3
    SitePoint Enthusiast SlayMan's Avatar
    Join Date
    Oct 2004
    Location
    Germany/ Hamburg
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    haven't thought about that, u r right my document is a hue including file, i am with sure i am able to locate the previous definition of $bearbeiter ,
    by the way : $bearbeiter = "wurscht"; // *** looks like u can speak german very well :-)
    SlayMan,
    Your friendly neighbourhood trainee and webmaster
    go, see for yourself @ http://www.alpupp.de


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
  •