I'm trying to work something out but I just can't get it to work. I need to do the following:
- Pull data from a MySQL Table
- Store that data in an array
- Use that data from the array in a Function.
Current code looks like this (currently pulls data from MySQL Table and iterates over it, putting it in a table (purely to check it worked).
mysql_connect("localhost", "*****", "*****") or die(mysql_error());
mysql_select_db("*****") or die(mysql_error());
$data = mysql_query("SELECT batch FROM widgetBatches") or die(mysql_error());
Print "<table border cellpadding=3>";
while($info = mysql_fetch_array( $data )) { Print "<tr>";
Print "<th>Batch:</th> <td>".$info['batch'] . "</td> ";
Print "" . " </td></tr>";
} Print "</table>";
Here's the function, $widgetBatches needs to take the array from the previous code however nothing i've tried works. (there is more to the Widget() however it's not relevant to this issue. Thanks in advance!
$uI = 550;
Widget($uI);
function Widget($input) {
$currentValue = $input;
$i = 0;
$widgetBatches = [250, 500, 1000, 2000];
while ($currentValue > 0) {
$i++;
echo "Batch Number " . $i . "<br/>";
echo "Widgets Left To Fulfill Order: " . $currentValue . "<br/>";
$closest = ClosestBatch($widgetBatches, $currentValue);
echo "Closest Batch Available: " . $closest . "<br/>";
$currentValue = $currentValue - $closest;
echo "Remaining Widgets: " . abs($currentValue) . "<hr/>";
}
echo "<br />";
}