duanlu4371 2013-09-01 05:07
浏览 44
已采纳

我有一个SQL表。 使用PHP的SQL请求,我希望将此请求的结果存储在变量中。 [关闭]

I have an SQL table. With an SQL request with PHP I want store the result of this request in a variable. The probleme is that this request have a lot of valors.

In other worlds I want to store in my variable a lot of IDs Maybe with an array but i dont now how. And i want to use variable for another SQL request using PHP.

What I want to do: With the IDs that I store in this variable, show all the names that have the same ID BUT this IDs of names are in another table. I want to use the IDs of the first table to second tables, and show all the names that correspond to the ID on mi web site. All the names (IDs) not just one.

I dont have the code yet.

I hope is an easy question, and you may help me thank you very much.

  • 写回答

1条回答 默认 最新

  • 普通网友 2013-09-01 05:16
    关注

    Not entrirly sure what you are asking here, but for the first part, storing everything in a variable is very simple, but if you write the script well, you dont have to use a new variable.

    $newVar = $_POST;

    BUT, you don't really need to do this, everything is already in POST, just access it with a key: $_POST[name_of_what_you_want]

    I think what you are asking is the basics of the CRUD website / database method. Create, read, update, and delete.

    You will get your info from the client in your script, ie GET or POST.

    Validate and scrub this data, prepping it for insertion into the database.

    Insert this data into your database. In your case you are talking about a relational database. Basically, you have a table which stores the bulk of the data, each of those entries, or rows as they are known, which has a unique ID. Then you have other tables that rely on that unique ID to link that particular row of data to something else, be it a page or a category, etc., of your website.

    Now that the data is in the database, you can query it and pull out what you need, based on a set of criteria, that you make up as you need. Then you build your webpage and send it to the user.

    Without providing specifics of your project, I am afraid I cannot help you much further, but I hope this helps.

    EDIT - based on your comment.

    Here is a pseudo mockup of what you are asking for.

    $sql = "SELECT name FROM table WHERE id='id_number'";
    $data = mysql_query($sql); <-- assuming you are using MySQL 
    while($row = mysql_fetch_assoc($data)){
       echo $row['name'];
    }
    

    What's going on? Query the database to pull out the rows with the ID you are looking for. Store them in an array, and step through that array, echoing the name to the user.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 聚类分析或者python进行数据分析
  • ¥15 如何用visual studio code实现html页面
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?