0

我不是编程人员,但在遥远的过去有过一些。我的网站人刚刚移民,我需要自己在这里对以下 PHP 代码进行一些小改动。为此招募开发人员是不值得的。

它只是相关的下面的“” mysql_fetch_row行。

目前,这将返回表中 OWNER 字段完全匹配的所有行。我需要更改它以匹配 OWNER 内容等于表字段的任何部分的位置,其中包含的每个项目都以 CSV 方式分隔。

例如,我需要在包含 owner1、owner2、owner3、owner4 等的字段中找到 owner3 输入匹配项

$rs = mysql_query("select
    type,
    ref,
    date,
    owner   

    from documents where account=" . quote($currentaccount) . " and owner=" .      quote($owner) . " and type like 'CR%' order by entered desc");
echo '<table class="data" width="97%">';
while ($r = mysql_fetch_row($rs))
{
    $i = 0;
    echo '<tr>';

    $type = $r[$i++];
    echo '<td>';
    echo esc($type);
    echo '</td>';

    $ref = $r[$i++];
    echo '<td>';
    echo '<a href="download.php?type=' . escurl($type) . '&ref=' . escurl($ref) . '">' .  esc($ref) . '</a>';
    echo '</td>';

    $s = $r[$i++];
    echo '<td>';
    echo strdate($s);
    echo '</td>';

    $s = $r[$i++];
    echo '<td align="right">';
    echo blankzero($s);
    echo '</td>';

    echo '</tr>';
}

echo '</table>';

require '../inc/end.php';
4

2 回答 2

0

您需要使用全文搜索或 INSTR。

and `owner` LIKE '%" . quote($owner) . "%'

或者

and INSTR(`owner`, '" . quote($owner) . "')

对于具有全文索引的行,第一个会更快。

于 2013-06-13T15:16:42.137 回答
0

将SQL更改为读取..

and owner LIKE ".quote("%".$owner."%")."
于 2013-06-13T15:09:01.187 回答