Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7610973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:32:59+00:00 2026-05-31T01:32:59+00:00

I have this foreach statement that is supposed to cycle through an array, but

  • 0

I have this foreach statement that is supposed to cycle through an array, but instead of outputting:

[checkbox] Something Here

It will instead output this:

[checkbox] [checkbox] Something here

Basically, the if statement isn’t being skipped over, but the foreach loop is looking at the values in my array (in this case I only have 2 for testing purposes) and processing them at the same time instead of separately. I’ve done some echo tests and that is what is happening, but why?

$blogID will have array values 56,57 so because the loop is processing both values at the same time, then both options in the if statement become true because 56 equals 56, but then 56 doesn’t equal 57 on its 2nd pass so it will process the 2nd half of the if statement as true. This is weird and I’ve never had this happen before.

Here is the code:

$getblog = mysql_query("SELECT * FROM content WHERE blogID = '{$_REQUEST['id']}' AND type = '5' ORDER BY `order` ASC");
while ($row = mysql_fetch_assoc($getblog)){
$blogID = $row['id'];    
$tempData[$blogID][] = $row;

$data = $_REQUEST['blogIDS'];
$ids = explode(",", $data);

foreach($ids as $blogIDS) {
    $getblogids = mysql_query("SELECT * FROM content WHERE id = '$blogIDS' AND type = '5' ORDER BY `order` ASC");
    while ($row2 = mysql_fetch_assoc($getblogids)){
        $blogIDS = $row2['id'];    
        $tempData2[$blogIDS][] = $row2;
    }
}
    if ($row['id'] == $blogIDS) {
            echo "<input type='checkbox' name='ids[]' value='{$row['id']}' checked='yes'/>\n";
    } else {
            echo "<input type='checkbox' name='ids[]' value='{$row['id']}'/>\n";
    }

    echo "<a class='heriyah_text1' href='manage_blogposts_add.php?resize=1&edit=1&id={$row['id']}&blogID={$_REQUEST['id']}&pageID={$_REQUEST['pageID']}&div={$_REQUEST['div']}'>{$row['title']}</a><p></p>\n";
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:33:00+00:00Added an answer on May 31, 2026 at 1:33 am

    edited. try this and let me know:

    $getblog = mysql_query("SELECT * FROM content WHERE blogID = '{$_REQUEST['id']}' AND 
                             type = '5' ORDER BY `order` ASC");
    while ($row = mysql_fetch_assoc($getblog)){
        $blogID = $row['blogID'];    
        $tempData[$blogID][] = $row;
    }
    
    $data = $_REQUEST['blogIDS'];
    $ids = explode(",", $data);
    
    foreach($ids as $blogID) {
        if (array_key_exists($blogID, $tempData)) {
            foreach($tempData[$blogID] as $key => $value) {
                if ($value['blogID'] == $blogID) {
                    echo "<input type='checkbox' name='ids[]' value='{$value['id']}' checked='yes'/>\n";
                } else {
                    echo "<input type='checkbox' name='ids[]' value='{$value['id']}'/>\n";
                }
    
                echo "<a class='heriyah_text1' href='manage_blogposts_add.php?resize=1&edit=1&id={$value['id']}&blogID={$_REQUEST['id']}&pageID={$_REQUEST['pageID']}&div={$_REQUEST['div']}'>{$value['title']}</a><p></p>\n";
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that looks something like this: //iteration over scales foreach ($surveyScales
I have this code here, {foreach from=$cart.cartItems item=item name=cart} <div id=cart2Produkt> <p>{if $item.Product.ID} <a
I have code that I want to look like this: List<Type> Os; ... foreach
I have this code that I need to run an if statement to set
I have this function that needs to be converted to a lambda statement: public
I have this loop // go through each alumni foreach (esDL.Alumni currAlumni in allAlumnis)
I basically have a PHP function that is in a giant foreach statement and
I have a search engine that is supposed to search through descriptions of products
I have this little foreach statement in an ASPX page: <% foreach(string path in
I have this code while($row = mysql_fetch_row($result)) { echo '<tr>'; $pk = $row[0]['ARTICLE_NO']; foreach($row

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.