PDA

View Full Version : help with making poll system dynamic



genia
10-05-2008, 09:01 PM
hi,
i'm trying to make poll system dynamic but i got stuck somewhere .
i use:
http://www.dbscripts.net/poll/

and mostly i mess with the config.php file.
this is how the orignal looks like:


$p = new Poll;
$p->question = "place you'r vote?"; // Question displayed to the user
$p->returnToURL = "../example.php"; // Specify the URL to return to for this poll; may be relative or absolute
$p->legend = "title"; // Form legend; leave empty for none
$p->control_type = $CONTROL_RADIOBUTTONS; // Control type; $CONTROL_RADIOBUTTONS or $CONTROL_COMBOBOX
$p->add_value("1", "a"); // Poll value ID and a display string
$p->add_value("2", "b");
$p->add_value("3", "c");
$p->add_value("4", "d");
$p->add_value("5", "e");
$VALID_POLLS["1"] = $p;


and this is what i changed it to:
(the db connection and table etc work fine):



function connectDB() {
require "conf.inc";
@mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
}

connectDB();
$query = "select * from poll";
$result=mysql_query($query);
$p = new Poll;
$p->question = "vote";
$p->legend = "title";
$p->control_type = $CONTROL_RADIOBUTTONS;
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$cityname = $row['cityname'];
$numofoptions = $row['numofoptions'];
$options = $row['options'];
$id2=$row['id'];
$id2=$id2+1;
$options2=explode("," , $options);
$p->add_value($id2-1,$options2[$id2-1]);

}

$VALID_POLLS['$id2-1'] = $p;

mysql_close();


the error comes from the poll system :"wrong poll id"

what i miss here?

thanks in advance

genia
10-06-2008, 08:34 AM
thanks for the links,i will try them.
i also changed a little my code:


function connectDB() {
require "conf.inc";
@mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

}

connectDB();
$query = "select * from poll";
$result=mysql_query($query);
$p = new Poll;
$p->question = "עבור מי תצביע בבחירות?(ההצבעה אנונימית)";
$p->legend = "משאל ראשון";
$p->control_type = $CONTROL_RADIOBUTTONS;
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$cityname = $row['cityname'];
$numofoptions = $row['numofoptions'];
$options = $row['options'];
$id2=$row['id'];
$options2=explode("," , $options);
for($i=$numofoptions-1;$i>=0;$i--){
$p->add_value('$i', '$options2[$i]');
}
$VALID_POLLS['$id2'] = $p;

}



mysql_close();


so now i get empty page.
i believe the problem is inputting the data from the for loop into the class
any suggestions on this?