I'm trying to organize my content by the first character. By now, I did something like this:
PHP:
$first_char = $_GET['search'];
$sql = "SELECT id
FROM table
WHERE SUBSTR(title,1,1) = '".$first_char."'"
....
HTML:
<a href="?search=a">[A]</a>
<a href="?search=b">[B]</a>
...
<a href="?search=z">[Z]</a>
<a href="?search=nr">[#]</a>
The thing is that when [A] is clicked, it shows titles starting with "A". What I want to do is when [#] is clicked, it should show all the posts starting with a number. So, when $_GET = 'nr' it shows all the titles starting with a number... I tried to do this with array(), but I failed.
Do you have any suggestions?
select ISNUMERIC(left('4ello world',1)) will be a "1" if the first character is a number.
SQL Server LEFT() Function The LEFT() function extracts a number of characters from a string (starting from left).
You should use the charAt() method, at index 0, to select the first character of the string. NOTE: charAt is preferable than using [ ] (bracket notation) as str.
$sql = "SELECT id
FROM table
WHERE SUBSTR(title,1,1) in (1,2,3,4,5,6,7,8,9,0)"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With