如何在数组中创建 href link
How to create href link inside array
实际上,我必须使用 php 数组将 table 数据填充到我的仪表板。 table 包含 URL。我需要设置用于重定向到动态 link 的 href。(下面是我的 while 循环代码)。我尝试使用下面的单行 echo php code.It 创建 href 工作并且我得到了可点击的 link,但它没有 return 数据在 table.它显示了 table 中的数据,没有任何对齐。
echo '<html><head></head><a href="'.$data['link'].'" target="_blank">'.$data['link'].'</a></html>';
但我想在数组中创建 href
请任何人帮助我们。
public function getTemperatures()
{
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_database = "new";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Oops some thing went wrong");
mysql_select_db($mysql_database, $bd) or die("Oops some thing went wrong");// we are now connected to database
$result = mysql_query("SELECT * FROM website"); // selecting data through mysql_query()
$pie = mysql_query("select count(*) from website where status = 'Error'");
while($data = mysql_fetch_array($result))
{
//echo '<html><head></head><a href="'.$data['link'].'" target="_blank">'.$data['link'].'</a></html>';
$temperatures[] = array(
'label1' => $data['link'],
'label2' => $data['time'],
'label3' => $data['os'],
'label4' => $data['browser'],
'label5' => $data['status'],
'label6' => $data['location'],
array('label6' => $data['widget_load_time'])
);
}
return DataTable::makeFromIndexedArray($temperatures);
}
看来您已经有了解决方案。只需更改将 'label1' 分配给以下内容的方式即可。
public function getTemperatures()
{
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_database = "new";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Oops some thing went wrong");
mysql_select_db($mysql_database, $bd) or die("Oops some thing went wrong");// we are now connected to database
$result = mysql_query("SELECT * FROM website"); // selecting data through mysql_query()
$pie = mysql_query("select count(*) from website where status = 'Error'");
while($data = mysql_fetch_array($result))
{
$temperatures[] = array(
'label1' => '<a href="'.$data['link'].'" target="_blank">'.$data['link'].'</a>',
'label2' => $data['time'],
'label3' => $data['os'],
'label4' => $data['browser'],
'label5' => $data['status'],
'label6' => $data['location'],
array('label6' => $data['widget_load_time'])
);
}
return DataTable::makeFromIndexedArray($temperatures);
}
如评论所述,避免使用 mysql_* 函数,因为它们不再受支持(这应该是足够的理由)
请添加这一行
'label1' => '<a href="'.$data['link'].'" target="_blank">'.$data['link'].'</a>',
实际上,我必须使用 php 数组将 table 数据填充到我的仪表板。 table 包含 URL。我需要设置用于重定向到动态 link 的 href。(下面是我的 while 循环代码)。我尝试使用下面的单行 echo php code.It 创建 href 工作并且我得到了可点击的 link,但它没有 return 数据在 table.它显示了 table 中的数据,没有任何对齐。
echo '<html><head></head><a href="'.$data['link'].'" target="_blank">'.$data['link'].'</a></html>';
但我想在数组中创建 href 请任何人帮助我们。
public function getTemperatures()
{
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_database = "new";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Oops some thing went wrong");
mysql_select_db($mysql_database, $bd) or die("Oops some thing went wrong");// we are now connected to database
$result = mysql_query("SELECT * FROM website"); // selecting data through mysql_query()
$pie = mysql_query("select count(*) from website where status = 'Error'");
while($data = mysql_fetch_array($result))
{
//echo '<html><head></head><a href="'.$data['link'].'" target="_blank">'.$data['link'].'</a></html>';
$temperatures[] = array(
'label1' => $data['link'],
'label2' => $data['time'],
'label3' => $data['os'],
'label4' => $data['browser'],
'label5' => $data['status'],
'label6' => $data['location'],
array('label6' => $data['widget_load_time'])
);
}
return DataTable::makeFromIndexedArray($temperatures);
}
看来您已经有了解决方案。只需更改将 'label1' 分配给以下内容的方式即可。
public function getTemperatures()
{
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_database = "new";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Oops some thing went wrong");
mysql_select_db($mysql_database, $bd) or die("Oops some thing went wrong");// we are now connected to database
$result = mysql_query("SELECT * FROM website"); // selecting data through mysql_query()
$pie = mysql_query("select count(*) from website where status = 'Error'");
while($data = mysql_fetch_array($result))
{
$temperatures[] = array(
'label1' => '<a href="'.$data['link'].'" target="_blank">'.$data['link'].'</a>',
'label2' => $data['time'],
'label3' => $data['os'],
'label4' => $data['browser'],
'label5' => $data['status'],
'label6' => $data['location'],
array('label6' => $data['widget_load_time'])
);
}
return DataTable::makeFromIndexedArray($temperatures);
}
如评论所述,避免使用 mysql_* 函数,因为它们不再受支持(这应该是足够的理由)
请添加这一行
'label1' => '<a href="'.$data['link'].'" target="_blank">'.$data['link'].'</a>',