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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:07:01+00:00 2026-06-13T06:07:01+00:00

I am baffled as to what I am doing wrong. I’ve looked this up

  • 0

I am baffled as to what I am doing wrong. I’ve looked this up in many resources, including the book that I am learning PHP out of, and it seems like it should be right…but it is just not working.

<?php

try
{
    $sql = 'SELECT parks.id, parks.state, parks.name, parks.description, parks.site, parks.sname, parks.street, parks.city, parks.zip, parks.phone FROM parks
INNER JOIN comments ON parks.parkid = comments.parkid
INNER JOIN photos ON parks.parkid = photos.parkid 
INNER JOIN events ON parks.parkid = events.parkid';
$result = $pdo->query($sql);
}
catch (PDOException $e)
{
    $error = 'Error fetching data: ' . $e->getMessage();
    include 'output.html.php';
    exit();
}

foreach ($result as $row)
{
    $datas[] = array ('id' =>$row['id'],
    'parkid' =>$row['parkid'],
    'state' =>$row['state'], 
    'name' =>$row['name'], 
    'description' =>$row['description'], 
    'site' =>$row['site'], 
    'sname' =>$row['sname'],
    'street' =>$row['street'], 
    'city' =>$row['city'], 
    'phone' =>$row['phone'],
    'zip' =>$row['zip'],
    'commentname' =>$row['commentname'],
    'comment' =>$row['comment'],
    'event' =>$row['event'],
    'date' =>$row['date'],
    'description2' =>$row['description2']);
}

include 'writing.html.php';

This returns all of the data that is in the first table (parks) just fine. The items commentname, comment, event, date, and description2 are from the joined tables (events and comments)

If I echo ‘$row[‘state’]’ I get a correct answer. But if I echo any of the items from the other tables (for instance $row[‘comment’]) I get no result.

What am I missing?

  • 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-13T06:07:02+00:00Added an answer on June 13, 2026 at 6:07 am

    SQL showing how to return columns from the joined tables

    SELECT parks.id, 
           parks.state, 
           parks.name AS park_name, -- use an alias when column names exist in more than one table
           parks.description, 
           parks.site, 
           parks.sname, 
           parks.street, 
           parks.city, 
           parks.zip, 
           parks.phone,
           comments.comment, -- to return the comment from the comments table
           events.name AS event_name, -- return name from the event table
           event_date  -- return date from the event table
      FROM parks 
      INNER JOIN comments 
              ON parks.parkid = comments.parkid 
      INNER JOIN photos 
              ON parks.parkid = photos.parkid  
      INNER JOIN events 
              ON parks.parkid = events.parkid'
    ;
    

    This is not a complete solution, but a demonstration of ho to return data from the joined tables rather than purely from the main table

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

Sidebar

Related Questions

I am baffled with this questions. I want to believe that through some Javascript
So I am baffled by this one. I have a function that is responsible
I am absolutely baffled by this. I have a script that spell checks stuff
I'm just doing some recursion exercises in PHP and I'm a bit baffled by
So I'm a bit baffled with the SVG coordinate system. I'm doing a project
this has baffled me for a couple of hours now. Why do i get
This question has baffled myself and my cohorts. In the program I had written
It has always baffled me that if a folder has read and write permissions,
This issue has me baffled, it's affecting a single user (to my knowledge) and
I'm baffled as to what this SQL statement means: SELECT exhibitor_categories+0 from exhibitor_registry What

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.