如何显示将多维数组插入到MySQL表中? [英] How show Multidimensional Arrays be inserted into a MySQL table?

查看:109
本文介绍了如何显示将多维数组插入到MySQL表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此表中,我有要输入数据的字段'title''url''keywords'和说明.顺便说一句,我拥有的所有字段依次为"id","title","description","keywords","url"和"rank".我基本上想将多维数组的数据输入到mysql表中,并为每个数组输入[title]和[url]等.我希望它是一行. 我的代码如下:

In this table, I have the fields 'title' 'url' 'keywords' and description that I want data entered into. By the way, all the fields i have are 'id', 'title', 'description, 'keywords' url' and 'rank' in that order. I basically want to input data from a multidimensional array into the mysql table and for every array, with [title] and [url] etc. I want it to be one row. My code is below:

 $data = array();
  foreach ($links as $link) {
$output = array(
  "title"       => Titles($link), 
  "link"        => $link,
  "description" => getMetas($link),
  "keywords" => getKeywords($link) 
    );
   if (empty($output["description"])) 
  {$output["description"] = getWord($link);
  }
  $data[] = $output;
  }
 print_r($data);  

 mysql_query("INSERT INTO scan (title, url, description, keywords) VALUES ('".implode("'),('",$data)."')");

if (!mysql_query()) {
echo "woops";
 }

  mysql_close($connect);

请清楚地说明一下,我想在我的MYSQL表中进行排列.

Just to be clear, I want to array above, in my MYSQL table.

推荐答案

这要视情况而定,因为您必须在数据库中创建一个表,其中包含时间,日期,竞争,first_team,second_team列

That depends, because you would have to do a table in the database with time,date,competition,first_team,second_team columns

这实际上取决于您目前所了解的信息,如果您只想记录一个普通数组,则可以将其序列化到数据库中并在代码中反序列化

It really depends on how much you know at the moment, if you just want to log a plain array you can just serialize it into the database and unserialize it in the code

例如 php代码:

$array = array ('one','two','three'); 
$array = serialize ($array);
var_dump ($array);
$unseralize = unserialize ($array);
var_dump ($unserialize);

某事告诉我,您可能希望将其放在数据库上并查询服务器,然后执行循环.

Something tells me you might want to just put it over the database and query the server then do the loop.

这篇关于如何显示将多维数组插入到MySQL表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆