dazzclub Posted March 26, 2009 Share Posted March 26, 2009 Hi guys and girls, I am trying to write a function along the lines of... get variables from url, use to retrieve from a database and update pages title, if not use the default tiltle instead. The ones i cant retrieve from the database will display their own title, these default titles will be set in the page with their own variable; $page_title = 'Home page'; Here is what i have got so far function pageTitle() { if ((isset($_GET['medical_product'])) && (isset($_GET['subcat_id'])) && (is_numeric($_GET['medical_product'])) && (is_numeric($_GET['subcat_id']))) { //correctly accessed $medical_product=$_GET['medical_product']; $subcat_id=$_GET['subcat_id']; } else { $errors[] = 'You have accessed this page incorrectly.'; } global $dbc; $query="SELECT * FROM SubCat1 WHERE CategoryID = $medical_product AND SubCatID = $subcat_id"; $result = mysqli_query ($dbc, $query)or die(mysqli_error() . "<p>With query:<br>$query"); while ($row = mysqli_fetch_array($result)) { echo "$row[subCatName]"; } } I'm struggling to find where to put my else statment to display the default title Default title i.e else { $page_title; } Thanks for any help Quote Link to comment Share on other sites More sharing options...
mrfitz Posted March 27, 2009 Share Posted March 27, 2009 ??? ???First problem is what is "mysqli_query" that is an invalid function. mrfitz Quote Link to comment Share on other sites More sharing options...
btherl Posted March 27, 2009 Share Posted March 27, 2009 You can use mysqli_num_rows() to see how many rows are in the result, and use that for your if statement. mrfitx, mysqli is "mysql improved" Quote Link to comment Share on other sites More sharing options...
dazzclub Posted March 27, 2009 Author Share Posted March 27, 2009 Hi guys, Thanks for your advice. What i went with at the end was switch statment. If the function couldnt grab the right vairables from the url the swtich statment will look for a variable called $action which i placed in the urls. index.php?action=news So my final code now looks like this function pageTitle() { if ((isset($_GET['medical_product'])) && (isset($_GET['subcat_id'])) && (is_numeric($_GET['medical_product'])) && (is_numeric($_GET['subcat_id']))) { //correctly accessed $medical_product=$_GET['medical_product']; $subcat_id=$_GET['subcat_id']; global $dbc; $query="SELECT * FROM SubCat1 WHERE CategoryID = $medical_product AND SubCatID = $subcat_id"; $result = mysqli_query ($dbc, $query)or die(mysqli_error() . "<p>With query:<br>$query"); while ($row = mysqli_fetch_array($result)) { echo "$row[subCatName]"; } } else { switch ($_GET['action']) { case 'about'; echo ' - about us'; break; case 'news'; echo ' - read all the latest news and our press release'; break; case 'contact'; echo ' - make an enquiry'; break; case 'quality'; echo ' - quality'; break; case 'home'; echo 'default title'; break; } } } If you still see areas of improvement then please let me know, im only a new-b Thank you Quote Link to comment Share on other sites More sharing options...
dazzclub Posted March 27, 2009 Author Share Posted March 27, 2009 i need to come back to this and sort it out, double check the variables to make sure they are string. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.