Try a stored procedure rather than a function.
A sample stored procedure with parameter -
DELIMITER $$
DROP PROCEDURE IF EXISTS MyFirstSP$$
CREATE PROCEDURE MyFirstSP(IN Id INT)
BEGIN
SELECT * FROM MyTable WHERE pk_id=Id;
END$$
You can follow this link to learn how to create a simple stored procedure.
MySQL: Creating a simple stored procedure [
^]
Hope, it helps :)