Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select only hashtag part of string from database

Tags:

php

mysql

hashtag

I have a PHP function to show message with hashtag.

PHP code like this :

include 'includes/_db_.php';

$sql_t = "SELECT message FROM t_haps_wall WHERE message LIKE '%#%'";
$hasil_t = mysql_query($sql_t) or die(mysql_error());

while($data_t = mysql_fetch_array($hasil_t))
{
$message_t = $data_t['message'];
}

This code is running ok, but now how to set just hashtag show ? If in example like this :

Message = I like you #loveyou

In my current, It will show all message, I just want show #loveyou. Is it possible ?

Thanks for helps.

like image 496
Nagini Avatar asked Nov 24 '12 06:11

Nagini


1 Answers

SELECT SUBSTR(message, LOCATE('#', message)) hashtag
FROM t_haps_wall
WHERE message like '%#%'
like image 83
Barmar Avatar answered Nov 04 '22 15:11

Barmar