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 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么