...

View Full Version : Help I can't see what I'm doing wrong



markspark100
07-10-2009, 07:07 PM
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 :confused:

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.


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 />";
}

tomws
07-10-2009, 07:27 PM
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:


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 />";
}

markspark100
07-10-2009, 07:38 PM
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

tomws
07-10-2009, 08:01 PM
What output are you getting? Error reporting on? Otherwise, no errors in server logs?

Here's the way to concat the array variables:

$oldquantity1 = mysql_query("SELECT Quantity FROM modifiers WHERE ProductCode = '".$row['ItemCode']."' AND ModifierValue = '".$row['name']."' ");

markspark100
07-10-2009, 09:15 PM
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 :confused:

Cheers

tomws
07-10-2009, 10:04 PM
but for some reason the query doesn't seem to acknowledge it.


What does this mean?

markspark100
07-11-2009, 12:21 AM
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 :confused:.

O well problem solved.

Again thanks for the help.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum