Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2010
    Posts
    35
    Thanks
    6
    Thanked 0 Times in 0 Posts

    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; 09-03-2011 at 03:00 AM.

  • #2
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    486
    Thanks
    10
    Thanked 33 Times in 32 Posts
    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. ^_^

  • #3
    New Coder
    Join Date
    Aug 2010
    Posts
    35
    Thanks
    6
    Thanked 0 Times in 0 Posts
    I am trying to get a dropdown list of all matches.

  • #4
    New Coder
    Join Date
    Aug 2011
    Posts
    51
    Thanks
    6
    Thanked 12 Times in 12 Posts
    Quote 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

  • Users who have thanked ASTP001 for this post:

    mrkfc (09-03-2011)

  • #5
    New Coder
    Join Date
    Aug 2010
    Posts
    35
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Thank you very much


  •  

    Posting Permissions

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