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 2009
    Location
    Birmingham, England
    Posts
    59
    Thanks
    5
    Thanked 6 Times in 6 Posts

    Help I can't see what I'm doing wrong

    I'm trying to take data from an XML file to update my database.
    I can get the relevant data from the XML and I've put it into an array called items which looks like this:
    Array (
    [0] =>
    Array ( [ItemName] => Flower [ItemCode] => az-1030 [Quantity] => 2 )
    [1] =>
    Array ( [ItemName] => Black / Yellow [ItemCode] => pet-ti [Quantity] => 1 )
    [2] => Array ( [ItemName] => Techno [ItemCode] => az-1030 [Quantity] => 1 )
    )
    Then I'm using the code below which doesn't return any errors but doesn't retrieve the data from the database even though it succesfully echo's the bits i'm using for the where clauses

    Any help would be really appreciated as I'm so stumped right now especially as I've done something pretty much identical before and I've looked at that code and can't see what's different.
    Code:
    foreach($items as $row)
    {
    $oldquantity1 = mysql_query("SELECT Quantity FROM modifiers WHERE ProductCode = '$row[ItemCode]' AND ModifierValue = '$row[name]' ");
    $oldquantity = mysql_fetch_array($oldquantity1);
    $newquantity = $oldquantity[0] - $row[Quantity];
    echo"$row[ItemCode]";
    echo"<br /> $oldquantity[0] <br /> $newquantity<br />";
    }
    Last edited by markspark100; 07-10-2009 at 08:10 PM.

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    I'm surprised you're not getting any errors. You're using the array notation $row[ItemCode] inside a string incorrectly. It needs to either be concatenated or wrapped in curly braces. The field names also need a quote wrap. Like this:
    Code:
    foreach($items as $row)
    {
    $oldquantity1 = mysql_query("SELECT Quantity FROM modifiers WHERE ProductCode = '{$row['ItemCode']}' AND ModifierValue = '{$row['name']}' ");
    $oldquantity = mysql_fetch_array($oldquantity1);
    $newquantity = $oldquantity[0] - $row['Quantity'];
    echo"{$row['ItemCode']}";
    echo"<br /> $oldquantity[0] <br /> $newquantity<br />";
    }
    Last edited by tomws; 07-10-2009 at 08:28 PM. Reason: fixed my missing quotes
    Are you a Help Vampire?

  • #3
    New Coder
    Join Date
    May 2009
    Location
    Birmingham, England
    Posts
    59
    Thanks
    5
    Thanked 6 Times in 6 Posts
    Thanks Tomws, but It's still outputting the exact same thing as before, still with no errors.

    What did you mean about concatenating it?

    cheers

  • #4
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    What output are you getting? Error reporting on? Otherwise, no errors in server logs?

    Here's the way to concat the array variables:
    PHP Code:
    $oldquantity1 mysql_query("SELECT Quantity FROM modifiers WHERE ProductCode = '".$row['ItemCode']."' AND ModifierValue = '".$row['name']."' "); 
    Are you a Help Vampire?

  • #5
    New Coder
    Join Date
    May 2009
    Location
    Birmingham, England
    Posts
    59
    Thanks
    5
    Thanked 6 Times in 6 Posts
    I'm getting the output I expect to apart from the result of the query.
    ie where i'eve put echo"$row[itemcode]"; it shows the value I expect but for some reason the query doesn't seem to acknowledge it.
    No error reporting's not off because I have been trying different things some of which have bee outputing errors.
    Like I said I've done something exactly the same before which I'm comparing this to but I can't see any differences.
    And if I replace the array with the code I know is in the array it works fine so it's communicating properly with the Database

    Cheers

  • #6
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Quote Originally Posted by markspark100 View Post
    but for some reason the query doesn't seem to acknowledge it.
    What does this mean?
    Are you a Help Vampire?

  • #7
    New Coder
    Join Date
    May 2009
    Location
    Birmingham, England
    Posts
    59
    Thanks
    5
    Thanked 6 Times in 6 Posts
    tomws,

    Thanks for the help but I've solved it... I trimmed the data receive from the XML before adding it the array and that seemed to solve the problem even though as far as I can tell there is no whitespace at either the start or end .

    O well problem solved.

    Again thanks for the help.


  •  

    Posting Permissions

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