I have simple php code here, where basically asking to display the value of query :

<?php
$table = "tbl_product";

/******************MULTIPLE QUERIES*******************/
 if($tbl_code==999){$condition = " WHERE (category = 'wellington') OR (category = 'hivis') OR (category = 'tools') OR (category = 'waterproof') ";}

else if($tbl_code==998){$condition = "  WHERE category = 'wellington' ";}
else if($tbl_code==997){$condition = "  WHERE category = 'hivis' ";}
else if($tbl_code==996){$condition = "  WHERE category = 'waterproof' ";}

else if($tbl_code==995){$condition = "  WHERE category = 'wellington' AND sub_category = 'women' ";}
else if($tbl_code==994){$condition = "  WHERE category = 'wellington' AND sub_category = 'cammo' ";}
else if($tbl_code==993){$condition = "  WHERE category = 'wellington' AND (sub_category = 'boy' OR sub_category = 'girl') ";}
else if($tbl_code==992){$condition = "  WHERE category = 'wellington' AND (sub_category = 'brandedmen' OR sub_category = 'brandedwomen') ";}
else if($tbl_code==991){$condition = "  WHERE category = 'wellington' AND sub_category = 'mens' ";}
else if($tbl_code==990){$condition = "  WHERE category = 'tools' AND sub_category = 'bags' ";}
else if($tbl_code==989){$condition = "  WHERE category = 'hivis' AND sub_category = 'men' ";}
else if($tbl_code==988){$condition = "  WHERE category = 'hivis' AND sub_category = 'women' ";}
else if($tbl_code==987){$condition = "  WHERE category = 'hivis' AND sub_category = 'kids' ";}
else if($tbl_code==986){$condition = "  WHERE category = 'waterproof' AND sub_category = 'men' ";}
else if($tbl_code==985){$condition = "  WHERE category = 'waterproof' AND sub_category = 'women' ";}
else if($tbl_code==984){$condition = "  WHERE category = 'waterproof' AND sub_category = 'kids' ";}

else if($tbl_code==983){$condition = "  WHERE category = 'hivis' AND sub_category = 'kids' ";}//new arrivals
else if($tbl_code==982){$condition = "  WHERE category = 'hivis' AND sub_category = 'kids' ";}//wholesale
else if($tbl_code==981){$condition = "  WHERE category = 'hivis' AND sub_category = 'kids' ";}//quickshipping
else if($tbl_code==980){$condition = "  WHERE category = 'hivis' AND sub_category = 'kids' ";}//with defect

else if($tbl_code==979){$condition = "  WHERE category = 'hivis' AND sub_category = 'kids' ";}
else if($tbl_code==978){$condition = "  WHERE category = 'hivis' AND sub_category = 'kids' ";}
else if($tbl_code==977){$condition = "  WHERE category = 'hivis' AND sub_category = 'kids' ";}
else if($tbl_code==976){$condition = "  WHERE category = 'hivis' AND sub_category = 'kids' ";}

else if($tbl_code==975){$condition = "  WHERE category = 'hivis' ";}
else if($tbl_code==974){$condition = "  WHERE category = 'wellington' AND (sub_category = 'cammo' OR sub_category = 'mens') ";}

else{ echo'<script>location.reload();</script>';}

?>

at first it works really great but when I'd tried to test every condition, It will send me on 404 error page. please check my code if I did a BAD programming here ! thnx =)

Recommended Answers

All 4 Replies

How does a query not working send you to a 404 (page not found) error?
Is the result being used to create a URL?
An incorrect SQl statement should generate a PHP error for you to view. Do you have display_errors on?

that is pretty nested. Try using switch statement.You can refactor the $tbl_code==976 to 983 as one query using PHP range function e.g. range(976,983).

range will give you an array. So, it would be nice if you can create a simple function to find out if the $tbl_code is in array to trigger the query.

yeah, yes sir it is used to create a url. i also have this code to force php to show if i have any error.

error_reporting(E_ALL);
ini_set('display_errors','1');

but suddenly it shows nothing, than sending me into 404 page..

veedeoo :
        the condition from 983 - 976 is just like a dummy, so far i prefer to use the same query just to know if the condition is working. and they really do.

  im sure that this is not the reason why query is sending me to 404 page, just because i have used to same query? or maybe i was wrong,



          what im trying to look is the $_SESSION. i know how to use session but not that deep. could you please tell me how sessions work. 





I end up hanging here -_-
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.