在PHP / MySQL查询中创建关联数组
发布时间:2020-12-13 22:50:58 所属栏目:PHP教程 来源:网络整理
导读:我的profileTable中有一个名为“Associations”的列…我正在尝试查询与关联相关的配置文件. $sql = mysqli_query($con,"SELECT * FROM profileTable WHERE Keyword_ID LIKE'%".$getKeyID."%' ORDER BY Associations 'School of Engineering and Computer Sci
我的profileTable中有一个名为“Associations”的列…我正在尝试查询与关联相关的配置文件.
$sql = mysqli_query($con,"SELECT * FROM profileTable WHERE Keyword_ID LIKE '%".$getKeyID."%' ORDER BY Associations <> 'School of Engineering and Computer Science',Associations AND LaName ASC LIMIT $start,$end"); 我可以通过教育而不是协会来索引个人资料. while ($row = mysqli_fetch_array($sql)) { $key = $row['Keyword_Name']; $keyID = $row['Keyword_ID']; $fname = $row['FirName']; $lname = $row['LaName']; $mname = $row['MName']; $suffix = $row['Suffix']; $title = $row['Title']; $title2 = $row['Title2']; $title3 = $row['Title3']; $education = $row['Education']; $education2 = $row['Education2']; $education3 = $row['Education3']; $dept = $row['Dept']; $phone1 = $row['PH1']; $phone2 = $row['PH2']; $email = $row['Email']; $photo = $row['Photo']; $bio = $row['BioLK']; $website = $row['Website']; $assocs = $row['Associations']; $actions=array('School of Engineering and Computer Science'=>'Computer Science and Engineering'); 我需要将关联与$key(单词)相关联,因此如果用户点击关键字“计算机”,它将与“工程与计算机科学学院”相关并首先在“工程与计算机科学学院”中对其进行索引. 这适用于其他列,如“教育”,但似乎无法使用我的关联数组.有任何想法吗? 示例sqlfiddle:http://sqlfiddle.com/#!2/c1802/7/0 解决方法
以下查询列出了根据需要排序的输出.
SELECT * FROM mediaContacts ORDER BY associations DESC,lname ASC Fiddle 协会将工程与计算机科学学院作为最后的阿尔法记录. 如果工程和计算机科学学院不是最后的alpha记录,则会失败并且需要另一种方法. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |