SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    psycho
    Join Date
    May 2000
    Location
    London
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi.

    Bit of a tricky problem here.

    I have a table called "releases", where each row is one release. They all have their own IDs.

    I also have a table called "releases_tl" which is the track listing for the releases. Each track has it's own review, so each release could have 15, 20 or more rows (according to how many tracks it has).

    Now, I want to be able to insert an optional link for each of my tracks. To do this, I so far have come up with this :

    http://216.74.114.212/php/tracklisting.php?ID=1

    The code for which is :

    Code:
    <?php
    
    if (!isset($submit)) {
    
    ?>
    
    
    <form action="tracklisting.php" method="post">
    <table width="100%" cellspacing="1" cellpadding="2">
    <?php
    
    include("/home/klone/db.inc");
    
    $result=mysql_query("SELECT * from releases_tl WHERE ID = '$ID'");
    
    while ($row = mysql_fetch_array($result) ) {
    
    ?>
    
    <tr bgcolor='#FFFFFF'>
    <td width="20%">
    <input type="text" name="<?php echo("$row[track_number]"); ?>">
    </td>
    <td width="80%"><font face="verdana" size="2"><b>
    <?php echo("$row[track_name]"); ?>
    </b></td>
    </tr>
    
    <?php
    
    }
    
    ?>
    
    <tr><td colspan="2" align="left"><input type="submit" name="submit" value="submit">
    </td>
    </tr>
    </form>
    </table>
    
    <?php
    
    }
    
    ?>
    Now, how would I process what the user types in, and insert it into the correct row ?

    Thanks
    James

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Two options:

    1) When your form is posted an array called $HTTP_POST_VARS holds all data passed from the form. So you could loop through the array and assign the data to each track. I've not used this personally so I assume that the value of the submit button is also in the array - so you would have to skip it.

    $count = count($HTTP_POST_VARS);

    for ($i = 0; $i < $count - 1; i++) {
    $tracks[$i] = $HTTP_POST_VARS[$i];
    }

    2) You can tell the form to put the data into your own array variable when you create the form. So where you have:

    <input type="text" name="<?php echo("$row[track_number]"); ?>">

    replace it with:

    <input type="text" name="tracks[]">

    NOTE you don't assign index numbers in the html - the data will be inserted into the array sequentially.

    I am very new to programming in PHP so someone tell me if the above is not correct.

    Cheers.

    <Edited by freakysid on 02-04-2001 at 07:47 AM>

  3. #3
    psycho
    Join Date
    May 2000
    Location
    London
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the great responce.

    I managed to sort it by putting them all into an array, then looping through that.

    Thanks again,
    James


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
  •