dp518158 2015-01-14 04:45
浏览 46
已采纳

使用<a href>将Filemaker PHP getfield作为URL

I am trying to return a list of projects which I can do via the following code: (this is part of a larger if statement, that is why the dangling { bracket in the foreach line)

foreach ($r->getRecords() as $project){
        echo $project->getField('Project_Name') .'<br />';

That returns the list just as it should. I am now trying to link each of the returned $project variable to a URL (each project will re-direct to another page showing project details.) Here is what I have tried.

foreach ($r->getRecords() as $project){
        echo '<a href="project_detail.php">' $project->getField('Project_Name') '</a>' .'<br />';

That returned a syntax error on the

foreach ($r->getRecords() as $project){
        echo $project->getField("<a href='project_detail.php'>'Project_Name'</a>") .'<br />';

Any advice or a nudge in the right direction would be appreciated.

  • 写回答

2条回答 默认 最新

  • dtrovwl75780 2015-01-14 05:23
    关注

    To be able to link to a project you're going to need to pass in some kind of identifier for the link so that your project_detail.php file knows what project record to find. In the code below I make the assumption that the id field of the project record id called id.

    // Please never use single letter variables in your code.
    foreach ($result->getRecords() as $project){
        $projectId   = $project->getField('id'); // This should be whatever primary key field (serial number field) you define for your project
        $projectName = $project->getField('Project_Name');
    
        echo "<a href='project_detail.php?id=$projectId'>$projectName</a><br>";
    }
    

    If you write the data you need into variables first, you can then use a double quote string to construct the link and use the variable names without having to concatenate everything. You end up with a couple of extra lines of code but your link string is way more readable.

    Now your project_detail.php file can use the project id value to find the project record:

    $projectId = $_GET['id'];
    
    $findRequest = $fm->newFindCommand('project_layout_name');
    $findRequest->addFindCriterion('id', $projectId);
    $findResult = $findRequest->execute();
    ....
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀