5

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

12
  • 4
    question: why are you unpacking that row into a million variables? Commented Dec 16, 2013 at 18:18
  • ?? @Mike'Pomax'Kamermans explain... Commented Dec 16, 2013 at 18:22
  • 1
    no, that was the entire question. You have a data container with all your data, why would you unpack it to 20 variables instead of using the associative data array in the section of code that needs to use it? This just makes your code unnecessarily huge, without any real benefit ($title1 is just as legible as $data["title1"], for instance) Commented Dec 16, 2013 at 18:24
  • On a more getting-an-answer related note, you probably also want to post a sqlfiddle.com link to show what your data actually looks like, with the queries easy to replicate. Commented Dec 16, 2013 at 18:26
  • 1
    Like THIS Commented Dec 17, 2013 at 19:47

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @davidstrachan this solved my query... and isolated my association according to my clicked keyword just as expected. Thanks again!
0

You can try the following

Change

while ($row = mysqli_fetch_array($sql)) {

to

while ($row = mysql_fetch_assoc($sql)) {

It will Return an associative array that corresponds to the fetched row and moves the internal data pointer ahead.

2 Comments

I thought this too but it instead did not return any results. With fetch_array it returns the results, just doesn't index the "Associations" first. Hmmm...
I've added a sqlfiddle at: sqlfiddle.com/#!2/c1802/7/0 if you change "assoc" back to "array" it works...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.