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

  • SEARCH
  • Home
  • 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 7649687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:02:02+00:00 2026-05-31T11:02:02+00:00

I have two tables in my database: 1) blog_table 2) content In blog_table I

  • 0

I have two tables in my database:

1) blog_table
2) content

In blog_table I have values called postID that may or may not match up to values called id in the table content. I am wanting to know how I can write a while loop or foreach loop that will cycle through content table and perform one action if the id equals the value of postID in the blog_table and perform a different action if it doesn’t.

Right now I can only get id = postID

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

while ($row = mysql_fetch_assoc($getblogtable)) 
{
$getblogposts1 = mysql_query("SELECT postID FROM `$blog_table`");
while ($row1 = mysql_fetch_assoc($getblogposts1)) 
{
 if( $row1['postID'] == $row['id']) {
      echo "do something<br>";
 }else{
     echo "do something else<br>";
 }
} echo "<p></p>";
}
  • 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-31T11:02:03+00:00Added an answer on May 31, 2026 at 11:02 am

    [Edit based on OP’s comments and revised question]

    $getblogposts = mysql_query("SELECT * FROM content WHERE type = '5' AND blogID = '{$_REQUEST['id']}' ORDER BY `order` ASC");
    while ($row = mysql_fetch_assoc($getblogposts))
    {
        $matches = mysql_query("SELECT * FROM $blog_table WHERE postID = $row['id']");
        if (mysql_num_rows($matches) > 0)
        {
            // do something
        }
        else
        {
            // do something else
        }
    }
    

    Regarding a different design, I can’t say for sure that it’s necessary, but I don’t like running a loop of queries like this. I think one query should be enough to get everything you need in this case. Maybe if you describe your application, we could find a better query or more appropriate design.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two database tables. One table stores data for a commitment that a
I have two tables in my database, called ratings and movies . Ratings: |
I have two tables in my database: NEWS table with columns: id - the
I have two tables in my database schema that represent an entity having a
I have two tables in my database: user and media_contact . The media_contact table
I have two tables in my database that look like that: Customer: C_ID city
I have two database tables that have a many to many relationship: People and
I have two tables in my database users table : +-----------+---------------------+---------+---------+ | id |
I have two tables in my database: Company table (ID, CompanyName, CompanyUsername, CompanyPassword) Employee
Let's say I have two tables in my database. TABLE:Categories ID|CategoryName 01|CategoryA 02|CategoryB 03|CategoryC

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.