0

Trying to filter the results after a query. Need to find a string inside of a tinytext string. That looks like: accounting, ACT, algebra 1, algebra 2, American history, biology, calculus, economics, English, European history, geometry, grammar, literature, piano, proofreading, psychology, reading, SAT math, SAT reading, SAT writing, statistics, violin, vocabulary,

Code - subject string to find is $subject and the list to search is $row['SubjectList']

$result = mysql_query($query, $dbConn);
$i=0;
while ($row = @mysql_fetch_assoc($result)){
    $results[$i]['Name'] = $row['Name'];
    $results[$i]['Zip'] = $row['ZipCode'];
    $results[$i]['SubjectList'] = $row['SubjectList'];
    $i++;
}

2 Answers 2

1

you are doing it completely the wrong way.

  1. Such a filtering should be done on the DB side, not in PHP.
  2. These subjects should not be stored like that but in separate fields in a relational table.
Sign up to request clarification or add additional context in comments.

1 Comment

just trying to work with what I have... can't move to a relational table and also the query is super complicated and I've posted 2 on how to add this search to it, but no one has given a working solution... so i'm trying to filter with conditionals after the fact... they have to go into an array anyway. can you help with current problem?
0

While I agree with Col. Shrapnels answer, in your specific case you are looking for the strpos function if you really want to do it in PHP

3 Comments

I've tried the strpos and also explode and they return lots of empty $results.
Can you update your question with the information of what you have tried and what failed?
figured it out at the db query... had to remove sprintf

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.