SitePoint Sponsor

User Tag List

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

    arrays and all that mess

    I have a table of CD releases - each CD has it's own ID.

    Then I have a table of the track listings - each track has it's own row, and an ID column linking back to the relevant release

    This table's structure is this :

    -ID (the ID of the corresponding release in the other table)
    -track_number
    -track_name
    -track_url (an optional link to a real audio clip)
    -disk (ie if it's a 4CD box set, if it's on the 1,2,3rd or whatever)

    Now, my problem is with adding the links to Real AUdio clips to the tracks.

    This is the code I'm currently using to go about it, but as you'll be able to see, it's flawed as I cannot work out a way to distinguish each disk, because at the moment there can be this situation :

    eg. Release ID 5 has 3 CD's - I want to add a track_url link to track 3 on disk 1, yet my system add's it to all disks.

    Here is my code :

    PHP 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="track[<?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="hidden" name="disk" value="<?php echo("$row[disk]"); ?>">
    <input type="hidden" name="ID" value="<?php echo("$ID"); ?>">
    <input type="submit" name="submit" value="submit">
    </td>
    </tr>
    </form>
    </table>

    <?php

    }

    ?>

    <?php

    if ($submit == "submit") {


    include(
    "/home/klone/db.inc");

    while(list(
    $key$val) = each($track)) {
    if (isset(
    $track)) {

    mysql_query("UPDATE releases_tl SET

    track_url = '
    $val' WHERE ID = '$ID' and track_number = '$key' and disk='$disk'

    "
    );


    }
    }
    echo(
    "Tracks added.");
    }
    ?>
    Thanks for the help.
    James

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    (deleted)
    Last edited by 7stud; May 30, 2001 at 18:42.

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

    OK - so now I have

    PHP Code:
    <input type="text" name="track[<?php echo("$row[track_number]"); ?>]">
    <input type="hidden" name="disk" name="disk[<?php echo("$row[disk]"); ?>]">
    How would I deal with the disk array? Thing is, I didn't write the array looping bit myself, so I don't really understand it.

    Cheers
    J

  4. #4
    psycho
    Join Date
    May 2000
    Location
    London
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is really urgent for a client so if any of you gurus out there are reading this but not replying, please help !

    J

  5. #5
    SitePoint Zealot Overgrow's Avatar
    Join Date
    Jan 2001
    Location
    Your basement
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you change the isset($track) part?

    Use if (!empty($track)) instead
    Overgrow the Government: The Edge Forums
    presented by Overgrow Marijuana Magazine

    *warning: adult content

  6. #6
    psycho
    Join Date
    May 2000
    Location
    London
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    doesn't seem to have solved the problem at all. Thanks anyway !

  7. #7
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    If you don't understand the basics of php, it is probably not a good idea to tell clients you are a php programmer and take on php programming jobs.

  8. #8
    psycho
    Join Date
    May 2000
    Location
    London
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    up yours 7stud!

  9. #9
    Talk to the /dev/null Theiggsta's Avatar
    Join Date
    Mar 2001
    Location
    Tampa, FL
    Posts
    376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I barely know coldfusion, but got offered a job to be lead CFML programmer for a new company.
    Aaron "Theiggsta" Kalin
    Pixel Martini
    Ruby and Rails Developer

  10. #10
    Hi there! Owen's Avatar
    Join Date
    Jan 2000
    Location
    CA
    Posts
    1,165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got offered a job programming java and don't know it!

    Anyway, I'm not sure what thep problem is. Try printing out variables at critical points and seeing if they match what is expected.

    Owen

  11. #11
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Theiggsta: Did you take it?

    Owen: I am on Chapter 6 of a java book, can I get a job in upper management at SUN?

  12. #12
    Your daddy. WALoeIII's Avatar
    Join Date
    Apr 2001
    Location
    USA
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is kind of a guess, I had a similar problem with a loop.

    When you selected everything ( * ) you got all the potential disks from mysql, what you need to do is, instead of passing the disk as a hidden form element, make it editable:

    PHP 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="track[<?php echo("$row[track_number]"); ?>]">
    </td>
    <td width="20%">
    <input type="text" name="disk[<?php echo("$row[disk]"); ?>]">
    </td>
    <td width="60%"><font face="verdana" size="2"><b>
    <?php echo("$row[track_name]"); ?>
    </b></td>
    </tr>

    <?php

    }

    ?>

    <tr><td colspan="3" align="left">
    <input type="hidden" name="ID" value="<?php echo("$ID"); ?>">
    <input type="submit" name="submit" value="submit">
    </td>
    </tr>
    </form>
    </table>

    <?php

    }

    ?>

    <?php

    if ($submit == "submit") {


    include(
    "/home/klone/db.inc");

    while(list(
    $key$val) = each($track)) {
    if (isset(
    $track)) {

    mysql_query("UPDATE releases_tl SET

    track_url = '
    $val' WHERE ID = '$ID' and track_number = '$key' and disk='$disk'

    "
    );


    }
    }
    echo(
    "Tracks added.");
    }
    ?>
    That way you can select the track number and the disk number. If that isn't right, then I have no idea. Good Luck!

  13. #13
    Talk to the /dev/null Theiggsta's Avatar
    Join Date
    Mar 2001
    Location
    Tampa, FL
    Posts
    376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by 7stud
    Hi,

    Theiggsta: Did you take it?

    Nope, they wanted me to relocate, it was bad timing.
    Aaron "Theiggsta" Kalin
    Pixel Martini
    Ruby and Rails Developer

  14. #14
    Hi there! Owen's Avatar
    Join Date
    Jan 2000
    Location
    CA
    Posts
    1,165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by 7stud

    Owen: I am on Chapter 6 of a java book, can I get a job in upper management at SUN?
    Probably... you couldn't possibly do any worse then they are doing now.

    Owen


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
  •