Support the ongoing development of Laravel.io →
Database Eloquent

Hi I'm trying to get the values of a table that references 2 tables. my tables looks like this

pages_content table

page_id   |  content_id
------------------------
    1     |       4
    6     |       10

pages table

id   |   title
-----------------
1    |   home
6	 |   contact


content table


id   |  content
-----------------
4 	 |  home page
10	 |  contact us    

I need to reference the pages_content table and get the values that are in the other tables.

I tried this

$content = DB::select('select * from pages_content pxc, content c where page_id = '.$page_id.' and content_id = c.id');

and I got a syntax error

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '<p>home page</p> and content_id = c.id' at line 1 (SQL: select * from pages_content pxc, content c where page_id = <p>home page</p> and content_id = c.id) (View: /Applications/MAMP/htdocs/test/app/views/public/content.blade.php)
Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

shiva shiva Joined 24 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.