选择建议php,关系多对多 [英] Select in suggest php, relation many-to-many
问题描述
我需要帮助选择,但在提出问题之前,我会简要介绍一下我的系统是如何工作的:
我的数据库有很多 - 许多关系,请看下面:
表产品:
prd_cod(pk)//存储产品代码ex:0,1 ,2
cat_cod(fk)
prd_name //存储产品名称,例如:tv,gps,笔记本
table description_characteristc:
prd_cod(fk)
id_characteristic(fk)
description //存储特征的描述,例如: sony,1kg,hj10
桌子特征:
id_characteristic(pk)
name_characteristic //存储名称特征,例如:品牌,重量,模型
i已经在index.php中做好了,建议jquery,我输入的每个单词都叫做suggest.php如下所示,选择并将结果返回到索引中的建议框。
I need help with a select, but before asking the question, I will give a short description of how my system works:
my database has a many-to-many relationship, look below:
table product:
prd_cod(pk) //stores the product code ex: 0,1,2
cat_cod(fk)
prd_name //stores the product name, ex: tv, gps, notebook
table description_characteristc:
prd_cod(fk)
id_characteristic(fk)
description //stores the description of the characteristic, ex: sony, 1kg, hj10
table characteristic:
id_characteristic (pk)
name_characteristic //store the name of characteristic, ex: brand, weight, model
i have ready made in the index.php, a suggest jquery, that every word I type it''s calls the suggest.php look below, that makes a select and returns the result into the suggestion box in the index.
header('Content-type: text/html; charset=UTF-8');
$hostname = 'localhost';
$username = 'root';
$password = '';
$dbname = 'cpd';
mysql_connect($hostname, $username, $password)or die('Erro ao tentar conecta o banco
de dados.');
mysql_select_db( $dbname );
if( isset( $_REQUEST['query'] ) && $_REQUEST['query'] != "" )
{
$q = mysql_real_escape_string( $_REQUEST['query'] );
if( isset( $_REQUEST['identifier'] ) && $_REQUEST['identifier'] == "sugestao")
{
$sql = "SELECT p.prd_name, d.description
FROM product p
INNER JOIN description_characteristc d using (prd_cod)
WHERE '".$q."' like concat(p.prd_name, '%') AND
concat(p.prd_name, ' ', d.description) like concat('".$q."', '%')LIMIT 10";
$r = mysql_query( $sql );
if ( $r )
{
echo '<ul>'."\n";
$cont = 0;
while( $l = mysql_fetch_array( $r ) ){
$p = $l['nome'];
$p = preg_replace('/(' . $q . ')/i', '<span style="font-<br mode=" hold=" /> weight:bold;">$1</span>',
$l['prd_nome'].' '.$l['descricao'].' '.$l['descricao']);
echo "\t".'<li id="autocomplete_'.$cont.'">
rel="'.$l['prd_nome'].'.'.$l['descricao'].'">'. utf8_encode( $p ) .':</li:>'."\n";
$cont++;
}
echo ':</ul:>';
}
}
}
?>
问题:
1°目前当用户键入''t'时,只有当用户输入''tv''结果时,select才会带来任何结果:
tv led
tv plasm
tv samsumg
i当用户输入'时't''选择带给我 - ''电视''
2°当你输入''tv plasm''它带来两倍相同name_characteristic:
ex:tv plasm plasm
3°目前我的选择选择prd_name和描述表格description_characteristc,例如:tv led,我想我的选择也可以进行反向选择,例如:led电视。
4°我希望当显示了选择的结果,可能有一个显示orde的缓存功能最不值得追求的最好的。
记住prd_name只存储''tv''
我正在寻找的帮助,可以是select的形式,因为在程序的形式,php文件也可以编辑,我谢谢大家。
questions:
1° currently when the user type ''t'', the select brings nothing, only when the user type ''tv'' is bringing the result:
tv led
tv plasm
tv samsumg
i would like that when the user type ''t'' the select bring me - ''tv''
2° when you type ''tv plasm'' it''s bringing two times the same name_characteristic:
ex: tv plasm plasm
3° currently my select selects the prd_name and the descriptions of table description_characteristc, ex: tv led, I would like my select could make a inverse select too, ex: led tv.
4°I would like that when the results of the select were shown, could have a cache feature that shows the order of the most sought for the less sought.
remembering that prd_name stores only ''tv''
the help I''m looking for, can be in the form of select, as in the form of procedure, php file can also be edited, i thank you all.
推荐答案
hostname = ' localhost';
hostname = 'localhost';
用户名 = ' root';
username = 'root';
密码 = ' ';
password = '';
这篇关于选择建议php,关系多对多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!