I have this function with a search box.
There has to be a bu, the other search criteria are optional except if you do search
by zonenumber you have to have the zoneid as well. The sql pulls from 2 tables
inventory and link. You can see the filter for these searches works.
If all goes well there is a match in the link table.
This page works except one small problem. If there are errors then there is no match in the related table. So I only want the table with the column names to display the 3 columns from the inventory table only: bu, ndc and error_flag instead of adding the other columns from the related table. I can't figure out how to eliminate that from displaying when the error_flag value is 1. As I said it works with the error_flag as 0.
I have tried adding an if(error_flag==1)
{ table with column names & while loop with just those 3 columns } in several places on this page and can't figure out how to get the display to be correct in the case there is no match on the ndc. I just want to display the 3 columns and allow the user to enter the correct ndc. I would love the page numbers to be correct but in this case I'll settle for just getting the right columns to display when there is an error.:evilgrin::evilgrin:
session_start();
function get_it(){
error_reporting(E_ALL ^ E_NOTICE);
$page=$_GET['page'];
if ( $_GET['order']=="" ) {
$order="bu";
}else{
$order=$_GET['order'];
}
//search criteria
//zoneid and zonenm must be searched on together
//bu is required for all searches
$bu= $_POST['search_bu'];
$cart_id =$_POST['search_cart_id'];
$zoneid= $_POST['search_zoneid'];
$zonenm= $_POST['search_zonenm'];
$ndc=$_POST['search_ndc'];
$error_flag=$_POST['search_error_flag'];
echo "<form action='$me' method='post'>";
echo "<table align='center' style='border:1px solid $CCCCCC;'>\n";
echo "<th align='right'>BU\n";
echo "<td><select name='search_bu'>\n";
get_bu();
echo "</select>\n";
echo "<tr>\n";
echo "<th align='right'>Cart ID\n";
echo "<td><input type'text' name='search_cart_id' size='10' class='txt1'>\n";
echo "<tr>\n";
echo "<th align='right'>Zone ID\n";
echo "<td><input type'text' name='search_zoneid' size='9' class='txt1'>\n";
echo "<tr>\n";
echo "<th align='right'>Zone Number\n";
echo "<td><input type'text' name='search_zonenm' size='9' class='txt1'>\n";
echo "<tr>\n";
echo "<th align='right'>NDC\n";
echo "<td><input type'text' name='search_ndc' size='10' class='txt1'>\n";
echo "<tr>\n";
echo "<th align='right'>Error Flag\n";
echo "<td><input type='radio' name='search_error_flag' class='rad1' value ='1' >Yes\n";
echo "<td><input type='radio' name ='search_error_flag' class='rad1' value='0'>No\n";
echo "<tr>\n";
echo "<td colspan='13' align='center'><input type='submit' value='Search'>\n";
echo "</table>\n";
echo "<tr>\n";
echo "</form>";
echo "---$error_flag---";
$sql="SELECT DISTINCT bu, cart_id, ndc, error_flag, item_id, description, upc, ndc_uom, std_uom ";
$sql.="FROM inventory, link ";
$sqlWhere="WHERE ndc=ndc ";
if ($bu!=''){ $sqlWhere.="AND bu ='$bu' ";}
if ($cart_id !='') { $sqlWhere.="AND cart_id='$cart_id' ";}
if (($zoneid !='') && ($zonenm!='')) { $sqlWhere.="AND zoneid ='$zoneid'AND zonenm='$zonenm' ";}
if ( $error_flag==0){$sqlWhere.="AND error_flag='$error_flag' ";}
$sqlOrder="ORDER BY $order ";
echo nrows($sql);
if( $page=='' ){
$nRecs=nrows($sql);
$_SESSION['recs']==$nRecs;
$startPage=25;
}else{
$startPage=$page *25;
}
//$sql.="LIMIT 50";
$sqlLimit="LIMIT $startPage,25";
$sql.= $sqlWhere . " " .$sqlOrder ." ". $sqlLimit ;
echo nrows($sql);
$result=mysql_query($sql);
if ( !$result ) {die("<font color='red'>Invalid query:</font>" . mysql_error() . "<br />$sql");}
//column names in first row in table
echo "<table align='center' style='border-collapse:collapse;'>\n";
echo "<td style='border:solid black 1px;padding:5px;'>\n";
if ( $order=='bu' ) { echo "<img src='images/downArrow.bmp'>"; }
echo "<th style='border:solid black 1px;padding:5px;'><a href='$me?order=bu'>bu</a>\n";
echo "<th style='border:solid black 1px;padding:5px;'><a href='$me?order=ndc'>ndc</a>\n";
if ( $order=='ndc' ) { echo "<img src='images/downArrow.bmp'>"; }
echo "<th style='border:solid black 1px;padding:5px;'><a href='$me?order=error_flag'>error_flag</a>\n";
if ( $order=='error_flag' ) { echo "<img src='images/downArrow.bmp'>"; }
echo "<th style='border:solid black 1px;padding:5px;'><a href='$me?order=item_id'>item_id</a>\n";
if ( $order=='item_id' ) { echo "<img src='images/downArrow.bmp'>"; }
echo "<th style='border:solid black 1px;padding:5px;'><a href='$me?order=description'>description</a>\n";
if ( $order=='description' ) { echo "<img src='images/downArrow.bmp'>"; }
echo "<th style='border:solid black 1px;padding:5px;'><a href='$me?order=upc'>upc</a>\n";
if ( $order=='upc' ) { echo "<img src='images/downArrow.bmp'>"; }
echo "<th style='border:solid black 1px;padding:5px;'><a href='$me?order=ndc_uom'>ndc_uom</a>\n";
if ( $order=='ndc_uom' ) { echo "<img src='images/downArrow.bmp'>"; }
echo "<th style='border:solid black 1px;padding:5px;'><a href='$me?order=std_uom'>std_uom</a>\n";
if ( $order=='std_uom' ) { echo "<img src='images/downArrow.bmp'>"; }
while ($row = mysql_fetch_array($result)) {
$bu=$row['bu'];
$ndc=$row['ndc'];
$error_flag=$row['error_flag'];
$item_id=$row['item_id'];
$description=$row['description'];
$upc=$row['upc'];
$ndc_uom=$row['ndc_uom'];
$std_uom=$row['std_uom'];
$cls=($cls=='gry') ? 'wht' : 'gry';
echo "<tr class='$cls'>\n";
echo "<td style='border:solid black 1px;padding:5px;'><input type='button' value='Save'>\n";
echo "<td style='border:solid black 1px;padding:5px;'>$bu\n";
echo "<td style='border:solid black 1px;padding:5px;'><input type='text' size='30' name='ndc' value='$ndc'>\n";
echo "<td style='border:solid black 1px;padding:5px;'>$error_flag\n";
echo "<td style='border:solid black 1px;padding:5px;'>$item_id\n";
echo "<td style='border:solid black 1px;padding:5px;'>$description\n";
echo "<td style='border:solid black 1px;padding:5px;'>$upc\n";
echo "<td style='border:solid black 1px;padding:5px;'>$ndc_uom\n";
echo "</select>\n";
echo "<td align='right' style='border:solid black 1px;padding:5px;'>$std_uom\n";
echo "</tr>\n";
}//while end
echo "</table>\n";
$noPages=$_SESSION['recs']/100;
echo $_SESSION['recs'];
for ( $p=1;$p<=$noPages;$p++ ) {
echo " <a href='$me?page=$p'>$p</a>\n";
}
//}
}//end function get it
So in other words, I only want to display these col header names with with the 3 column data in the while loop from the first table if
there error_flag = 1 in the filter but I don't know where to put the if ....
echo "<table align='center' style='border-collapse:collapse;'>\n";
echo "<td style='border:solid black 1px;padding:5px;'>\n";
if ( $order=='bu' ) { echo "<img src='images/downArrow.bmp'>"; }
echo "<th style='border:solid black 1px;padding:5px;'><a href='$me?order=bu'>bu</a>\n";
echo "<th style='border:solid black 1px;padding:5px;'><a href='$me?order=ndc'>ndc</a>\n";
if ( $order=='ndc' ) { echo "<img src='images/downArrow.bmp'>"; }
echo "<th style='border:solid black 1px;padding:5px;'><a href='$me?order=error_flag'>error_flag</a>\n";
while ($row = mysql_fetch_array($result)) {
$bu=$row['bu'];
$ndc=$row['ndc'];
$error_flag=$row['error_flag'];
$item_id=$row['item_id'];
$cls=($cls=='gry') ? 'wht' : 'gry';
echo "<tr class='$cls'>\n";
echo "<td style='border:solid black 1px;padding:5px;'><input type='button' value='Save'>\n";
echo "<td style='border:solid black 1px;padding:5px;'>$bu\n";
echo "<td style='border:solid black 1px;padding:5px;'><input type='text' size='30' name='ndc' value='$ndc'>\n";
echo "<td style='border:solid black 1px;padding:5px;'>$error_flag\n";
echo "</tr>\n";