Hallo
Hat schon jemand einen Random Survey Block hingekriegt?
Ich bastle nämlich gerade daran und habe das Problem, dass zwischendurch ein Block ohne Umfrage, also nur mit Button und Link zu Ergebniss und anderen Umfragen, erscheint.
Weiss jemand Rat?
....
if (eregi("block-Survey.php", $PHP_SELF)) {
Header("Location: index.php");
die();
}
global $prefix, $multilingual, $currentlang, $dbi, $boxTitle, $content, $pollcomm, $user, $cookie;
if ($multilingual == 1) {
$querylang = "WHERE planguage='$currentlang' AND artid='0'";
} else {
$querylang = "WHERE artid='0'";
}
$result = sql_query("SELECT pollID FROM $prefix"._poll_desc." $querylang ORDER BY pollID DESC LIMIT 1", $dbi);
$numrows = sql_num_rows($result, $dbi);
mt_srand((double)microtime()*1000000);
$pollID = sql_fetch_row($result, $dbi);
$pollID = mt_rand(1,($pollID[0]));
if(!isset($url))
$url = sprintf("pollBooth.php?op=results&pollID=%d", $pollID);
$content .= "<form action=\"pollBooth.php\" method=\"post\">";
$content .= "<input type=\"hidden\" name=\"pollID\" value=\"".$pollID."\">";
$content .= "<input type=\"hidden\" name=\"forwarder\" value=\"".$url."\">";
$result = sql_query("SELECT pollTitle, voters FROM $prefix"._poll_desc." WHERE pollID=$pollID", $dbi);
list($pollTitle, $voters) = sql_fetch_row($result, $dbi);
$boxTitle = _SURVEY;
$content .= "<font class=\"content\"><b>$pollTitle</b></font><br><br>\n";
$content .= "<table border=\"0\" width=\"100%\">";
for($i = 1; $i <= 12; $i++) {
$result = sql_query("SELECT pollID, optionText, optionCount, voteID FROM $prefix"._poll_data." WHERE (pollID=$pollID) AND (voteID=$i)", $dbi);
$object = sql_fetch_object($result, $dbi);
if(is_object($object)) {
$optionText = $object->optionText;
if($optionText != "") {
$content .= "<tr><td valign=\"top\"><input type=\"radio\" name=\"voteID\" value=\"".$i."\"></td><td width=\"100%\"><font class=\"content\">$optionText</font></td></tr>\n";
}
}
}
$content .= "</table><br><center><font class=\"content\"><input type=\"submit\" value=\""._VOTE."\"></font><br>";
if (is_user($user)) {
cookiedecode($user);
}
for($i = 0; $i < 12; $i++) {
$result = sql_query("SELECT optionCount FROM $prefix"._poll_data." WHERE (pollID=$pollID) AND (voteID=$i)", $dbi);
$object = sql_fetch_object($result, $dbi);
$optionCount = $object->optionCount;
$sum = (int)$sum+$optionCount;
}
$content .= "<br><font class=\"content\"><a href=\"pollBooth.php?op=results&pollID=$pollID&mode=$cookie[4]&order=$cookie[5]&thold=$cookie[6]\"><b>"._RESULTS."</b></a><br><a href=\"pollBooth.php\"><b>"._POLLS."</b></a><br>";
if ($pollcomm) {
list($numcom) = sql_fetch_row(sql_query("select count(*) from $prefix"._pollcomments." where pollID=$pollID", $dbi), $dbi);
$content .= "<br>"._VOTES.": <b>$sum</b> <br> "._PCOMMENTS." <b>$numcom</b>\n\n";
} else {
$content .= "<br>"._VOTES." <b>$sum</b>\n\n";
}
$content .= "</font></center></form>\n\n";
Hi JaneWayne
es muss die Gesamtzahl (nicht die höchste id) der Polls ermittelt werden.
Aus dieser die Zufallszahl bilden.
Anhand dieser Zufallszahl, den x-ten Datensatz ermitteln.
Die poll-ID dieses Datensatzes ist dann die zufällige pollid
Hallo Andi
Ich kenne ja den Spruch "learning by doing", aber wie lern ich was, wenn ich nicht weiss, was ich tue :P
Also, ich habe hoffentlich rausgefunden, wie ich die gesamte Anzahl der PollID's ermittle:
$result = sql_query("SELECT COUNT(PollID) AS total FROM nuke_poll_desc", $dbi);
aber was kommt danach?
Aus dieser die Zufallszahl bilden: $result = mt_rand(0,($result)); ??
Anhand dieser Zufallszahl, den x-ten Datensatz ermitteln: $result2 = sql_query("select PollID from nuke_poll_desc where pollID='$result', $dbi);??
Die poll-ID dieses Datensatzes ist dann die zufällige pollid:
Es will einfach nicht , ausser tonnenweise Supplied argument is not a valid MySQL result resource Fehlermeldungen :cry
hihihi, :D
habe jetzt gleich nen kompletten Block gebastelt....
//modules.php?name=Downloads&d_op=search&query=zufällige%20Umfrage
@JaneWayne :)
Die sql-fehler kamen von in den Abfragen. Die müssen wohl irgendwie beim kopieren des Codes da rein gerutscht sein.
Habe es jetzt doch ganz anders gemacht als gedacht.
Sorry für den kurzen Beitrag Heute Mittag, war kurz vor Feierabend..... :redhead:
[Editiert am 27.6.2002 von SiteAdmin Andi]
Hallo Andi
Vielen herzlichen Dank für Deine Hilfe, mein Tag ist gerettet :D
Musste lediglich die "Links" für mein Nuke 5.4 anpassen und in Zeile 39 das
print "<br>$recordnr, $pollID, $pollTitle";
rausnehmen, denn da erschien, zumindest bei mir, oberhalb des Blockes eine Zeile mit diesen Angaben.
Aber sonst: Perfekt!!!
:thumbup:
Also, vielen Dank noch mal, ich setz mich jetzt hinter mein "Kalender-Topis-Update-Problem"
PS: Den Feierabend hast Du Dir wirklich redlich verdient :P
uuups,:puzz
da hab ich doch glatt wieder ne debugausgabe vergessen :cry
Die print-Zeile gehört da natürlich nicht hin.
Super dass es funzt :thumbup: :D :) :D
HI,
Super Idee :D :D
Super Ausführung :D :D
einfach Klasse...