CSS
Code: Select all
:root
{
--MainDivBkgnd: #ffffff;
--SubTabBorder: #006699;
--SubTabBkgnd: #dbe7ef;
--MainTdBorder: #87CEEB; /* royal blue */
--SubTdBorder: #87CEEB; /* royal blue */
}
body {color: #000080; }
a {color: #0000FF; text-decoration: none;}
a:hover { background-color: aqua;}
div.fixed { position: fixed; top: 20; left: 20;} /* UP & Home */
table {border-collapse: collapse; margin-left: auto; margin-right: auto;}
caption {color:var(--SubTabBkgnd); background-color: var(--SubTabBorder);
line-height: 1em;
padding-top: 2px;
padding-bottom: 2px;
font-size: 0.8em;
font-family: Arial, Helvetica, sans-serif;
text-transform: uppercase;}
td.Sub1 { border: 1px solid var(--SubTdBorder); vertical-align: middle;}
td.Sub2 { border: 1px solid var(--SubTdBorder); vertical-align: middle;}
td.sub1 img { width: 160px; vertical-align:middle;} /* img inside td */
div.main { width: 1220px; margin: 0 auto; background-color:var(--MainDivBkgnd); border-style:none;}
.Banniere {width: 1200px; display: block; padding-top: 10px; padding-bottom: 10px; margin: 0 auto; }
table.main {width: 1200px;}
tr.main {vertical-align: top;}
tr.sub:nth-child(odd) {background-color: #ECF3F7;}
tr.sub:nth-child(even) {background-color: #E1EBF2;}
table.sub {border: 5px solid var(--SubTabBorder); background-color: var(--SubTabBkgnd); width: 380px;}
table.last {border: 1px solid var(--SubTabBorder); background-color: var(--SubTabBkgnd); width: 380px;}
/* Nouvelles règles si la fenêtre fait au plus 1200px de large */
@media screen and (max-width: 1200px)
{
div.main { width: 100vw;}
table.main {width: 97vw;}
table.sub {width: 27vw;}
table.last {width: 27vw;}
td.sub1 img { width: 14vw; } /* img inside td */
}
PHP
Code: Select all
<TABLE class="main" frame="box" rules="rows"><caption>Tous les sondages le plus récent en premier par ordre décroissant de votes exprimés</caption> <THEAD><TR><TH>Titre</TH><TH colspan=2>Votes</TH><TH>Option</TH><TH>Votants</TH></TR></THEAD>
<TBODY>
<?php
$RowBkgndEven="#ecf3f6";
$RowBkgndOdd="#e1ebf1";
$RowBkgnd="";
// connexion à la base
$db = mysqli_connect("localhost","my_user","my_password") or die('Erreur de connexion '.mysqli_error());
// sélection de la base
mysqli_select_db($db,your DB name) or die('Erreur de selection '.mysqli_error());
$results = mysqli_query($db,'select * from phpbb_topics WHERE poll_title != "" ORDER BY topic_status ASC, topic_id DESC ');
while($result = mysqli_fetch_array($results))
{
$RowBkgnd = ($RowBkgnd == $RowBkgndEven ? $RowBkgndOdd : $RowBkgndEven); /* condition ? true : false */
$topic = $result['topic_id'];
$options = mysqli_query($db,'select * from phpbb_poll_options WHERE topic_id = '.$topic.' AND poll_option_total != 0 ORDER BY poll_option_total DESC');
$NumRows = mysqli_num_rows($options);
$TotalVotes=0;
while($option = mysqli_fetch_array($options)) $TotalVotes=$TotalVotes+$option['poll_option_total'];
if ($TotalVotes == 0)
{
echo "<TR style='background-color:".$RowBkgnd."'><td>";
echo "<a href='Your board url/viewtopic.php?f=".$result['forum_id']."&t=".$result['topic_id']."'>".$result['poll_title']."</a>";
echo $result['topic_status'] == 1 ? "<br><img src='/images/Lock.gif'>" : "<br>"; /* condition ? true : false */
echo "<br>".$TotalVotes." votes ";
echo "</TD><td></td><td></td><td></td><td></td><td></td>";
}
else
{
echo "<TR style='background-color:".$RowBkgnd."'><td rowspan=".$NumRows.">";
echo "<a href='Your board url/viewtopic.php?f=".$result['forum_id']."&t=".$result['topic_id']."'>".$result['poll_title']."</a>";
echo $result['topic_status'] == 1 ? "<br><img src='/images/Lock.gif'>" : "<br>"; /* condition ? true : false */
echo "<br>".$TotalVotes." votes ";
echo "</TD>";
mysqli_data_seek($options, 0); /* Reset query pointer */
while($option = mysqli_fetch_array($options))
{
$Text = str_replace ("<s>","",$option['poll_option_text']);
$Text = str_replace ("</s>","",$Text);
$Percent=$option['poll_option_total']/$TotalVotes;
echo "<td nowrap><img src='PollBar.jpg' height=16 width='".Round(100*$Percent)."'> ".$option['poll_option_total']."</TD>";
echo "<td nowrap align = right> ".number_format(100*$Percent)."% : </TD>";
echo !strpos($Text,":") ? "<td>".$Text : "<td>".substr($Text,0,strpos($Text,":"))."<small>".substr($Text,strpos($Text,":")-strlen($Text))."</small>";
echo "</td><td><small>";
$Sep="";
$optionID = $option['poll_option_id'];
$votes = mysqli_query($db, 'select vote_user_id from phpbb_poll_votes WHERE topic_id = '.$topic.' AND poll_option_id = '.$optionID);
while($vote = mysqli_fetch_array($votes))
{
$users = mysqli_query($db, 'select username from phpbb_users WHERE user_id = '.$vote['vote_user_id']);
while($user = mysqli_fetch_array($users))
{
echo $Sep.$user['username'];
$Sep=", ";
}
}
echo "</small></TD></TR><TR style='background-color:".$RowBkgnd."'>";
}
}
echo "</TR>";
}
echo "</TBODY></TABLE>";
mysqli_close($db);