Jump to content
php.lv forumi

tagi


sandrulis

Recommended Posts

Veidojot tagu mākoni, man neizdodas apvienot vārdus. ja ir vienādi vardi viņi vienkārši atkārtojās, nevis apvienojas. izmēģināju vis kaut ko bet nekādīgi nesanāk. nevarat izlīdzēt?

 

 

Šis ir kods ko izmantoju kā pamatu.

$result=mysql_query("SELECT * FROM topics");
 while($row = mysql_fetch_array($result))
   {

   $tag = explode(" ", $row['tags']);
   $skaits =  count($tag);

     for ($i = 0; $i < $skaits; ++$i)
       {
           $tagi = $tag[$i];

           print $tagi.', ';
       }
   }

 

Zinu ka man sanāktu ja mācētu šādi, lai parādās $randomWords = array($tags1, $tags2, $tags3, $tags4, $tags5), bet man viņš uzmet tikai pēdējo :(. kad lietoju šādu kodu:

$result=mysql_query("SELECT * FROM topics");
 while($row = mysql_fetch_array($result))
   {

   $tag = explode(" ", $row['tags']);
   $skaits =  count($tag);

     for ($i = 0; $i < $skaits; ++$i)
       {
           $tagi = $tag[$i];

           $randomWords = array($tags);
       }
   }

 

 

Lūdzu palīdziet man izveidot, lai ir šādi:

 

$randomWords = array($tags1, $tags2, $tags3, ..., $tagsN);

 

vai arī kādu citu piedāvājumu :)

 

Paldies

Link to comment
Share on other sites


$randomWords  = array();

$result=mysql_query("SELECT * FROM topics");
 while($row = mysql_fetch_array($result))
   {

   $tag = explode(" ", $row['tags']);
   $randomWords = array_merge($randomWords, $tag);
   }

 print_r($randomWords);

 

Tā var salikt masīvā visus tagus

Link to comment
Share on other sites

Reku pats vienkaarshaakais variants

 

$tags = array();
$result = mysql_query('SELECT tags FROM topics');
while($row = mysql_fetch_assoc($result)) {
 $article_tags = explode(' ', $row['tags']);
 $tags = array_merge($tags, $article_tags);
}
$tags = array_unique($tags);

echo '<pre>' . print_r($tags, 1) . '</pre>';

 

Labaak, gan, protams, buutu glabaat tagus atsevishkjaa tabulaa un join'ot tos kopaa ar rakstu izmantojot tresho tabulu

 

articles

- id

- title

- text

 

tags

- id

- tag

 

taginizer

- article_id

- tag_id

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...