Wednesday, 21 August 2013

Return rows where first character is alpha and equivalent to accented characters

Return rows where first character is alpha and equivalent to accented
characters

I'm looking for a query that will return the rows where the first alpha
character of the name starts with a letter given in a variable. It should
also include the equivalent for non accented characters.
table in mySQL as an example:
id name
--------------------------
25 Como yo te quiero
57 Me quieres
34 Ahora
45 África
568 No me mires
78 ¿A que?
89 Y sin embargo
5 ¡... A que no!
34 ...A la madre
85 Por que
51 A mi manera
PHP file:
// alpha letter to search in the name
$char = $_GET['char'];
// layout of the query
$sql = 'SELECT song_id, name FROM song WHERE song.name starts with ?';
$conn = connect('read');
$stmt = $conn->stmt_init();
$stmt->prepare($sql);
$stmt->bind_param('s', $char);
$stmt->execute();
$stmt->bind_result($songid, $name);
$stmt->fetch();
$stmt->free_result();
$stmt->close();
$conn->close();
if $char equals 'a', then the result set should returns all rows where the
first alpha letter in the name starts with a or A or á or Á etc...
output:
34 Ahora
45 África
78 ¿A que?
5 ¡... A que no!
34 ...A la madre
51 A mi manera
if $char equals 'e', then the result set should returns all rows where the
first alpha letter in the name starts with e or E or é or É etc...
if $char equals 'p', then the result set should returns all rows where the
first alpha letter in the name starts with p
and so on...
What is the query ? Do i need some sort of a conversation table to tell
PHP what characters are equivalent to a, e , o, etc...?

No comments:

Post a Comment