blueman378 Posted June 4, 2008 Share Posted June 4, 2008 hi guys, well i have a function inside a class, and if i call it through: $prodadmin->view_prod($cid); it will show only the products from the category with the id cid, however if i call it as $prodadmin->view_prod(); it gets all products, this is what i want however i get an error saying missing arguements, so i call it as @$prodadmin->view_prod(); that way i dont have to have two functions, and it doesnt show the error, is it ok to do this or should i just write two codes? Link to comment https://forums.phpfreaks.com/topic/108677-ok-to-do/ Share on other sites More sharing options...
trq Posted June 4, 2008 Share Posted June 4, 2008 You'll want to use null as a default then check this within your function to execute the appropriate query. eg; <?php function view_prod($id=null) { if (is_null($id)) { $sql = "SELECT * FROM foo"; } else { $sql = "SELECT * FROM foo WHERE id = $id"; } // ... } ?> Link to comment https://forums.phpfreaks.com/topic/108677-ok-to-do/#findComment-557410 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.