Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looking for some feedback here

Status
Not open for further replies.

phpPete

Programmer
Feb 25, 2002
88
US
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(&quot;../../include/phpClasses/MyConnect.php&quot;);
new MyConnect();
$theCode = &quot;id3cc575193&quot;;//will be $_POST['recCode']


$sql = &quot;SELECT rec_ingredient FROM recipe_ingredient_data WHERE rec_code
='&quot; . $theCode . &quot;'&quot;;
$rs = mysql_query($sql) or die(mysql_error());

$sql2 = &quot;SELECT ingredient, gross_cost FROM ingredient&quot;;
$rss = mysql_query( $sql2 ) or die( mysql_error());


//declare global arrays
$GLOBALS[&quot;ALL&quot;] = array();
$GLOBALS[&quot;REC&quot;] = 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(&quot;<BR><BR>rCode[5][0]== &quot; .$rCode[5][0]);

//spit out some test data
echo(&quot;<BR><BR>Rec Array Sample: &quot; . $REC[4][0] . &quot;\n&quot;);
echo(&quot;<BR>All ingredients array sample: &quot; . $ALL[0][0] . &quot;<BR><BR>\n&quot;);
?>

//diagnostic data
Number of ingredients is: <?= $numIngreds .&quot;<BR>\n&quot;?>
Number of Recipe Ingredients is: <?= $numRecIngreds .&quot;<BR>\n&quot;?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top