SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    foreach problem...

    Hi,

    I've got the below code that queries the database, grabs all the records and places them into an array. I then use a foreach at certain sections to print out the desired results. However for the foreach I have below it should print out 1 records although it is print 2 records, that are exactly the same. There are also only two records in the database which are totally different. So does anyone have any idea why this is doing this?

    PHP Code:
    $stuff mysql_query("SELECT * FROM " $pre "templates");
    if(!
    $stuff) {
    errorMsg($l_query);
    print 
    mysql_error();
    } else {
    while (
    $stuffa mysql_fetch_array($stuff)) {
    $ID $stuffa["ID"];
    $Name $stuffa["Name"];
    $Value $stuffa["Value"];
    $Type $stuffa["Type"];

    $more = array("ID" => $ID"Name" => $Name"Value" => $Value"Type" => $Type);
    }

    print 
    "<b>Footers</b><br>";
    reset ($more);
    foreach (
    $more as $key => $value) {
    $more[$key]["ID"] = $ID;
    $more[$key]["Name"] = $Name;
    $more[$key]["Value"] = $Value;
    $more[$key]["Type"] = $Type;

    if(
    $Type[$value] == "1") {
    echo 
    "$Name <a href='$PHP_SELF?fid=$ID&action=editfooter'>Edit</a>";
    echo 
    " <a href='$PHP_SELF?fid=$ID&action=deletefooter'>Delete</a><br>\n";
    }
    }

    Thanks
    -Peter McNulty

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change

    PHP Code:
    $more = array("ID" => $ID"Name" => $Name"Value" => $Value"Type" => $Type); 
    to

    PHP Code:
    $more[] = array("ID" => $ID"Name" => $Name"Value" => $Value"Type" => $Type); 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •