Jump to content

Recommended Posts

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  :))

Link to comment
https://forums.phpfreaks.com/topic/159504-solved-page-navigation/
Share on other sites

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.

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.

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
";
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.