duanfuchi7236 2016-12-14 11:51
浏览 68
已采纳

一个数据Php / SQL的不同样式

I'm trying to create a word cloud with PHP, CSS and SQL. The user can enter any word and it will be integrated into the word cloud.

The problem is that the word cloud works with CSS li class (the words are separated by text transformation, color, size etc ...).

Below is my attempt. The problem is everything is repeated and I don't know how I can put every word from my SQL database in the different class of <li> (see the screenshot).

<!DOCTYPE html>
<html>
<head><link rel="stylesheet" type="text/css" href="wordcloud.css">
<title>Nuage de mot</title>
</head>
<body>
<?php 
$bdd = new PDO('mysql:host=localhost;dbname=wordcloud', 'root', 'root');

$reponse = $bdd->query('SELECT * FROM form_element');
$donnees = $reponse->fetch();

?>
<ul class="word-cloud">
<?php while ($donnees = $reponse->fetch())
{
    ?>
    <li class="word-cloud__word  word-cloud__word--x-small"><?php echo $donnees['mot']?></li>
    <li class="word-cloud__word  word-cloud__word--small"><?php echo $donnees['mot']?></li>
    <li class="word-cloud__word  word-cloud__word--large"><?php echo $donnees['mot']?></li>
    <li class="word-cloud__word"><?php echo $donnees['mot']?></li>
<?php 
}
$reponse->closeCursor();
?>
</ul>
<div>
<a href="form.html"><input type="button" value="Ajouter un nouveau mot"></a>
</div>
</body>
</html>

enter image description here


This part is ok, when I put word in my form, they are in the cloud.

But now you were right, I have to integrate the notion of occurrences...

Words repeated xx times have to be bigger...

I have to change my database ?

I thought to create a column "repeated words" and create an if function in my form. But I don't know if it possible for the script to recognize, the word for example "hello", the number of times it is present in my colum "repeated word".

  • 写回答

2条回答 默认 最新

  • dtcd27183 2016-12-14 12:00
    关注

    Here, just a idea how you can do it.

    $counter = 0;
    <?php while ($donnees = $reponse->fetch())
    {
    
    $counter++;
    
    if($counter == 1) { ?>
     <li class="word-cloud__word  word-cloud__word--x-small"><?php echo $donnees['mot']?></li>
    <?php }
    if($counter == 2) { ?>
     <li class="word-cloud__word  word-cloud__word--small"><?php echo $donnees['mot']?></li>
     <?php }
    if($counter == 3) { ?>
     <li class="word-cloud__word  word-cloud__word--large"><?php echo $donnees['mot']?></li>
    <?php }
    if($counter == 4) { ?>
    <li class="word-cloud__word"><?php echo $donnees['mot']?></li>
    <?php $counter = 0;
    }
     ?>
    

    May there are some syntax errors with the <?php ?> havent checked it. But I think you should know what I mean and you'll find the error by yourself if there are some. ;)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?