php mysql filter after query
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++;
}
you are doing it completely the wrong way.
- Such a filtering should be done on the DB side, not in PHP.
- These subjects should not be stored like that but in separate fields in a relational table.
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
精彩评论