Am I on the right track here?
The jist of this is that ultimately I want to set up a select box that's
pre-selected with data already in the DB.
The reason for the 2 queries is this:
i only want to allow my user to choose what's available in the DB
obviously, but also, a new election will need to update the database with
pricing data specific to the selected ingredient. As pricing data is
stored in only one place, the "ingredient" table, that data needs to go
into the UPDATE.
<?php
include("../../include/phpClasses/MyConnect.php"
new MyConnect();
$theCode = "id3cc575193";//will be $_POST['recCode']
$sql = "SELECT rec_ingredient FROM recipe_ingredient_data WHERE rec_code
='" . $theCode . "'";
$rs = mysql_query($sql) or die(mysql_error());
$sql2 = "SELECT ingredient, gross_cost FROM ingredient";
$rss = mysql_query( $sql2 ) or die( mysql_error());
//declare global arrays
$GLOBALS["ALL"] = array();
$GLOBALS["REC"] = array();
//declare counter variable
$counterVal = 0;
//place this recipes' ingredients into an array with GLOBAL SCOPE
while($rec_ing = mysql_fetch_array( $rs ))
{
$REC[$counterVal] = $rec_ing;
$counterVal++;
}
//re-set counter variable
$counterVal = 0;
//place ALL ingredients into an array with GLOBAL SCOPE
while($all_ing = mysql_fetch_array( $rss)) {
$ALL[$counterVal] = $all_ing;
$counterVal++;
}
//determine the number of elements in each array
$numIngreds = count($ALL);
$numRecIngreds = count($REC);
// determine the elements common to both arrays
$rCode = array_intersect($REC, $ALL);
//print out the values from the intersection so we can see what we have
here
print_r( $rCode);
//access a specififc element of the intersection
echo("<BR><BR>rCode[5][0]== " .$rCode[5][0]);
//spit out some test data
echo("<BR><BR>Rec Array Sample: " . $REC[4][0] . "\n"
echo("<BR>All ingredients array sample: " . $ALL[0][0] . "<BR><BR>\n"
?>
//diagnostic data
Number of ingredients is: <?= $numIngreds ."<BR>\n"?>
Number of Recipe Ingredients is: <?= $numRecIngreds ."<BR>\n"?>
The jist of this is that ultimately I want to set up a select box that's
pre-selected with data already in the DB.
The reason for the 2 queries is this:
i only want to allow my user to choose what's available in the DB
obviously, but also, a new election will need to update the database with
pricing data specific to the selected ingredient. As pricing data is
stored in only one place, the "ingredient" table, that data needs to go
into the UPDATE.
<?php
include("../../include/phpClasses/MyConnect.php"
new MyConnect();
$theCode = "id3cc575193";//will be $_POST['recCode']
$sql = "SELECT rec_ingredient FROM recipe_ingredient_data WHERE rec_code
='" . $theCode . "'";
$rs = mysql_query($sql) or die(mysql_error());
$sql2 = "SELECT ingredient, gross_cost FROM ingredient";
$rss = mysql_query( $sql2 ) or die( mysql_error());
//declare global arrays
$GLOBALS["ALL"] = array();
$GLOBALS["REC"] = array();
//declare counter variable
$counterVal = 0;
//place this recipes' ingredients into an array with GLOBAL SCOPE
while($rec_ing = mysql_fetch_array( $rs ))
{
$REC[$counterVal] = $rec_ing;
$counterVal++;
}
//re-set counter variable
$counterVal = 0;
//place ALL ingredients into an array with GLOBAL SCOPE
while($all_ing = mysql_fetch_array( $rss)) {
$ALL[$counterVal] = $all_ing;
$counterVal++;
}
//determine the number of elements in each array
$numIngreds = count($ALL);
$numRecIngreds = count($REC);
// determine the elements common to both arrays
$rCode = array_intersect($REC, $ALL);
//print out the values from the intersection so we can see what we have
here
print_r( $rCode);
//access a specififc element of the intersection
echo("<BR><BR>rCode[5][0]== " .$rCode[5][0]);
//spit out some test data
echo("<BR><BR>Rec Array Sample: " . $REC[4][0] . "\n"
echo("<BR>All ingredients array sample: " . $ALL[0][0] . "<BR><BR>\n"
?>
//diagnostic data
Number of ingredients is: <?= $numIngreds ."<BR>\n"?>
Number of Recipe Ingredients is: <?= $numRecIngreds ."<BR>\n"?>