I would like to set up conditional branching within MySql.

Asked 1 years ago, Updated 1 years ago, 35 views

Thank you for your help.

Please give me some advice.Thank you for your cooperation.

When you click a table in MySql, each tab is aligned, and when you click the "View" tab on the leftmost side, the fields in the table are aligned in a horizontal column.

In this example, in a table that defines the URL of a website, each field includes, for example, page_id, name, url, filename, ...

Filename is a template file for that site, but I would like to flag the URL of that site and replace it with multiple template files. Is it possible for mysql to set up the process?(Because the php side cannot set the action for some reason.) (If the php side sets it, the settings will be as follows.)

 if($_GET['id']==1){
$this->tpl_mainpage='file1.tpl';
} else if($_GET['id']==2){
$this->tpl_mainpage='file2.tpl';
} else{
$this->tpl_mainpage='file3.tpl';
}

mysql

2022-09-29 22:22

1 Answers

If SQL is OK with you
*Please note that if you do the following, you will rewrite the filename of all records.
(Additional note) I added a condition not to rewrite the filename of all records because it said, "Flag the URL of the site."
Rewrite the table name and the id part of the WHERE statement.

UPDATE table name SET
  filename = CASE page_id
    WHEN1THEN'file1.tpl'
    WHEN2THEN'file2.tpl'
    ELSE 'file3.tpl'
END
WHERE page_id IN (1, 2, other eligible id)


2022-09-29 22:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.