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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?