Simple Name Simple Name - 3 months ago 10
MySQL Question

PHP MYSQLI Count Row Correct [delete this]

Table

enter image description here

Hello i try to finds all hashtags with name #c3 and mysqli query show me: 3 rows but correct is 2 rows with #c3 ??? where is problem ? I want to show me 2Rows !

$sql_query = mysqli_query($Connection, "SELECT * FROM my_table WHERE hashtag LIKE '%#c3%'");
echo mysqli_num_rows($sql_query);

Answer

To answer this and as left in comments (by myself)

Use '%#c3' by removing the last %

Using LIKE, the % wildcard does the following and a few examples:

%XXX% - Matches anything before and after XXX

%XXX - Matches anything before XXX

XXX% - Matches anything after XXX.

References:

Plus, should there be any user input, consider using a prepared statement:

It will help against a potential SQL injection.