dthhlf1777 2013-03-20 23:53
浏览 70
已采纳

PHP MySQL如何在一个表行中关联两个字段?

If I could talk to my database table, I would say "if client_id and salesrep_id are in the same row, do this!

Most of the conditional logic I've got. It's the "in the same row" part I'm struggling with.

Essentially, I'm building a system that allows all sales reps to view the entire data table but will permit each rep to update only their own specific entries.

The idea is to disable everybody else's "EDIT" links in the display.

Like so ...

    <?php if ($row_listClients['client_id'] && $row_listClients['salesrep_id']) { ?>
    <td><a href="edit_clients.php?client_id=<?php echo $row_listClients['client_id']; ?>">Edit</a>
    </td>
    <?php } else { ?>
    <td>Edit</td>
    <?php } ?>

Obviously the initial condition doesn't work ( && will always be true ) but everything else works great. It's just this one bit I'm stuck on.

Hope that makes sense, I know it's probably pretty basic stuff.

Thanks a bunch guys, any pointers would be really appreciated.

--

Here's the query :

    $query_listClients = "SELECT client_id, user_id, repname, date, client_type, company,
    contact_firstname, contact_lastname, phone, email, property, address, city, province,
    repnotes FROM clientdata ORDER BY company ASC";
    $listClients = mysql_query($query_listClients, $connAdmin) or die(mysql_error());
    $row_listClients = mysql_fetch_assoc($listClients);

Thanks again ...

--

Sample of database data - which I entered as a test only. The first two number are client_id and user_id respectively:

    19;"33"; "Ronald Wharton"; "March 20 2013"; "Commercial"; "Bonkers Inc."; "Brett";
    "Bonkers"; "987   654 3211"; "brentbonkers@bonkersinc.com"; "Retail Outlet"; 
    "12765 34 Ave"; "Lost Soul City"; "Sask"; "Brett wants to meet with Keith and Dean 
    before the end of the week.  Please call before Friday."        

Don't know if that's any help, but there ya go, thanks.

  • 写回答

2条回答 默认 最新

  • dongshan1396 2013-03-21 20:22
    关注

    I reread your question. It sounds as if you're querying to get all records, but only want to show edit links for items a particular sales rep should be allowed to edit.

    Since you want all records, this shouldn't be done via SQL, and it sounds like all you need to do is change:

    <?php if ($row_listClients['client_id'] && $row_listClients['salesrep_id']) { ?>
    

    To something like:

    <?php if ($row_listClients['salesrep_id'] == $currentSalesRepId) { ?>
    

    You'll obviously need to use the appropriate variable for the $currentSalesRepId.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样