Je passe la procédure null à below car elle ne renvoie aucune valeur même si les données sont présentes dans la table?gestion des paramètres null dans la procédure mysql - ne fonctionne pas
appelez view_ads (NULL, 'vehicles', 9);
appelez view_ads ('placename', null, 9);
============================================== =======================================
ci-dessous est le code
delimiter $$
drop procedure view_ads$$
create procedure view_ads (place_name varchar(200),category_name varchar(200),pagecount int(8))
begin
declare lowerval int(8);
declare higherval int(8);
set lowerval= pagecount-9;
set higherval=pagecount;
if isnull(place_name) then
SET @sql = CONCAT("select idads_list,category,subcategory,state,city,title,
title_decode,phonenumber,userid,description,DATE_FORMAT(ad_date,'%d-%M-%Y %H:%i:%s') posteddate,automated
from ads_list
where automated='N' and (category ='",category_name,"' or subcategory='",category_name,"')
union all
select idads_list,category,subcategory,state,city,title,
title_decode,phonenumber,userid,description,DATE_FORMAT(ad_date,'%d-%M-%Y %H:%i:%s') posteddate,automated
from ads_list
where automated='Y' and (category ='",category_name,"' or subcategory='",category_name,"')
order by automated asc,posteddate desc
limit ",lowerval,",",higherval)
;
elseif ISNULL(category_name) then
SET @sql = CONCAT("select idads_list,category,subcategory,state,city,title,
title_decode,phonenumber,userid,description,DATE_FORMAT(ad_date,'%d-%M-%Y %H:%i:%s') posteddate,automated
from ads_list
where automated='N' and (state ='",place_name,"' or city='",place_name,"')
union all
select idads_list,category,subcategory,state,city,title,
title_decode,phonenumber,userid,description,DATE_FORMAT(ad_date,'%d-%M-%Y %H:%i:%s') posteddate,automated
from ads_list
where automated='Y' and (state ='",place_name,"' or city='",place_name,"')
order by automated asc,posteddate desc
limit ",lowerval,",",higherval)
;
else
SET @sql = CONCAT("select idads_list,category,subcategory,state,city,title,
title_decode,phonenumber,userid,description,DATE_FORMAT(ad_date,'%d-%M-%Y %H:%i:%s') posteddate,automated
from ads_list
where automated='N' and (state ='",place_name,"' or city='",place_name,"') and (category ='",category_name,"' or subcategory='",category_name,"')
union all
select idads_list,category,subcategory,state,city,title,
title_decode,phonenumber,userid,description,DATE_FORMAT(ad_date,'%d-%M-%Y %H:%i:%s') posteddate,automated
from ads_list
where automated='Y' and (state ='",place_name,"' or city='",place_name,"') and (category ='",category_name,"' or subcategory='",category_name,"')
order by automated asc,posteddate desc
limit ",lowerval,",",higherval)
;
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
end if;
end$$