Pagina 1 din 1

Am nevoie de putin ajutor !!!

Scris: Mar Noi 18, 2014 8:11 am
de Stef4n
NU reusec nici cum sa setez o limita "LIMIT". Doresc sa folosesc doar 6 cuvinte cheie de exemplu.

function GetTags($joc_id){
$sql = mysql_query("SELECT `keywords` FROM `jocuri` WHERE `joc_id` = '".$joc_id."' ");
$res = mysql_fetch_assoc($sql);
$joctags = $res['keywords'];
if(substr($joctags , 0 , 1) == ","){
$joctags = substr($joctags , 1 , strlen($joctags));
}
if(substr($joctags , -1) == ","){
$joctags = substr($joctags , 0 , - 1);
}
$tags = explode(',', $joctags);



foreach($tags as $cuvCheie){


$cuvCheieA = str_replace(' ','-',$cuvCheie);
if($cuvCheieA[0] == '-'){
$cuvCheieA = substr($cuvCheieA, -(strlen($cuvCheieA)-1));
}
if($cuvCheieA[strlen($cuvCheieA)-1] == '-') {
$cuvCheieA = substr($cuvCheieA, 0, -1);
}
if($cuvCheie[0] == ' '){
$cuvCheie = substr($cuvCheie, -(strlen($cuvCheie)-1));
}
if($cuvCheie[strlen($cuvCheie)-1] == ' ') {
$cuvCheie = substr($cuvCheie, 0, -1);
}
if(strlen($cuvCheieA ) > 3){
$cuvCheieA = str_replace('', '-' , $cuvCheieA );
echo '<a href="'.CALEFRONTEND.'jocuri/'.strtolower($cuvCheieA).'.html" title="'.$cuvCheie.'">'.strtolower($cuvCheie).'</a>' ;
}

}



}

Re: Am nevoie de putin ajutor !!!

Scris: Mar Noi 18, 2014 10:28 am
de takedown
Pai cum ai cuvintele cheie in tabel? daca le ai separate prin virguala, atunci folosesti un explode si dupa un for.Sa-ti dau un exemplu simplu:

Cod: SelectaĊ£i tot

<?php

$tags = 'need for speed,nfs,car games,racing games,download need for speed,need for speed download,download car games,car games download';

$keywords = explode(",", $tags);

for($x=0;$x<=5;$x++){
   echo $keywords[$x] .'<br>';
}
?>


sau vrei sa setezi un LIMIT general, adica de unde vrei sa inceapa si unde vrei sa se opreasca, gen cel folosit in SQL? de ex, codul de mai sus foloseste LIMIT 0, 5