Php mysql查询以获取相关列

Php mysql查询以获取相关列,php,mysql,Php,Mysql,希望你们能帮我解决这个问题,我还是sql的新手,我还没弄明白 我已经使用PHP构建了一个页面,$\u获得唯一id以显示记录 在此页面上,我想显示共享特定列的所有记录 比如说 php获取唯一的id,即44 SELECT * FROM products WHERE id = 44 -- (the problem) 从id=44列cat_02获取数据 现在显示cat_02中的所有“racing”产品标题 我希望这是有道理的 创建到数据库的连接 使用您的查询创建一个准备好的语句 执行提供参数的语句

希望你们能帮我解决这个问题,我还是sql的新手,我还没弄明白

我已经使用PHP构建了一个页面,$\u获得唯一id以显示记录

在此页面上,我想显示共享特定列的所有记录

比如说

php获取唯一的id,即44

SELECT * FROM products WHERE id = 44 -- (the problem) 
从id=44列cat_02获取数据 现在显示cat_02中的所有“racing”产品标题

我希望这是有道理的

创建到数据库的连接 使用您的查询创建一个准备好的语句 执行提供参数的语句 循环执行的结果 例如:

    // creates a new PDO connection, you'll need to modify this to work with whatever DB you are using
    $dbh =  new PDO('mysql:host='.$host_name.';dbname='.$database, $username, $password);

    $stmt = $dbh->prepare("SELECT cat_02 FROM products WHERE id = ?"); // selects just the cat_02 column that has the product titles
    if ($stmt->execute(array($_GET['id']))) { // uses the id variable from $_GET
      while ($row = $stmt->fetch()) { // loops through all of the rows returned from the query
        print_r($row); // do what ever you wanted to with the row of results
      }
    } 

发布完整的查询代码我知道这大部分不是sql,但希望它能帮助我从id=id和所选$id=cat_02的产品中获得$query=SELECT*,并在cat_02中显示所有产品标题;这很有道理。我想我必须用sql完成整个查询。非常感谢。