i have query in mysqli:
function getPicByAlbumt($query)
{
$sqlStr = "SELECT TOP 10 * FROM tbl_albumpictures WHERE album_Id = ? ".$query;
return $sqlStr;
}
and this is the proccess of this query:
<?php
$sqlu = getPicByAlbumt("order by rating");
if ($result2u = $mysqli->prepare($sqlu))
{
$rekzak = 76;
$result2u->bind_param("i",$rekzak);
$result2u->execute();
$result2u->store_result();
$rows2u = $result2u->num_rows;
}
if($rows2u>0)
{
$rowu = fetch($result2u);
for($g=0; $g<$rows2u; $g++)
{
$picname = $rowu[$g]["pic_name"];
?>
<div style="float:right; width:115px; height:96px; background:url(<?=$site_url?>/images/t/girlpicbg.png); margin-right:1px; margin-top:2px;">
<img src="<?=$site_url?>/uploads/albums/<?=$picname?>" style="width:106px; height:88px; margin-top:3px; margin-right:6px;" />
</div>
<?php
}
}
?>
,,,my problem is that the TOP 10 * is not working in mysqli :S .. any suggestions or help please :S ?.. another words : if i have 20 photos...ordered by rating....i mean that the last photo can be the first if his order is 1...and the first can be the last if his order is 20 ... so i want to order the first 10 id but this 10 to order them by rating...i mean .. if i selected the first 10 id's (photos)...and the first photo rating is 20...in this group(first 10 photos by id) i want the first photo to be ordered the last..because his id is 20 and the biggest rating value
You are using MySQL
right? use LIMIT 10
instead of TOP 10
(for MSSQL).
SELECT...
FROM...
WHERE...
ORDER BY...
LIMIT 10
SELECT TOP
is used for SQL-Server, not for MySQL. What you're looking for is LIMIT
:
SELECT * FROM tbl_albumpictures WHERE album_Id = ? LIMIT 10