php - 如何根据用户选择功能更改在 echo 脚本中使用的给定 $variable 值
问题描述
首先,我有一些 php 代码检查是否记录了哪些用户,以便为他们提供各自的帐户值。之后,有几个变量的一些值会导致数据库上的不同文件链接。在设置变量后,这些变量在脚本内用于回显输出上的映射。结论是我想在应用程序中实现语言更改,但为了做到这一点,变量上的值需要更改为相应的语言值。
For example: Initially the $bars
is set to $row['barsgr']
, what we want is that when the language is selected, the $bars will change to $row['barseng]
.
我尝试过使用案例,但我不知道如何在当前情况下实现它。
<?php
$sql = "SELECT * FROM users WHERE uidUsers = '" . $_SESSION['userUid'] . "'";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0) {
while ($row = mysqli_fetch_assoc($result)){
$bars = $row['barsgr'];
$food = $row['foodgr'];
echo "<script>I am a map script that uses the variable $bars to show a layer but want to change the value when another language is picked so I show the translated layer from another column</script>";
?>
我希望当在 php 代码之外选择语言选择器时,php 代码中的变量会更改为它们各自的语言。
例如有人选择英语,
$bars = $row[barsgr];
更改为$bars = $row[barseng];
解决方案
也许这样的事情可以帮助:
<?php
$lang= $_POST['lang'] // Or maybe $_SESSION['lang'] if you store it there
if(!isset($lang)) {
$lang = 'gr';
}
$sql = "SELECT * FROM users WHERE uidUsers = '" . $_SESSION['userUid'] . "'";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0) {
while ($row = mysqli_fetch_assoc($result)){
$bars = $row['bars'.$lang];
$food = $row['food'.$lang];
echo "<script>I am a map script that uses the variable $bars to show a layer but want to change the value when another language is picked so I show the translated layer from another column</script>";
?>
推荐阅读
- gremlin - 如何排除不包含值的顶点
- c++ - 如何为给定的测试用例解决这个 geeksforgeeks 问题?
- javascript - Highchart 根据 y 轴的值改变十字准线颜色
- algorithm - 以下程序的时间复杂度是多少?
- output - 问题:带有附加 1 的 plm 包虚拟变量的输出
- azure - 如何获取 azure 管道的最后运行 id?
- imagemagick - 识别命令输出中的颜色图和直方图有什么区别?
- nginx - www 在域中返回超时,在我在 nginx 中使用正则表达式添加重定向之后
- c++ - 如何仅使用用户 ID num 显示用户帐户
- python - 使用 docker-compose 在容器之间创建共享目录