Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Associative Arrays in PHP/MySQL Query

Tags:

arrays

php

mysql

I have a column in my profileTable called "Associations"... I am trying to query profiles relative to the 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");

I am able to index profiles by education but not by Association.

    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');

I need to relate the Associations with the $key(word) so if a user clicks on a keyword "Computers" it will relate to "School of Engineering and Computer Science" and index those in the "School of Engineering and Computer Science" first.

This works fine with other columns like "Education" but can't seem to get it to work with my associative array. Any ideas?

example sqlfiddle: http://sqlfiddle.com/#!2/c1802/7/0

like image 949
MizAkita Avatar asked Nov 01 '22 08:11

MizAkita


1 Answers

The following query lists output ordered as required.

SELECT * FROM mediaContacts ORDER BY  associations DESC,lname ASC

Fiddle

As associations has School of Engineering and Computer Science as the last alpha record this works.

If School of Engineering and Computer Science is not the last alpha record this fails and another method is required.

like image 110
david strachan Avatar answered Nov 09 '22 07:11

david strachan