Hi David,
In the code below I cannot get the select query to work, it just won't see the variable, any ideas what I'm doing wrong. I'm not even sure the whole block is right.
Thanks
David
<?php
require("MagicParser.php");
function myRecordHandler($item)
{
$provider = $item["PROVIDER"];
global $provider;
if ($item["STATUS-ID"] == 2)
{
$query = "SELECT * FROM mytable WHERE provider LIKE '$provider'";
$result=mysql_query($query) or die("Couldn't execute query");
while ($row = mysql_fetch_array ($result)) {
echo "<TR>";
echo "<TD WIDTH=75 align='center'><div align='center'><a class='style1' href='/jump.php?id=" . $row['id'] . "' target='blank'><img src='" . $row['image'] . "' alt='" . $row['title'] . "'/></a></div></TD>";
echo "<TD WIDTH=300 ><div class='package'><h1><a class='style1' href='jump.php?id=" . $row['id'] . "' target='blank'>" . $row['title'] . "</a></h1>" . $row['package'] . "</div></TD>";
echo "<TD WIDTH=75 class='speed' align='center'>" . $row['speed'] .'MB'. "</TD>";
if ($row['usagelimit'] == 999)
echo "<TD WIDTH=75 class='usage' align='center'>".'No Limit'."</TD>";
else
echo "<TD WIDTH=75 class='usage' align='center'>" . $row['usagelimit'] . "GB</TD>";
if ($row['price'] == 0)
echo "<TD WIDTH=75 class='price' align='center'>".'FREE'."</TD>";
else
echo "<TD WIDTH=75 class='price'align='center'>" .'£'. $row['price'] . "</TD>";
//echo "<TD WIDTH=75 align='center'><a href='/jump.php?id=" . $row['id'] . "&track=$track'><img src='images/more1.gif' /></a></TD>";
echo "<TD WIDTH=75 align='center'><a href='/jump.php?id=" . $row['id'] . "' target='blank'><img src='images/moreblue.gif' /></a></TD>";
//echo "<TD WIDTH=75 align='center'><a href='/jump.php?id=" . $row['id'] . "'><img src='images/moreblue.gif' /></a><br><br><img src='images/3.5stars.png' /></TD>";
//echo "<TD WIDTH=75 align='center'>" . $row['url'] . "</TD>";
echo "</TR>";
}
echo "</TABLE>";
}
}
MagicParser_parse("check.xml","myRecordHandler","xml|RESULTS/CHECKS/CHECK/");
?>
Thanks David,
It shows what i thought in that the $provider variable (in this case BT ADSL) is not being passed through to the select query?
Array ( [CHECK] => [CHECK-ID] => adsl [PROVIDER] => BT ADSL [TYPE] => BT xDSL [STATUS] => Enabled [STATUS-ID] => 2 [SERVICE] => Normal [SERVICE-ID] => 4 [ENABLEDATE] => 2002-05-31 [UPDATED] => 2007-02-08 [ERROR] => None [ERROR-ID] => 0 ) SQL: SELECT * FROM mytable WHERE provider LIKE ''
Thanks for your help so far, any ideas?
David
Hi David,
I've just tested this - the problem is the following line:
global $provider;
Because this apears after you have set $provider = $item["PROVIDER"]; it is "reset" within the function. This line needs to go at the very top of the function, before any code...
Cheers,
David.
Hi David,
I would add some debug code to:
a) print out the contents of $record to confirm that PROVIDER is there...
b) print out the SQL.
Here's your script with this debug code, which exits after printing out the messages:
<?php
require("MagicParser.php");
function myRecordHandler($item)
{
print_r($item);
$provider = $item["PROVIDER"];
global $provider;
if ($item["STATUS-ID"] == 2)
{
$query = "SELECT * FROM mytable WHERE provider LIKE '$provider'";
print "SQL: ".$query;
exit();
$result=mysql_query($query) or die("Couldn't execute query");
while ($row = mysql_fetch_array ($result)) {
echo "<TR>";
echo "<TD WIDTH=75 align='center'><div align='center'><a class='style1' href='/jump.php?id=" . $row['id'] . "' target='blank'><img src='" . $row['image'] . "' alt='" . $row['title'] . "'/></a></div></TD>";
echo "<TD WIDTH=300 ><div class='package'><h1><a class='style1' href='jump.php?id=" . $row['id'] . "' target='blank'>" . $row['title'] . "</a></h1>" . $row['package'] . "</div></TD>";
echo "<TD WIDTH=75 class='speed' align='center'>" . $row['speed'] .'MB'. "</TD>";
if ($row['usagelimit'] == 999)
echo "<TD WIDTH=75 class='usage' align='center'>".'No Limit'."</TD>";
else
echo "<TD WIDTH=75 class='usage' align='center'>" . $row['usagelimit'] . "GB</TD>";
if ($row['price'] == 0)
echo "<TD WIDTH=75 class='price' align='center'>".'FREE'."</TD>";
else
echo "<TD WIDTH=75 class='price'align='center'>" .'£'. $row['price'] . "</TD>";
//echo "<TD WIDTH=75 align='center'><a href='/jump.php?id=" . $row['id'] . "&track=$track'><img src='images/more1.gif' /></a></TD>";
echo "<TD WIDTH=75 align='center'><a href='/jump.php?id=" . $row['id'] . "' target='blank'><img src='images/moreblue.gif' /></a></TD>";
//echo "<TD WIDTH=75 align='center'><a href='/jump.php?id=" . $row['id'] . "'><img src='images/moreblue.gif' /></a><br><br><img src='images/3.5stars.png' /></TD>";
//echo "<TD WIDTH=75 align='center'>" . $row['url'] . "</TD>";
echo "</TR>";
}
echo "</TABLE>";
}
}
MagicParser_parse("check.xml","myRecordHandler","xml|RESULTS/CHECKS/CHECK/");
?>
Does the output produced by this help?
Cheers,
David.