mercredi 23 mars 2016

Error in a LOOP for a condition in PHP/MYSQL

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.

Aucun commentaire:

Enregistrer un commentaire