dpkpaxhzffixp8426 2019-03-28 11:00
浏览 52
已采纳

动态网址链接与PHP不同的PHP变量

My title may not be the good one, i tried my best.

I want to load different links through ajax, and I want them to direct them to different pages, based on the links URL they have.

the href value is php variable that is changing.

In simple case we do this : <a href = "somepage.php?varible = 'ifany' ">

But I've pages with different names and these names are changing through variable.

How can I have the page name with their extension and with the ability to send variables to that page dynamically, how can I do that ?

The following links are loaded with different href values through ajax.

if ($run = mysqli_query($connect, "SELECT `day` from `foodd_schedule` WHERE `week` = '$week' group by day"))
{
    while ($row = mysqli_fetch_assoc($run)) {
?>

    <a href="<?php echo $row['day'] . '.php'; ?>" value="<?php echo $row['day']; ?>" name="<?php echo $row['day'] ?>"><?php echo $row['day']; ?></a>

<?php
    }
}

In href value I'll have different days with that I've appended extension i.e php, I don't know is this right or wrong?

How can I append variables to the dynamically created page names?

I want to append an id to these dynamically created links.

  • 写回答

2条回答 默认 最新

  • dos8410 2019-03-28 11:06
    关注

    This would be the code for your href value

    <?php echo $row['day'] . '.php?id=' . $id; ?>
    

    I would recommend to create a function where you would build your url. For the GET parameters use http_build_query function see the doc.

    Update:

    How to append multiple params using http_build_query, full example:

    <php
    if ($run = mysqli_query($connect, "SELECT `day` from `foodd_schedule` WHERE `week` = '$week' group by day")) {
        while ($row = mysqli_fetch_assoc($run)) {
    
            $params = [
                'id' => $id,
                'foo' => 'some string',
            ];
            $query = http_build_query($params); // generate url encoded string
    ?>
            <a href="<?php echo $row['day'] . '.php' . (!empty($query) ? '?' . $query : ''); ?>" value="<?php echo $row['day']; ?>" name="<?php echo $row['day']; ?>"><?php echo $row['day']; ?></a>
    <?php
        }
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c