简体   繁体   English

如何从MySQL表中提取多行并将所有行自动用于同一事物?

[英]How can I pull multiple rows from a MySQL table and use all of them automatically for the same thing?

Basically, I have multiple URL's stored in a MySQL table. 基本上,我在MySQL表中存储了多个URL。 I want to pull those URLs from the table and have cURL connect to all of them. 我想从表中提取这些URL,并让cURL连接到所有URL。 Currently I've been storing the URL's in the local script, but I've added a new page that I can add and remove them from the database, and I'd like the page to reflect it appropriately. 目前,我一直将URL的内容存储在本地脚本中,但是我添加了一个新页面,可以在数据库中添加和删除它们,并且希望该页面能够正确地反映出来。

Here is what I currently have: 这是我目前拥有的:

  $sites[0]['url'] = "http://example0.com ";
  $sites[1]['url'] = "http://example1.com";
  $sites[2]['url'] = "http://example2.com";
  $sites[3]['url'] = "http://example3.com";

  foreach($sites as $s) 
  {
   // Now for some cURL to run it.
   $ch = curl_init($s['url']); //load the urls and send GET data
   curl_setopt($ch, CURLOPT_TIMEOUT, 2); //No need to wait for it to load. Execute it and go.
   curl_exec($ch); //Execute
   curl_close($ch); //Close it off 
  }

Now I assume it can't be too amazingly difficult to do, I just don't know how. 现在,我认为这并不是很难做到的,我只是不知道怎么做。 So if you could point me in the right direction, I'd be grateful. 因此,如果您能指出正确的方向,我将不胜感激。 But if you supply me with some code, please comment it appropriately so that I can understand what each line is doing. 但是,如果您向我提供了一些代码,请对其进行适当的注释,以使我能够理解每一行的内容。

Assuming you have a MySQL connection set up, here's the code that will do it for you: 假设您已建立MySQL连接,下面的代码将为您完成此操作:

/* Define $SQL variable being a dataset returned from the database.
The SELECT url FROM urls means "fetch the column 'url' for each row 
in the table 'urls' or generate an error" */
$SQL = mysql_query("SELECT url FROM urls") or die(mysql_error());
/* Loop through the dataset and create a new variable which is an
array (loopable) that contains the fetched data */
while($resultSet = mysql_fetch_array($SQL)){
    // Now for some cURL to run it.
   $ch = curl_init($resultSet['url']); //load the urls and send GET data
   curl_setopt($ch, CURLOPT_TIMEOUT, 2); //No need to wait for it to load. Execute it and go.
   curl_exec($ch); //Execute
   curl_close($ch); //Close it off 
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用一行从同一mySQL表中提取其他多行 - How do I use one row to pull multiple other rows from the same mySQL table 如何从电子邮件中提取内容并将其写入mysql表中? - how can I pull out the contents from an email and write them in a mysql table? MySQL:我需要根据相同的条件从多个行中提取相同的列名称到单个查询中 - MySQL: i need to pull the same column name from multiple rows into single query based on same conditions 如何使用函数从mysql提取多行 - How to pull multiple rows from mysql with a function MySQL查询-从具有相同ID的多行添加数据并将其放置在表中 - Mysql query - add data from multiple rows with the same id and place them in a table 从数据库获取同一事物的多行 - Getting multiple rows of the same thing from database 如何使用联接基于另一个表中的行从一个表中获取mysql行? - How can I use joins to fetch mysql rows from one table based on rows that are found in another? 如何下拉具有先前在mySQL和Android PHP中选择的列表名称的表的所有行 - How do I pull down all rows for a table with the list name that was selected previously in mySQL and Android PHP 如何从MySQL中获取多行,并使它们成为复选框的值,以将其插入php中数据库的另一个表中? - How Do I fetch multiple rows from MySQL and and make them the value of checkbox(es) to be inserted to a another table in the database, in php? mysql如何比较同一表中的两行? - mysql How can i compare two rows in the same table?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM