SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I access array values within the query string

    Hi,

    I'm using a form which a user predicts winning margins in a football fixtures list

    Code PHP:
    while ($row = $res->fetch_array(MYSQLI_NUM)) {
    		echo '<input type="hidden" name="fixture['.$row[0].']" value ="">';
    		echo '<tr><td>'.$row[2].'</td>';
    		echo '<td class="fixtures"><select name = "team1" id="team1"/><option value=""></option>';
    		for ($i = 1; $i < 31; $i++)
    			echo '<option value="'.$i.'">'.$i.'</option>';
    		echo '</td>';
    		echo '<td class="fixtures"><input type="checkbox" name="f'.$row[0].'draw" id="f'.$row[0].'draw" value="1"/></td>';
    		echo '<td class="fixtures"><select name = "team2" id="team2"/><option value=""></option>';
    		for ($i = 1; $i < 31; $i++)
    			echo '<option value="'.$i.'">'.$i.'</option>';
    		echo '</td>';
    		echo '<td>'.$row[4].'</td>';
    		echo '</tr>';

    The code above retrieves a round of fixtures from a database and outputs team names, dropdown lists of winning margins and a checkbox for a draw e.g. Team 1 beats Teams 2 by 5 goals in fixture 1

    I want to be able to insert each fixture prediction into my database when the user submits the form

    At the moment my query string looks like

    prelatfixh.php?fixture[1]=&team1=5&team2=&fixture[2]=&team1=&team2=&fixture[3]..........

    How do I strip out the relevant value (in the example above - team1 in fixture 1 winning by 5 goals) for each fixture

    Is this even the smartest way to approach this ?

    Many thanks in advance

    aor

  2. #2
    SitePoint Addict
    Join Date
    Apr 2006
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Those values are stored in a special variable in PHP: $_REQUEST

    http://us3.php.net/manual/en/reserve...es.request.php

    Basically, you need to craft an SQL insert query to insert the data into your database using those values and the mysql_query function.

    http://us3.php.net/manual/en/function.mysql-query.php

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the reply adwatson

    i am using $_GET for testing purposes but I'm not clear on how to get a value when its part of an array.

    I've tried the following code but it doesnt display any value

    Code PHP:
    foreach($_GET['fixture'] as $key => $value)
    		echo 'Fixture'.$key.' - '.$value.'<br/>';

    produces Fixture 1 - ..........

    I want to be able to determine which team won and the margin by accessing each fixture and display

    Fixture 1 - team1=4

    if the team1 variable is set to 4 from a URL fixture[1]=&team1=4&team2=&fixture[2]......so that it only pulls a set value

    I can then build the insert statement around these values where i can insert into database the fixture id, winning team, winning margin

    I think I've found another way to access it (modifying the original form) but it doesnt seem efficient to me and thought there may be a simple method that I just havent discovered yet

    anyway thanks again

  4. #4
    SitePoint Addict X-Cart's Avatar
    Join Date
    May 2009
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try looking at serialize() and unserialize() for passing array and object data via POST or GET.
    X-Cart - tens thousands live online shops worldwide
    Follow us on Twitter

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that. I'm not sure how I'm going to use it though. Will I just end up with same issue but the string just stored differently ?

    Anyone else got any idea on if it is possible to get one value from each array member ?

    Each fixture will only ever have one value...I've just got to select either team or a draw.....


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
  •