/    Sign up×
Community /Pin to ProfileBookmark

sqlite column aliases

For some reason when I use a column alias, I cannot retrieve the value of a column’s field.

[code=php]
$cat=sqlite_query($handle,”select cd.categories_name from categories_description cd”);
while($cat_row=sqlite_fetch_array($cat)){
$cat_row[‘categories_name’].”<br>”;
$i++;
}
[/code]

but this works:

[code=php]
$cat=sqlite_query($handle,”select categories_name from categories_description”);
while($cat_row=sqlite_fetch_array($cat)){
$cat_row[‘categories_name’].”<br>”;
$i++;
}
[/code]

I need to use column aliases for joining tables.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@sitehatcheryauthorFeb 08.2007 — using categories_description.categories_name doesn't work either.
Copy linkTweet thisAlerts:
@sitehatcheryauthorFeb 09.2007 — Ok, I found the solution.

Joining 2 tables, you only should use a table alias for the ambiguous column name. Then, use a column alias as well for that column name.

For instance,
[code=php]
$query="select p.cat_id as cat_id from products p, categories c where p.product_id=c.product_id"
[/code]


if you don't put the "as cat_id" part, it won't work. This means I will have to alter quite a bit of code to make it compatible with sqlite. The good thing is, I won't have to alter it if I want to revert back to mysql.
×

Success!

Help @sitehatchery spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...