Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php更改MySQL查询中生成的html表列的值_Php_Mysql_Dom - Fatal编程技术网

使用php更改MySQL查询中生成的html表列的值

使用php更改MySQL查询中生成的html表列的值,php,mysql,dom,Php,Mysql,Dom,所以,我有一个表,它是由一个MySQL查询产生的。此查询是MySQL数据库中两个表的内部联接,其中一个提供产品名称,另一个提供HTML格式的价格表(可以有2列或更多列,行数可变) Mysql查询: SELECT catalog_product_entity_varchar.value as `name`, catalog_product_entity_text.value as `html_table` from catalog_product_entity_varchar INNER JOIN

所以,我有一个表,它是由一个MySQL查询产生的。此查询是MySQL数据库中两个表的内部联接,其中一个提供产品名称,另一个提供HTML格式的价格表(可以有2列或更多列,行数可变)

Mysql查询:

SELECT catalog_product_entity_varchar.value as `name`, catalog_product_entity_text.value as `html_table` from catalog_product_entity_varchar INNER JOIN catalog_product_entity_text on catalog_product_entity_varchar.entity_id=catalog_product_entity_text.entity_id AND catalog_product_entity_text.attribute_id=171 AND catalog_product_entity_varchar.attribute_id=71"
为了输出该表,我使用了以下方法:

echo '<table border="1">';

if ($result->num_rows > 0) {
    // output data of each row
        while($row = $result->fetch_assoc()) {
         echo
            '<th>'.$row["name"]. '</th><tr><td>'. $row["html_table"].'</td></tr>';

    }
echo';
如果($result->num_rows>0){
//每行的输出数据
而($row=$result->fetch_assoc()){
回声
'.$row[“name”].'.$row[“html_table”].';
}
现在,我需要更改“html_table”部分的内容,特别是第二列(第一行也是文本)的第二行(第一行是文本)

我已经研究了几个解析器,比如simplehtmldom或php的DOM类,但我仍然无法掌握如何只更改那些特定的行/列


如果您有任何建议,我们将不胜感激!

您需要执行两个步骤:

  • 添加JQuery代码,该代码将向PHP文件发送请求并获得响应。获得响应后,将加载JSON并显示在table->tbody部分
  • PHP文件将接收请求,然后连接MySQLi,根据您的要求获取结果并返回JSON

您需要执行两个步骤:

  • 添加JQuery代码,该代码将向PHP文件发送请求并获得响应。获得响应后,将加载JSON并显示在table->tbody部分
  • PHP文件将接收请求,然后连接MySQLi,根据您的要求获取结果并返回JSON

您真正需要做的就是在while循环中添加一个条件以跳过表头,以及某种格式化功能

echo '<table border="1">';

if ($result->num_rows > 0) {
// output data of each row

//This boolean flag will determine if the row is the header (first row), 
//and skip formatting for this row
$header_row = true;

//We can use a closure here to do our custom formatting. 
//If you have another formatting method elsewhere, 
//use that instead of this.
$format_html_table = function($data) {

    //manipulate $data here based on what you need to do for formatting 
    //for all of the non-header rows
    //ex: $data = ...
return $data;
};

while($row = $result->fetch_assoc()) {
    if ($header_row) {
        $html_table = $row["html_table"];
    } else {
        $html_table = $format_html_table($row["html_table"]);
    }
    echo
        '<th>'.$row["name"]. '</th><tr><td>'. $html_table.'</td></tr>';

    //We set the boolean flag to false here after the first row has processed, 
    //so all remaining rows will be formatted.
    $header_row = false;
}
echo';
如果($result->num_rows>0){
//每行的输出数据
//此布尔标志将确定该行是否为标题(第一行),
//并跳过此行的格式设置
$header\u row=真;
//我们可以在这里使用闭包来进行自定义格式设置。
//如果您在其他地方有其他格式化方法,
//用那个代替这个。
$format\u html\u table=函数($data){
//根据格式化所需的操作在此处操作$data
//对于所有非标题行
//例:$data=。。。
返回$data;
};
而($row=$result->fetch_assoc()){
如果($header\u行){
$html_table=$row[“html_table”];
}否则{
$html_table=$format_html_table($row[“html_table]”);
}
回声
'.$row[“name”].'.$html_table.';
//在处理第一行之后,我们在这里将布尔标志设置为false,
//因此,所有剩余的行都将被格式化。
$header\u row=false;
}


确实没有理由为此而干扰dom解析器。您只需在生成任何标记之前对数据库中的原始源数据响应执行编辑即可。

您真正需要做的就是向while循环添加一个条件,以跳过表头,并使用某种格式化功能

echo '<table border="1">';

if ($result->num_rows > 0) {
// output data of each row

//This boolean flag will determine if the row is the header (first row), 
//and skip formatting for this row
$header_row = true;

//We can use a closure here to do our custom formatting. 
//If you have another formatting method elsewhere, 
//use that instead of this.
$format_html_table = function($data) {

    //manipulate $data here based on what you need to do for formatting 
    //for all of the non-header rows
    //ex: $data = ...
return $data;
};

while($row = $result->fetch_assoc()) {
    if ($header_row) {
        $html_table = $row["html_table"];
    } else {
        $html_table = $format_html_table($row["html_table"]);
    }
    echo
        '<th>'.$row["name"]. '</th><tr><td>'. $html_table.'</td></tr>';

    //We set the boolean flag to false here after the first row has processed, 
    //so all remaining rows will be formatted.
    $header_row = false;
}
echo';
如果($result->num_rows>0){
//每行的输出数据
//此布尔标志将确定该行是否为标题(第一行),
//并跳过此行的格式设置
$header\u row=真;
//我们可以在这里使用闭包来进行自定义格式设置。
//如果您在其他地方有其他格式化方法,
//用那个代替这个。
$format\u html\u table=函数($data){
//根据格式化所需的操作在此处操作$data
//对于所有非标题行
//例:$data=。。。
返回$data;
};
而($row=$result->fetch_assoc()){
如果($header\u行){
$html_table=$row[“html_table”];
}否则{
$html_table=$format_html_table($row[“html_table]”);
}
回声
'.$row[“name”].'.$html_table.';
//在处理第一行之后,我们在这里将布尔标志设置为false,
//因此,所有剩余的行都将被格式化。
$header\u row=false;
}


确实没有理由为此而使用dom解析器。您只需在生成任何标记之前对数据库中的原始源数据响应执行编辑即可。

好的,我可以试试,但还没有这样做。我的主要目标是构建一个小PHP脚本,因此我希望避免将jQuery和JSON等混合使用。这将是我们的目标在一些使用html表格而不是正确的magento选项的magento存储中进行编辑。有了这些信息,您认为我还有其他方法可以做到这一点吗?好的,您可以通过两种方法来做到,有页面刷新和没有页面刷新。如果您使用页面刷新,那么您可以在隐藏字段或会话中保存偏移量,每次页面刷新时都定义一个按钮单击它将获取接下来的几条记录。如果我们不进行页面刷新,比如加载更多选项,那么我们需要JSON和JQueryOk,我可以尝试一下,但还没有这样做。我的主要目标是构建一个小PHP脚本,所以我希望避免混合使用jQuery和JSON,等等。这将在一些使用这些html表而不是html表的magento存储中使用e正确的magento选项。有了这些信息,你认为我还有其他方法可以做到吗?好吧,你可以用两种方法做到,有页面刷新和没有页面刷新。如果你使用页面刷新,你可以在隐藏字段或会话中保存偏移量,每次页面刷新时定义一个按钮,单击它将获取接下来的几条记录。如果我们不使用页面刷新h、 像加载更多选项一样,我们需要使用JSON和JQuery