SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2002
    Location
    london
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help needed with arrays

    hey amigos

    i have a table with these fields in each row...

    commentid (autoincrement int key)
    commentname (text)
    commentmail (text)
    commentsite (text)
    commentcomment (text)
    commentdte (timestamp)

    i have this code...

    $query = "SELECT commentid, commentname, commentmail, commentsite, commentcomment, commentdte FROM $table_name ORDER BY commentid DESC";
    $res = mysql_query($query);

    // build the display array

    while($row = @mysql_fetch_array($res)) {
    $disp_array[$row[commentid]] = $row[commentname];
    }


    then this to display...


    <form>
    <?
    while(list($id,$comment) = @each($disp_array)) { ?>
    <input name="name[<?= $id ?>]" size="30" maxlength="70" value="<?= $comment ?>">
    <?}?>
    </form>


    what this does is create four input textboxes

    (there are four entries in the table)

    what i want to be able to do is create other textboxes to include all the other info for each row of my table. thing is i cant work out how the arrays are supposed to go

    can anyone help?

    thanks
    give me all your lentils

  2. #2
    Your daddy. WALoeIII's Avatar
    Join Date
    Apr 2001
    Location
    USA
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't get what you are asking.

  3. #3
    Action! filmfoto's Avatar
    Join Date
    Dec 2001
    Location
    Sweden
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    PHP Code:
    $count 0;

    while(
    $row mysql_fetch_array($res)) { 
        
    $disp_array[$count] = array( "commentid"         => $row['commentid'],
                                     
    "commentname"        => $row['commentname']
                                     
    "commentmail"        => $row['commentmail'],
                                     
    "commentsite"        => $row['commentsite'],
                                     
    "commentcomment"    => $row['commentcomment'],
                                     
    "commentdte"        => $row['commentdte']
                                    );
        
    $count++;



    for (
    $i 0$i sizeof($disp_array); $i++) {

        echo(
    "<form>\n");
        echo(
    "<input name=\"name[$dispaly_array[$i]['commentid']]\" type=\"text\" size=\"30\" maxlength=\"70\" value=\"$dispaly_array[$i]['commentname']\">\n");
        echo(
    "<input name=\"mail[$dispaly_array[$i]['commentid']]\" type=\"text\" size=\"30\" maxlength=\"70\" value=\"$dispaly_array[$i]['commentmail']\">\n");
        echo(
    "</form>\n");

    }

    etc... 

    Haven't checked it myself but should work for you. Just continue filling in the input field with the other array members and you should be set.


    Cheers

  4. #4
    purple monkey dishwasher scoates's Avatar
    Join Date
    Nov 2001
    Location
    Montreal
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $count = 0;
    $disp_array[$count]
    and
    $count++

    are redundant in this case

    just use:
    $disp_array[]

    not that it's wrong, though..
    (-:

    S

  5. #5
    Action! filmfoto's Avatar
    Join Date
    Dec 2001
    Location
    Sweden
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Very true!

  6. #6
    SitePoint Zealot
    Join Date
    Jan 2002
    Location
    london
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i did it like this in the end:

    PHP Code:
    $query "SELECT * FROM $table_name ORDER BY commentid DESC";
    $res mysql_query($query);

    // build the display array 

    while($row = @mysql_fetch_array($res)) {
    $comment = array(name=>$row[commentname],mail=>$row[commentmail],site=>$row[commentsite],comm=>$row[commentcomment],dte=>$row[commentdte]);
      
    $disp_array[$row[commentid]] = $comment;

    then

    PHP Code:
    while(list($id,$comment) = @each($disp_array)) { ?>
    <tr><td>Date added:<?= $comment[dte?></td><td align='center' rowspan='5'><input type="checkbox" name="delete[<?= $id ?>]" value="yes"></td></tr>
    <tr><td><input name="name[<?= $id ?>]" size="30" maxlength="70" value="<?= $comment[name?>"></td></tr>
    <tr><td><input name="name[<?= $id ?>]" size="30" maxlength="70" value="<?= urlencode($comment[mail]) ?>"></td></tr>
    <tr><td><input name="name[<?= $id ?>]" size="30" maxlength="70" value="<?= urlencode($comment[site]) ?>"></td></tr>
    <tr><td><TEXTAREA NAME="name[<?= $id ?>]" ROWS=4 COLS=26 WRAP="virtual"><?= $comment[comm?></TEXTAREA></td></tr>
    <? ?>
    was that a long way round to it?
    give me all your lentils


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
  •