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 8198363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:56:08+00:00 2026-06-07T05:56:08+00:00

I have a query of a mysql database that joins two tables. In the

  • 0

I have a query of a mysql database that joins two tables. In the first table it just pulls records based on an id. For the second table, there may or may not be matches based on a value in the first table. I want to get matches if there are any, otherwise, presumably those values of the resulting record set are empty.

The query seems to produce the right number of records. However, when I try to access values of some variables that should be present, I am not getting anything, either because I may be calling them the wrong name or they are not in recordset somehow. I am a bit fuzzy on mysql queries so would greatly appreciate any advice..

Table 1 parks

id | name | stateid 

Table 2 parksvisited

id | visited | parkid | userid

PHP script

$sql = "SELECT * 
FROM `parks` p
LEFT JOIN `parksvisited` pv
ON p.id = pv.parkid
WHERE p.stateid = '44'"

run query…

while($row = mysql_fetch_array($res))
{
if ($row['visited'] == 1) {
$visited = 1; }  
else {
$visited = 0; }
<a href="javascript:void(0);" onclick="loadParks(\''.$row['stateid'].'\',\''.$row['p.id'].'\',\''.$visited.'\');">Visited</a>

}

Basically, I get stateid but I am not getting p.id or visited. It could be I am naming them wrong or possibly they are getting left out of results somehow… Thanks for any suggestions.

  • 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-06-07T05:56:09+00:00Added an answer on June 7, 2026 at 5:56 am

    p.id is probably missing because each of p.id and pv.id are going to get returned as id, not as p.id or pv.id. Try this instead:

    SELECT p.id pid,
           p.*,
           pv.id pvid,
           pv.*
    FROM `parks` p
    LEFT JOIN `parksvisited` pv
    ON p.id = pv.parkid
    WHERE p.stateid = '44'
    

    It also doesn’t look like you’re selecting anything from pv in your original query, just p. See if this new query takes care of visited as well. And make sure to refer to pid as $row['pid'], not $row['p.id'].

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

Sidebar

Related Questions

We have a MySQL database that has two tables, Warehouse and Crate Warehouse: WarehouseID
I have a MySQL database with two tables (simplified for this question): movies table
Suppose I have the following two tables in my MySQL database: Table 1:: EMP:
I am using MYSQL. I have two tables in my database. Table 1: ‘courseTable’
I have in my MySQL database these two tables: CREATE TABLE IF NOT EXISTS
I'm working on a mysql query in a Drupal database that pulls together users
I have a MySQL database with a lot of tables, and I have two
I have two tables in my database table: products table: companies +-----------+------------+ +------+------------+ |
I have two tables in a MySQL database, courses and sessions. I'm trying to
Consider these two tables stored in a MySQL database. The first stores a list

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.