Simple Name Simple Name - 1 year ago 132
MySQL Question

PHP MYSQLI Count Row Correct [delete this]


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 Source

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.


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

It will help against a potential SQL injection.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download