below is my code through which I'm trying get certain values to a drop down box from a SQL database. I'm also trying to exclude some of the data before loading to the dropdown box.
In my code $excld[] works fine and the expected zero values are not shown when the dropdown is populated, but the values I expect to exclude via $exclude=$rec['chkNum']; doesn't work, or else the values I dont want to be in the dropdown still shows. Can someone tell me is there anything wrong in the approach?
thanks.
$exclude = array();
$query = "SELECT * FROM invoentry WHERE dist_inv='$distUsr'";
$runx=mysqli_query($db,$query) or die ("SQL Error");
$norx=mysqli_num_rows($runx);
while ($rec = mysqli_fetch_array($runx))
{
$exclude[] = $rec['chkNum']; $excld[] = '0';
}
$SQLx="SELECT * FROM newchk WHERE dist_chk='$distUsr'";
$runx=mysqli_query($db,$SQLx) or die ("SQL Error");
$norx=mysqli_num_rows($runx);
while ($rec = mysqli_fetch_array($runx))
{
if($rec['sbstart'] != '0' & $rec['sbend'] != '0') {
for($i=$rec['sbstart']; $i<=$rec['sbend']; $i++)
{
if (!in_array($i, $exclude, $excld))
{
echo "<option id='options' value='$i'>$i<br></option>";
}
} }
if($rec['gwstart'] != '0' & $rec['gwend'] != '0') {
for($i=$rec['gwstart']; $i<=$rec['gwend']; $i++)
{
if (!in_array($i, $exclude, $excld))
{
echo "<option id='options' value='$i'>$i<br></option>";
}
} }
}
EDIT :
Database structure is as follows; Database name :regional_data Two tables in the same database invoentry and newchk
invoentry:
usr_inv dist_inv chkNum InvoNum
---------------------------------
John Guardian 300455 457gXT
newchk:
usr_chk dist_chk sbstart sbend totsb gwstart gwend totgw
----------------------------------------------------------
John Guardian 300400 300550 151 300 310 10
invoentryandnewchktables? There's probably a pure-SQL solution to this problem.$excld, why you are using bitwise&, why$excludeis used to filtersbstart,sbend,gwstart, andgwend.<option>tags don't typically getidattributes, and if they do, allidvalues in an HTML document must be unique. Your sample data only contains one row per table; might there be more than one from either table? It is unnecessary to duplicate an option's text as itsvalueattribute - you can safely omit thevaluedeclaration.