Forum Moderators: coopster

Message Too Old, No Replies

Change content php file with a script

         

EftheM

9:26 pm on May 24, 2004 (gmt 0)



Hey all,

I am using a nice poll system to display polls on my website.

I use the following code to show the poll:

<?php mysql_connect('localhost','***','****'); mysql_select_db('***'); $ID = '1'; $Tabel = 'Stembussen'; include('stembus.php');?>

the "$ID = '1'" part is ofcourse the part that select to show which poll from the mysql database.

Is there a way that I can have a script make change this number.. because I want to show the latest poll on the website and not always poll id=1.

and ofcourse I do not want to manually change this file :)

thnx in advance!

keep it up with the great site here.

Birdman

10:44 pm on May 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello,

You probably need to go into the file stembus.php and edit the SQl select statement. It probably goes something like:

select * from polls where id = $ID

You can just change it to:

select * from polls order by id limit 0,1 desc

Sorry if that doesn't work out but we will need to see the actual SQL to really know what to do.

Birdman

EfEnrico

2:34 pm on May 26, 2004 (gmt 0)

10+ Year Member



allright here I am.. the same one as EftheM but I was blocked for having an illegal nickname.

here is the content of the code!

<?php

// Begin Stembus

$Stembus = mysql_fetch_object(mysql_query("SELECT * FROM $Tabel WHERE ID = '$ID'"));
$Antwoorden = explode("¦",ereg_replace("\¦$","",$Stembus->Antwoorden));
$Resultaten = explode("¦",ereg_replace("\¦$","",$Stembus->Resultaten));
$Gestemd = strstr("¦$Stembus->IPadressen","¦$REMOTE_ADDR¦");
$TotaalAantal = 0; while(list($nummer,$aantal) = each($Resultaten)) { $TotaalAantal += $aantal; }

if($stem && $deid == $ID &&!$Gestemd) {
if(isset($Antwoorden[$antwoord])) {
$Resultaten[$antwoord] = $Resultaten[$antwoord] + 1;
$ResultatenNieuw = implode("¦",$Resultaten);
$IPadressenNieuw = $Stembus->IPadressen . "$REMOTE_ADDR¦";
mysql_query("UPDATE $Tabel SET Resultaten = '$ResultatenNieuw', IPadressen = '$IPadressenNieuw' WHERE ID = '$ID'") or die(mysql_error());
$Stembus = mysql_fetch_object(mysql_query("SELECT * FROM $Tabel WHERE ID = '$ID'"));
$Antwoorden = explode("¦",ereg_replace("\¦$","",$Stembus->Antwoorden));
$Resultaten = explode("¦",ereg_replace("\¦$","",$Stembus->Resultaten));
$TotaalAantal = 0; while(list($nummer,$aantal) = each($Resultaten)) { $TotaalAantal += $aantal; }
$Gestemd = true;
}
else { $Gestemd = false; }
}

if($Gestemd) {
echo("<table cellpadding=0 cellspacing=0 border=0><tr><td colspan=2 class=polltitle>$Stembus->Vraag</td></tr><tr><td colspan=2 class=pollvotes>($TotaalAantal stemmen)</td></tr><tr>
<td colspan=2 class=polloptions>&nbsp;</td>
</tr>");
while(list($nummer,$hetantwoord) = each($Antwoorden)) {
$hetantwoord = trim($hetantwoord);
$plaatje = round((($Resultaten[$nummer] / $TotaalAantal) * 50),1);
$procent = round((($Resultaten[$nummer] / $TotaalAantal) * 100),1);
$server = '$_SERVER["DOCUMENT_ROOT"].';
echo("
<tr><td class=polloption>$hetantwoord</td><td class=pollimage ><img src=/mundus/images/pollbalk.gif height=10 width=$plaatje>&nbsp;&nbsp;&nbsp;<span class=pollpercentage>$procent%</span></td></tr>\n");
}
echo("
<tr>
<td colspan=2>&nbsp;</td>
</tr>
<tr><td colspan=2><b>Je hebt al gestemd.</b></td></tr></table>
");
}

else {
echo("<table cellpadding=0 cellspacing=0 border=0><tr><td colspan=2 class=polltitle>$Stembus->Vraag</td></tr><tr><td colspan=2 class=pollvotes>($TotaalAantal stemmen)</td></tr><tr>
<td colspan=2 class=polloptions>&nbsp;</td>
</tr>
<form method='post'>");
while(list($nummer,$hetantwoord) = each($Antwoorden)) {
$hetantwoord = trim($hetantwoord);
echo("<tr><td class=polloptions><input type=radio name=antwoord value='$nummer'> $hetantwoord</td></tr>\n");
}

echo("</table><br>
<input type=hidden name=deid value=$ID>
<input type=submit name='stem' value='Breng je stem uit' style='font-size: 8pt'>
</form>");
}

// Einde Stembus

?>

EfEnrico

12:56 pm on Jun 3, 2004 (gmt 0)

10+ Year Member



no one here to help me out any further?

sorry for the bump.. but I hate to post it another time..

vincevincevince

1:48 pm on Jun 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



change line 3 to:

$Stembus = mysql_fetch_object(mysql_query("SELECT * FROM $Tabel ORDER BY ID DESC LIMIT 1"));

EfEnrico

2:34 pm on Jun 3, 2004 (gmt 0)

10+ Year Member



okay thanks for your reply..

it worked! but not quite good enough..

I made another poll and indeed the last one is showed on the mainpage.

but when I vote to the poll2, the vote is being counted at poll1. And it also doesn't remember the number of votes as wel as the ip's anymore..

can you help me out?

EfEnrico

3:06 pm on Jun 3, 2004 (gmt 0)

10+ Year Member



okay well I just tried some things out.. and it is working now! it looks like this if you see some bugs or security gaps please let me know!

<?php
mysql_connect('localhost','***','****');
mysql_select_db('****'); $ID = '1'; $Tabel = 'Stembussen';
?>

<?php

// Begin Stembus

$Stembus = mysql_fetch_object(mysql_query("SELECT * FROM $Tabel ORDER BY ID DESC LIMIT 1"));
$Antwoorden = explode("¦",ereg_replace("\¦$","",$Stembus->Antwoorden));
$Resultaten = explode("¦",ereg_replace("\¦$","",$Stembus->Resultaten));
$Gestemd = strstr("¦$Stembus->IPadressen","¦$REMOTE_ADDR¦");
$TotaalAantal = 0; while(list($nummer,$aantal) = each($Resultaten)) { $TotaalAantal += $aantal; }

if($stem && $deid == $ID &&!$Gestemd) {
if(isset($Antwoorden[$antwoord])) {
$Resultaten[$antwoord] = $Resultaten[$antwoord] + 1;
$ResultatenNieuw = implode("¦",$Resultaten);
$IPadressenNieuw = $Stembus->IPadressen . "$REMOTE_ADDR¦";
mysql_query("UPDATE $Tabel SET Resultaten = '$ResultatenNieuw', IPadressen = '$IPadressenNieuw' ORDER BY ID DESC LIMIT 1") or die(mysql_error());
$Stembus = mysql_fetch_object(mysql_query("SELECT * FROM $Tabel ORDER BY ID DESC LIMIT 1"));
$Antwoorden = explode("¦",ereg_replace("\¦$","",$Stembus->Antwoorden));
$Resultaten = explode("¦",ereg_replace("\¦$","",$Stembus->Resultaten));
$TotaalAantal = 0; while(list($nummer,$aantal) = each($Resultaten)) { $TotaalAantal += $aantal; }
$Gestemd = true;
}
else { $Gestemd = false; }
}