dongmou5628 2014-01-28 17:08
浏览 39

根据ID从表中获取特定行

I want to get a specific row from a table with an id. My table has 5 columns named: id, title, active, position, content

for example, if i give id 5 then the database must give me the row where ID = 5

now i have this

$result = mysql_query("SELECT * FROM klant1");

    $contents = mysql_fetch_array($result); 
            $rows = mysql_num_rows($result);

            for($i = 0; $i <= $rows - 1; $i ++){
                echo "<div id='block'>";
                echo "<table id='titleTab'>";
                echo "<tr id='title'>";
                echo "<td>Title</td><td>Active</td><td>Remove</td><td>Position</td><td></td></tr></table>";

                echo "<table id='sub'><tr><td>Menu</td>";
                echo "<td><input style='float: left;' type='checkbox'/></td>";
                echo "<td><img style='height:11px;'src='img/delete.png'/></td>";
                echo "<td><select><option value='1'>1</option></select></td>";
                echo "<td><img style='float: right; height: 20px;' src='img/save.png'/></td>";
                echo "</tr></table> </div>";
            }

I want to change keywords such as Title in the right title of the current row.

Sorry for my bad english by the way

  • 写回答

2条回答 默认 最新

  • doushuo1989 2014-01-28 17:10
    关注

    Add a WHERE and use PDO. mysql_query is deprecated.

    $pdo = new PDO(...);
    $statement = $pdo->prepare("SELECT * FROM klant1 WHERE id = ?");
    $statement->bindParam(1, $id);
    $statement->execute();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集