Web Analytics Made Easy -
StatCounter PHP MySQL multiple resuls array. - CodingForum

Announcement

Collapse
No announcement yet.

PHP MySQL multiple resuls array.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Resolved PHP MySQL multiple resuls array.

    I am trying to make a PHP MySQL script to get multiple results from a database and then display them in a HTML form list.
    Here is my current code:
    PHP Code:
    <?php
    include_once "connect_to_mysql.php";
    $fetchmatch mysql_query("SELECT * FROM matches WHERE hteam='$team' and played='no'");  //get matches for your team
    //get the varialbes into an array
    $matchcount mysql_num_rows($fetchmatch);
    while(
    $row2 mysql_fetch_assoc($fetchmatch)){
    $matchid $row2["id"];
    $ateam $row2["ateam"];
    }
    $matchname "$team vs $ateam";
    ?>
    PHP Code:
    <select name="matchid" id="matchid">
                                   <option value="<?php echo"$matchid"?>" selected="selected"><?php echo"$matchname"?></option>
                                 </select>
    Any help would be appreciated, thanks
    Last edited by mrkfc; Sep 2, 2011, 11:00 PM.

  • #2
    Ok, what exactly are you trying to do? A drop down list of all the matches or a drop down list of all the teams??
    Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
    I always recommend the HEAD First series of books for learning a new coding language. ^_^

    Comment


    • #3
      I am trying to get a dropdown list of all matches.

      Comment


      • #4
        Originally posted by mrkfc View Post
        I am trying to make a PHP MySQL script to get multiple results from a database and then display them in a HTML form list.
        Here is my current code:
        PHP Code:
        <?php
        include_once "connect_to_mysql.php";
        $fetchmatch mysql_query("SELECT * FROM matches WHERE hteam='$team' and played='no'");  //get matches for your team
        //get the varialbes into an array
        $matchcount mysql_num_rows($fetchmatch);
        while(
        $row2 mysql_fetch_assoc($fetchmatch)){
        $matchid $row2["id"];
        $ateam $row2["ateam"];
        }
        $matchname "$team vs $ateam";
        ?>
        PHP Code:
        <select name="matchid" id="matchid">
                                       <option value="<?php echo"$matchid"?>" selected="selected"><?php echo"$matchname"?></option>
                                     </select>
        Any help would be appreciated, thanks
        ok, what you need to do is store match id and ateam as an array... so to do that do
        PHP Code:
        $matchid[] = $row2["id"];
        $ateam[] = $row2["ateam"]; 
        and so all the entries will be stored in there.
        and then to make a list of all the options find out the number of entries in the array by doing
        PHP Code:
        $indexCount count($matchid); 
        and run a loop for the options
        PHP Code:
        for($index=0$index $indexCount$index++) {
         echo 
        '<option value="' $matchid '" selected="selected">"' $matchname '</option>';

        also, when you're setting
        PHP Code:
        $matchname "$team vs $ateam"
        it should be
        PHP Code:
        $matchname $team " vs " $ateam

        Comment


        • #5
          Thank you very much

          Comment

          Working...
          X