SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member illusionaz's Avatar
    Join Date
    Jan 2003
    Location
    USA
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with Poll - PHP MYSQL database from IPB

    I can't seem to figure out how to break this down from an IPB forum to show the choices and results of a poll on my site. Any help greatly appreciated

    choices text Yes NULL

    And here is what is inside that column:

    a:1:{i:1;a:3:{s:8:\"question\";s:18:\"What do you think?\";s:6:\"choice\";a:2:{i:1;s:3:\"Yes\";i:2;s:2:\"No\";}s:5:\"votes\";a:2:{i:1;i:1;i:2;i:0;}}}
    Adam H. Paoli
    Owner and Operator

    Paoli Web Design

  2. #2
    SitePoint Member illusionaz's Avatar
    Join Date
    Jan 2003
    Location
    USA
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok I got it unserialized into an array, but I could use some help displaying the array. This is what i get when I print it.

    Array ( [question] => Who is going to be the Wild Cards in the AFC? [multi] => 1 [choice] => Array ( [1] => Cincinnati [2] => Jacksonville [3] => New York Jets [4] => Kansas City [5] => Denver [6] => Other ) [votes] => Array ( [1] => 0 [2] => 0 [3] => 1 [4] => 1 [5] => 0 [6] => 0 ) )
    Adam H. Paoli
    Owner and Operator

    Paoli Web Design

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    If the array you mentions creates a form that users fill in, look at the HTML of the form. If the "action" is GET then you can access what the user chose by doing:

    print_r($_GET);

    if its a POST action then use print_r($_POST)

    Is that what you mean?

  4. #4
    SitePoint Member illusionaz's Avatar
    Join Date
    Jan 2003
    Location
    USA
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want to show the results of the poll, but I can't display the arrays inside the array. There are 2 more arrays, choice and votes.
    Adam H. Paoli
    Owner and Operator

    Paoli Web Design

  5. #5
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    I think I get you, do you mean that from your array example you should show:

    Jets = 1
    KC = 1

  6. #6
    SitePoint Member illusionaz's Avatar
    Join Date
    Jan 2003
    Location
    USA
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yea
    Adam H. Paoli
    Owner and Operator

    Paoli Web Design

  7. #7
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    PHP Code:
    $t = Array ( 
    "question" => "Who is going to be the Wild Cards in the AFC?",  
    "multi" => 1
    "choice" => Array ( => "Cincinnati"=> "Jacksonville"=> "New York Jets"=> "Kansas City",
    => "Denver"=> "Other" ),
    "votes" => Array ( => 0=> 0=> 1=> 1=> 0=> 
    );
    print_r($t);
    echo 
    '<hr>';

    foreach (
    $t['choice'] as $k=>$v){
    echo 
    $v ' - ' $t['votes'][$k] .' votes <br>' ;


    I know there must be a nicer way of doing it, but that works

  8. #8
    SitePoint Member illusionaz's Avatar
    Join Date
    Jan 2003
    Location
    USA
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you so much i tried forever but your code worked like a charm!
    Adam H. Paoli
    Owner and Operator

    Paoli Web Design

  9. #9
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    My pleasure, honing up my array skills for my exam.

    Heres one up, only show those with results > 0 and order them by number of votes, in reverse order....
    PHP Code:
    $t = Array (
    "question" => "Who is going to be the Wild Cards in the AFC?",  
    "multi" => 1,
    "choice" => Array ( => "Cincinnati"=> "Jacksonville"=> "New York Jets"=> "Kansas City",
    => "Denver"=> "Other" ),
    "votes" => Array ( => 0=> 0=> 1=> 2=> 3=> )
    );

    arsort($t['votes']);  // magic here

    print_r($t);  // some debug
    echo '<hr>'// just a delimiter of debug

    foreach ($t['votes'] as $k=>$v){

     if(
    $t['votes'][$k] > ){
       echo 
    $v ' - ' $t['choice'][$k] .' votes <br>' ;
     } 

    Gives:
    3 - Denver votes
    2 - Kansas City votes
    1 - New York Jets votes

    Did you know there are about 80 array functions in PHP? Nor me.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •