Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 21

Thread: unset problem

  1. #11
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    I will look at that more closely when I get home, but if you think something could be interfering then put the "deleting" code on a separate page, by itself, and see if it works then. If it does, than something is interfering within the main script.

  2. The Following User Says Thank You to traq For This Useful Post:

    I am Abby (05-04-2010)

  3. #12
    Join Date
    Apr 2010
    Location
    University of Illinois
    Posts
    86
    Thanks
    13
    Thanked 2 Times in 2 Posts

    Default

    After getting rid of the other php code, I still had the same problem.

  4. #13
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    keep troubleshooting...

    PHP Code:
    // Deleting an Announcement)
    if ( $_POST['deletechecker'] == )
    {
    // check that the code is being triggered
    echo $_POST['deletechecker'];

    //    $dcount = array();
    //  the above line IS COMMENTED OUT in your script, correct?

        
    $dcount $_POST["dcount"];
    //  Check that we're getting the correct $dcount value
        
    echo $dcount;

        
    $file '../sidebar.xml';
        
    $xml simplexml_load_file($file);

    $i 0;
    foreach(
    $xml as $kid){
    // see what we're comparing $dcount to each time
        
    echo $kid->id;

        if(
    $kid->id == $dcount){
    //  see if script finds a match
    echo $kid->id.' is equal to '.$dcount;
    // make sure it's the right entry
    echo $xml->myquotes[$i];

            unset(
    $xml->myquotes[$i]); break;
        }
        
    $i ++;
    }

    $xml $xml->asXML($file);  


  5. #14
    Join Date
    Apr 2010
    Location
    University of Illinois
    Posts
    86
    Thanks
    13
    Thanked 2 Times in 2 Posts

    Default

    I think I found the problem but do not understand.

    when I echo $dcount, the reply is "Array" and becuase of this it is never equal to $kid->id.

    The question is why is $dcount = Array instead of being an array?
    I saw this before which lead me to comment out "$dcount = array();"
    Last edited by I am Abby; 05-04-2010 at 04:28 PM. Reason: add more inforamtion

  6. #15
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    It IS an array. That's what you want. "echo" can only work with strings.
    When you use "echo"+[non-string] the result will be a warning of sorts, like "array" or "resource" (for something like a mysql query).

    (array(1)==array(1)) is true.
    (array(1)==array(2)) is false.

    There's no reason you can't match arrays.

    But if you want to "echo" an array, you need to use another function. The common one is print_r($array);.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. The Following User Says Thank You to djr33 For This Useful Post:

    I am Abby (05-04-2010)

  8. #16
    Join Date
    Apr 2010
    Location
    University of Illinois
    Posts
    86
    Thanks
    13
    Thanked 2 Times in 2 Posts

    Default

    Code:
    print_r($dcount)
    worked fine.

    So the problem seems to be on the line
    Code:
    if($kid->id == $dcount);
    when I do an echo
    Code:
    $kid->id;
    I get nothing back.

    Or is the problem with the foreach line
    Code:
    foreach($xml as $kid){
    I get no response from
    Code:
    echo $kid;

  9. #17
    Join Date
    Apr 2010
    Location
    University of Illinois
    Posts
    86
    Thanks
    13
    Thanked 2 Times in 2 Posts

    Default

    The problem has to be in the if statements. I just changed it to a not equal statement and echoed "hello" which was triggered for every record in my .xml file.

    To echo on an array you had to do the print_r($array)...do we also need a trick for using them in if statements?

    something like
    Code:
    if(in_array($kid->id, $dcount))

  10. #18
    Join Date
    Apr 2010
    Location
    University of Illinois
    Posts
    86
    Thanks
    13
    Thanked 2 Times in 2 Posts

    Default

    I love you guys. It works!

  11. #19
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    I thought that might be the problem - we added that a while back because you might have had multiple entries to delete. But then, I saw that the $dcount = array(); line was commented out, so I figured it was something else. But it's still an array because your html inputs are named "dcount[]". Duh.

    I'm glad you got it figured out!

  12. #20
    Join Date
    Apr 2010
    Location
    University of Illinois
    Posts
    86
    Thanks
    13
    Thanked 2 Times in 2 Posts

    Default

    Quote Originally Posted by traq View Post
    I thought that might be the problem - we added that a while back because you might have had multiple entries to delete. But then, I saw that the $dcount = array(); line was commented out, so I figured it was something else. But it's still an array because your html inputs are named "dcount[]". Duh.
    I wondered why I didn't need the
    Code:
    $dcount = array();
    when I had to have it with the counter array. This is a good site to learn...thanks.

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
  •