I am trying to get an output pertaining to some conditions with a query and IF condition. Just want to know, is this the correct way to achieve the result or is there a better way. The following script doesnt execute correctly at times. If you see my php script, you will be clear on what iam trying to do. Pls help me on the same.
$query_slab1 = mysql_query("SELECT slab_range,sup_itempartno FROM quotation_items where tender_id='$tender_id' ");
if ($result_slab1 = mysql_fetch_array($query_slab1)){
if (($result_slab1['slab_range'] == "") && ($result_slab1['sup_itempartno'] == "")){
echo 'NO SLAB RANGE or NO PART NUMBER';
}
else if (($result_slab1['slab_range'] !== "") && ($result_slab1['sup_itempartno'] !== "")){
echo 'SLAB RANGE and PART NUMBER EXISTS';
}
else if (($result_slab1['slab_range'] == "") || ($result_slab1['sup_itempartno'] !== "")){
echo 'SLAB RANGE is NOT THERE and PART NUMBER EXISTS';
}
else if (($result_slab1['slab_range'] !== "") && ($result_slab1['sup_itempartno'] == "")){
echo 'SLAB RANGE EXISTS and PART NUMBER IS NOT THERE';
}
else {
echo 'NO ITEMS FOUND IN THE DB';
}
}
Im just checking in the rows if Slab Range or Part Number exists. If both exists it's a different echo, if both doesnt exists its a different echo or if any one exists or not its a different echo. As of now its just checking the first record. How will i add a for loop or a while loop here to check all the records and give a display as per that.
These are the expected results iam trying to achieve.
=========================================
tender_id | slab_range | sub_itempartno
=========================================
15001 ABCDE
15001 1-2 AMKOI
15001 5-6 OUIPR
15004
15004 CVIOU
15005
15005
15005
15009
15009 8-9
15009 6-9
Result for 15001 is 'SLAB RANGE AND PART NUMBER EXISTS' since when i iterete through the rows i can find both slab_range and sub_itempartno ENTERED.
Result for 15004 is 'SLAB RANGE DOESNT EXIST AND PART NUMBER EXISTS' since when i iterete ethrough the rows i can find both slab_range empty or null and sub_itempartno ENTERED.
Result for 15005 is 'SLAB RANGE AND PART NUMBER DOES NOT EXIST' since when i iterete through the rows i can find both slab_range and sub_itempartno NOT ENTERED.
Result for 15009 is 'SLAB RANGE EXISTS AND PART NUMBER DOES NOT EXIST' since when i iterete through the rows i can find slab_range ENTERED and sub_itempartno NOT ENTERED.