php - Codeigniter join 2 tables data with new column for id value -
I'm new to I want to join two tables which I will get the result How much time was it so far? {$ This-> Db- & gt; Choose ('*'); Order - ('id', 'character') from $ '-' ('post') -> - & gt; Range ($ numberOfRows, $ start); $ This- & gt; Db- & gt; Where ('category_id', $ categoryID); $ This- & gt; Db- & gt; Join ('Categories', 'posts.category_id == categories.id'); $ Query = $ this- & gt; Db- & gt; get receive (); Return $ query- & gt; Result_are (); } Thanks in advance. =========================================== ============================= EDIT: Adrian Farsius of the North After trying: I am getting this error: ==== Edit 2: So I found some mistakes in the code and decided them, tried again, but then Also made me an error: (using the What it wants to do: Codeigniter and
PHP , just learn I Searched for it but did not find the correct answer. I have a table in which there is some data, call it
post and in this table, I have
category_id in each post. I have
categories There is one more table and I have 2 columns in this table:
id and
name .
post as well as another column called
category_name
categories. Name . .
function getPostsWithByCategoryID ($ numberOfRows, $ start, $ categoryId)
function getPostsWithByCategoryID ($ numberOfRows, $ start, $ categoryId) {$ this- & gt; Db- & gt; ('*, Category; name AS category_name'); Order - ('id', 'character') from $ '-' ('post') -> - & gt; Range ($ numberOfRows, $ start); $ This- & gt; Db- & gt; Where ('category_id', $ categoryID); $ This- & gt; Db- & gt; Join ('Categories', 'posts.category_id = categories.id'); $ Query = $ this- & gt; Db- & gt; get receive (); Return $ query- & gt; Result_are (); }
Error number: 1054: Unknown column in 'field list' category.name 'SELECT *, ` Category 'name' from AS Category_name (`post ') Include` categories' on' post '.' Category_id` = `Categories````````` where` NO 'on the basis of category_ID`` ID Code>
$ categoryId instead of the
$ categoryID and select
category.name instead of the correct name of the table
categories which
categories.name
error number: 1052: column 'ID' is indistinguishable in the order segment SELECT *, `categories`. `` `` `` `` `` `` `` `` `` `` `` `` `` ` Include 'category' id```` categories```````` where`category_id` = '3' / pre>
function getPostsWithByCategoryID ($ numberOfRows, $ start, $ categoryId) Select {$ this-> db-> ('*, $ '-' ('posts') -> gt; by order - ('posts.id', 'desc') - & gt; range from $ ($ numberOfRows, $ start) $ $ - & gt; db- & gt; $ This- & gt; Db- & gt; Where ('category_id', $ categoryId); $ This- & gt; Db- & gt; Join ('Categories', 'posts.category_id = categories.id'); $ Query = $ this- & gt; Db- & gt; get receive (); Return $ query- & gt; Result_are (); }
Comments
Post a Comment