Hello i need some help on how to select like this here below. Do i need somthing like not equal or greater than ? C. ------------------------------------ Ca Car Cars ..........................................<<< this is good ------------------------------------ H. ------------------------------------ Ho Hom Home........................................ <<< this is good Home G Home Ga Home Garden............................<< < this is good ------------------------------------ And the result should be like that C. ------------------------------------ Cars ------------------------------------ H. ------------------------------------ Home Home Garden ------------------------------------ Here is the script i use and i cant figure it out how to do that ! <?php mysql_connect("localhost","//","//"); mysql_select_db("//s"); $sql = mysql_query("SELECT * FROM videos WHERE 1"); $count = mysql_num_rows($sql); $keywords = array(); $id = array(); // IF Needed to match the video to its keywords. while($row = mysql_fetch_assoc($sql)) { $keywords[] = $row['channel']; $id[] = $row['id']; // Should be the primary key in your db table. on Auto Increment } $video_keywords = array(); $video_total = array(); $k=0; for($i = 0; $i < $count; $i++) { $keywords_expanded = explode(',',$keywords[$i]); $keywordsExp_count = count($keywords_expanded); // print_r($keywords_expanded[1]); for($j = 0; $j < $keywordsExp_count; $j++) { if(!in_array(trim($keywords_expanded[$j]),$video_keywords) && trim($keywords_expanded[$j])!='') { $video_keywords[$k] = trim($keywords_expanded[$j]); $k++; } $video_total[trim($keywords_expanded[$j])] = $video_total[trim($keywords_expanded[$j])]+1; } } $video_keywords = array_unique($video_keywords); //array_walk($video_keywords, create_function('&$val', '$val = trim($val);')); sort($video_keywords); $currChar = ''; foreach ( $video_keywords as $word) { if((int)$word[0]) { if($currChar != '#') { $currChar = '#'; echo '<br>'.$currChar . '<br>'.'<br>'; } } elseif ( $word[0] != $currChar ) { $currChar = $word[0]; echo '<br>'.$currChar . '<br>'.'<br>'; } echo '<a href="http://example.com/search.php?search='. $word .'&submit='. $word .'">'.$word. '</a>' .($video_total[$word]) .'<br /> ' ; } ?> PHP: Thanks for any help !
Not completely sure what your trying to accomplish. But the "like" statement might be what your looking for. SELECT * FROM table WHERE field LIKE %'home garden'% PHP: This would return anything in the field that has home garden in it, regardless of whats before or after. The same way, if you type "H", Home Garden would be a result.
Yeah searching from table using % should help, but the syntax should be something like this: SELECT * FROM videos WHERE channel LIKE '$keyword%' PHP: