Poll in pagina web

Secţiune dedicată începatorilor.

Moderatori: Moderatori, Start Moderator


Avatar utilizator
a4tech
Senior Member
Mesaje: 211
Membru din: Joi Noi 03, 2005 12:55 am
Localitate: Bucuresti
Contact:

Mesajde a4tech » Sâm Sep 30, 2006 11:33 pm

Cu respect Paul !

vvv_vvv
PHPRomania Supporter
Mesaje: 5
Membru din: Sâm Sep 30, 2006 11:23 pm

Mesajde vvv_vvv » Sâm Sep 30, 2006 11:41 pm

Pagina de index:
<?php
require_once('config.php');

$cerereSQL = 'SELECT * FROM `intrebare`';
$rezultat = mysql_query($cerereSQL);
while($rand = mysql_fetch_array($rezultat)) {
echo '<table width="294" border="0" cellpadding="0" cellspacing="0">
<form name="votare" action="voteaza.php" method="post">
<tr>
<td width="294" height="28" valign="top"><p>'.$rand['intrebare'].'</p></td>
</tr>';
}

$cerereSQL = 'SELECT * FROM `optiuni`';
$rezultat = mysql_query($cerereSQL);
while($rand = mysql_fetch_array($rezultat)) {
echo '<tr>
<td height="19" valign="top">
<input name="optiune" type="radio" value="'.$rand['id'].'&'.$rand['voturi'].'"> '.$rand['optiune'].' </td>
</tr>';
}

echo '<tr>
<td height="14"></td>
</tr>
<tr>
<td height="24" valign="top"><input name="Voteaza" type="submit" id="Voteaza" value="Voteaza"> <br><br>
<a href="rezultate.php">Vezi rezultate</a></td>
</tr>
</form>
</table>';

?>
config
<?php
session_start();
set_time_limit(0);
error_reporting(E_ALL);

// Informatii baza de date

$AdresaBazaDate = "localhost";
$UtilizatorBazaDate = "root";
$ParolaBazaDate = "parola_baza";
$NumeBazaDate = "votare";

$conexiune = mysql_connect($AdresaBazaDate,$UtilizatorBazaDate,$ParolaBazaDate) or die("Nu ma pot conecta la MySQL!");
mysql_select_db($NumeBazaDate, $conexiune) or die("Nu gasesc baza de date!");

function addentities($data){
if(trim($data) != ''){
$data = htmlentities($data, ENT_QUOTES);
return str_replace('\\', '\', $data);
} else return $data;
} // End addentities() --------------

?>
votare
<?php
require_once('config.php');

if(!isset($_POST['Voteaza'], $_POST['optiune'])) {
echo 'Pentru a vota trebuie sa selectati o optiune. <br>
Apasati <a href="index.php">aici</a> pentru a va intoarce.';
} else {

$informatii = explode('&', $_POST['optiune']);
$id = $informatii[0];
$voturi = $informatii[1];

$cerereSQL = "UPDATE `optiuni` SET `voturi` = (".$voturi."+1) WHERE `id` = ".$id."";
mysql_query($cerereSQL);

echo 'Apasati <a href="rezultate.php">aici</a> pentru a vizualiza rezultatele';

}

?>
rezultate
<?php
require_once('config.php');

$cerereSQL = 'SELECT * FROM `intrebare`';
$rezultat = mysql_query($cerereSQL);
while($rand = mysql_fetch_array($rezultat)) {
echo '<table width="537" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="28" colspan="3" valign="top"><p>'.$rand['intrebare'].'</p></td>
</tr>';
}


$cerereSQL = 'SELECT * FROM `optiuni`';
$rezultat = mysql_query($cerereSQL);
$totale = mysql_result(mysql_query('SELECT SUM(voturi) FROM `optiuni`'),0);
while($rand = mysql_fetch_array($rezultat)) {

$procent = ($rand['voturi']*100)/$totale;
if($procent <= 0) $procent = 1;

echo '<tr>
<td width="113" height="19" valign="top"> '.$rand['optiune'].' </td>
<td width="115" valign="top">'.$rand['voturi'].' voturi </td>
<td width="309" valign="middle"><img src="linie.gif" width="'.$procent.'%" height="9"></td>
</tr>';
}

echo '<tr>
<td height="14"></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="24" colspan="3" valign="top"><a href="index.php">Inapoi la sistemul de votare</a> </td>
</tr>
</table>';

?>

Defapt este un exercitiu de la o carte php... da sunt varza nu stiu cum sa-l pun in pagina

Avatar utilizator
a4tech
Senior Member
Mesaje: 211
Membru din: Joi Noi 03, 2005 12:55 am
Localitate: Bucuresti
Contact:

marea rezolvare :))

Mesajde a4tech » Dum Oct 01, 2006 12:28 am

Cu respect Paul !

vvv_vvv
PHPRomania Supporter
Mesaje: 5
Membru din: Sâm Sep 30, 2006 11:23 pm

Mesajde vvv_vvv » Dum Oct 01, 2006 12:35 am


vvv_vvv
PHPRomania Supporter
Mesaje: 5
Membru din: Sâm Sep 30, 2006 11:23 pm

Mesajde vvv_vvv » Mar Oct 03, 2006 6:39 pm


Avatar utilizator
a4tech
Senior Member
Mesaje: 211
Membru din: Joi Noi 03, 2005 12:55 am
Localitate: Bucuresti
Contact:

Mesajde a4tech » Mar Oct 03, 2006 8:47 pm

Cu respect Paul !

bresti
Senior Member
Mesaje: 215
Membru din: Sâm Iun 24, 2006 5:03 am
Localitate: craiova
Contact:

Mesajde bresti » Joi Oct 05, 2006 7:53 am

vvv_vvv poate si pui si mysql sa il avema si noi "Expertii" :D
catalin


Înapoi la “PHP Incepători”

Cine este conectat

Utilizatori ce ce navighează pe acest forum: Niciun utilizator înregistrat și 22 vizitatori