Help with arrays

Discussion in 'PHP' started by amorph, May 31, 2007.

  1. #1
    It seems so hard with the arrays that my head i sabout to explode. I have a database from which I'm supposed to create some arrays.

    For example 2 tables with a survey options and answers (questions and number of answers):

    are you married? should return the following results:

    yes = 2; (2 answered with yes)
    No =4; (4 answered with no)

    Now the SQL :

    $sql = "SELECT poll_options.poll_option AS the_option, COUNT(poll_answers.ID) AS answers FROM poll_options LEFT JOIN poll_answers ON(poll_answers.ID_option=poll_options.ID) WHERE ID_question='".mysql_real_escape_string($row_question['ID'])."' GROUP BY poll_options.ID";
    PHP:
    how do I create an array to look like this:

    $data = array(
    array('yes', 'no'), array(2, 4)
    );
    PHP:

    Thank you.
     
    amorph, May 31, 2007 IP
  2. ndreamer

    ndreamer Guest

    Messages:
    339
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    why not just return the data as

    $data = array('yes' => 2, 'no' => 4);
    Code (markup):
    then you can access it with $data['yes'] for the yes votes, $data['no'] for the no votes.
     
    ndreamer, May 31, 2007 IP
  3. amorph

    amorph Peon

    Messages:
    200
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Becaus I don't need it this way. Anyways, I got it working. Thanks.
     
    amorph, May 31, 2007 IP