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 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?