alemapo Posted May 24, 2009 Share Posted May 24, 2009 Hi, Experienced programmer in COBOL on AS400 - VERY newbie to web programming. Using Dreamweaver, MySQL and PHP. Question - is it possible to switch to a new page based on data from the database and not just from a link click. My situation is this - users can update records they have previously entered. They will click the record on the master page they want to update but the screen to call from the link will be different based on the type of record they are attempting to change. Very simple in the world I know but I'm not sure how to do in PHP. I thought to have the link call an external php function to determine which screen to call based on the type of record (they are different types of classifieds) but then I don't know how to "call" the correct screen. I have searched in PHP, Dreamweaver, and HTML but don't even know how to correctly search for this solution. Thanks! Pamela (Old dog trying to learn new tricks - well, maybe not that old ) Quote Link to comment https://forums.phpfreaks.com/topic/159504-solved-page-navigation/ Share on other sites More sharing options...
Maq Posted May 25, 2009 Share Posted May 25, 2009 So, in your table each record is assigned a classified type, and you want to call a certain page based on that type? Can you post your table structure and the different types? You can probably just query the database based on the record they click and see what the classified type is, then pass the type via http to determine what page should be called. Quote Link to comment https://forums.phpfreaks.com/topic/159504-solved-page-navigation/#findComment-841453 Share on other sites More sharing options...
alemapo Posted May 25, 2009 Author Share Posted May 25, 2009 Yes, that is exactly what I want to do. The column in my table for classified type is simply cls_type char(4) The four characters are such as AUTO, BIKE, PETS, JOBS etc. The key to this table is simply cls_id int(10) which is an auto_incremented integer. My link to the matching record in the table does give me the cls_type I need to determine the screen to call. I was thinking I would have to have the link call an external function and use either if's or case to determine the correct screen (or something like that). My very newbie question is once I have the correct screen name - what is the code in php, html, or whatever to write the screen. My problem is not getting the screen name but writing it once I get it. I am very new at this and I think my other programming knowledge is making this more complicated than it is. Thanks so much for your help. Quote Link to comment https://forums.phpfreaks.com/topic/159504-solved-page-navigation/#findComment-841467 Share on other sites More sharing options...
Maq Posted May 25, 2009 Share Posted May 25, 2009 I assume these are 2 separate tables? I don't believe you'll need to join them. You can just check the classified type from the first table and determine the page to call from that. Here is some testing code I wrote, I hope it gives you an idea of how to pass variables within the same page using the $_GET method. Please read more here - GET. You will need to retrieve the id from the link, by passing it via http (get method) and perform a query, matching the id, check what the type is, compare it to the switch statement, then proceed to include that screen in your page. Let me know if you have any questions: $callPage = "default"; $id = $_GET['id']; echo $id; $typeArr = array("AUTO", "BIKE", "PETS", "JOBS"); /** You're going to have to query the database for the type like this: $sql = "SELECT cls_type FROM table WHERE id = '$id'"; $result = mysql_query($sql) or die(mysql_query); $row = mysql_fetch_assoc($result); $num = mysql_num_rows($result); $type = ($num>0) ? {$row['cls_type'} : "default"; **/ switch ($id) { case "AUTO": $callPage = "auto.php"; break; case "BIKE": $callPage = "bike.php"; break; case "PETS": $callPage = "pets.php"; break; case "JOBS": $callPage = "jobs.php"; break; default: $callPage = "default.php"; break; } ?> These are your records: echo "Requiring page: $callPage "; //Instead of echoing it you should use require_once($call_page) foreach($typeArr as $arr => $value) echo "Record $value "; ?> Quote Link to comment https://forums.phpfreaks.com/topic/159504-solved-page-navigation/#findComment-841479 Share on other sites More sharing options...
alemapo Posted May 25, 2009 Author Share Posted May 25, 2009 Thanks! It looks like I can get what I need from this code. I will give it a shot tomorrow and reply back if resolved. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/159504-solved-page-navigation/#findComment-841486 Share on other sites More sharing options...
Maq Posted May 25, 2009 Share Posted May 25, 2009 Thanks! It looks like I can get what I need from this code. I will give it a shot tomorrow and reply back if resolved. Thanks again. Or problems YW, good luck! Quote Link to comment https://forums.phpfreaks.com/topic/159504-solved-page-navigation/#findComment-841489 Share on other sites More sharing options...
alemapo Posted May 25, 2009 Author Share Posted May 25, 2009 YW? Quote Link to comment https://forums.phpfreaks.com/topic/159504-solved-page-navigation/#findComment-841492 Share on other sites More sharing options...
Maq Posted May 25, 2009 Share Posted May 25, 2009 You're Welcome. Quote Link to comment https://forums.phpfreaks.com/topic/159504-solved-page-navigation/#findComment-841493 Share on other sites More sharing options...
alemapo Posted May 25, 2009 Author Share Posted May 25, 2009 Duh! Sorry, brain dead! Quote Link to comment https://forums.phpfreaks.com/topic/159504-solved-page-navigation/#findComment-841494 Share on other sites More sharing options...
alemapo Posted May 26, 2009 Author Share Posted May 26, 2009 Problem solved. I was able to take part of your sample code and work it in to solve my problem. I appreciate your help! THANKS! Quote Link to comment https://forums.phpfreaks.com/topic/159504-solved-page-navigation/#findComment-842089 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.