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>
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".
Here, just a idea how you can do it.
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. ;)