473,837 Members | 1,518 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

retrieveing vars from mysql join ?

Hi all ,

I have the following problem :

$some_query = mysql_query(
"SELECT table1.id, table1.category , table1.author, table1.title,
table2.title, table2.category FROM table1, table2
WHERE table1.category = table2.category ORDER by table1.id DESC");

while($record = mysql_fetch_arr ay($some_query) )
{
$mycategory = ($record['table1.categor y']);
$mytitle = ($record['table2.title']);

echo"$mycategor y";
echo"$mytitle";
}

Does someone know what's wrong here ?
echo don't show the requested values ....
thanks !
Dec 1 '06 #1
5 1237
= poster = wrote:
Hi all ,

I have the following problem :

$some_query = mysql_query(
"SELECT table1.id, table1.category , table1.author, table1.title,
table2.title, table2.category FROM table1, table2
WHERE table1.category = table2.category ORDER by table1.id DESC");

while($record = mysql_fetch_arr ay($some_query) )
{
$mycategory = ($record['table1.categor y']);
$mytitle = ($record['table2.title']);

echo"$mycategor y";
echo"$mytitle";
}

Does someone know what's wrong here ?
echo don't show the requested values ....
thanks !
Hi,

Many databases return their results without table specification.
However, If you have 2 columns with the same name you MUST specify which one
you need in the query, or the database will start complaining about it.

The way around this problem is simple, use an alias in the query, and do not
give the tablenames in PHP.

In your case:
$some_query = mysql_query(
"SELECT table1.id,
table1.category AS cat1 ,
table1.author,
table1.title as title1,
table2.title as title2,
table2.category AS cat2
FROM table1, table2
WHERE table1.category = table2.category ORDER by table1.id DESC");

while($record = mysql_fetch_arr ay($some_query) )
{
$mycategory = ($record['cat2']);
$mytitle = ($record['title2']);

echo"$mycategor y";
echo"$mytitle";
}

(Not tested)

Good luck and regards,
Erwin Moller
Dec 1 '06 #2
= poster = wrote:
Hi all ,

I have the following problem :

$some_query = mysql_query(
"SELECT table1.id, table1.category , table1.author, table1.title,
table2.title, table2.category FROM table1, table2
WHERE table1.category = table2.category ORDER by table1.id DESC");

while($record = mysql_fetch_arr ay($some_query) )
{
$mycategory = ($record['table1.categor y']);
$mytitle = ($record['table2.title']);

echo"$mycategor y";
echo"$mytitle";
}

Does someone know what's wrong here ?
echo don't show the requested values ....
thanks !

A stupid question - but are you actually calling mysql_query() before
trying the fetch the results?

Then try the following - and look at your index values:

echo "<pre>\n";
print_r($record );
echo "</pre>\n";

And finally, you can make things easier on yourself with something like:

"SELECT ... table1.category AS tab1category,
... table2.category AS tab2category ...

Also, if a column has a unique name in the tables listed in your FROM
clause, just use the column name. You only need the table name when you
have duplicate column names, as in category.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Dec 1 '06 #3
Thanks a lot for your help !

The problem was that I dind't know the 'AS' alias function.

Does the aliasing have an impact on the speed of the query ?

thanks a lot !
Dec 1 '06 #4
= poster = wrote:
Thanks a lot for your help !

The problem was that I dind't know the 'AS' alias function.

Does the aliasing have an impact on the speed of the query ?
Probably a weee little, but I wouldn't care about that effect too much.

Regards,
Erwin
>
thanks a lot !
Dec 1 '06 #5
= poster = wrote:
Thanks a lot for your help !

The problem was that I dind't know the 'AS' alias function.

Does the aliasing have an impact on the speed of the query ?

thanks a lot !

Nothing measurable, at any rate. There might be if you had a few
hundred aliases, but for a few I've never been able to measure a
difference the margin of error in the system.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Dec 1 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2029
by: flamesrock | last post by:
ok, so to my knowledge, object oriented means splitting something into the simplest number of parts and going from there. But the question is- when is it enough? For example I have the following code: #def put_file(file_id, delete=False): # """ Function to put the file on the FTP Server # """ # print " FTP for this file started"
0
3955
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest version of this document can be found at: http://prdownloads.sourceforge.net/souptonuts/README_mysql.txt?download
33
3066
by: MLH | last post by:
I've read some posts indicating that having tons of GV's in an Access app is a bad idea. Personally, I love GVs and I use them (possibly abuse them) all the time for everything imaginable - have been for years. If the machine has memory to spare and windows can use it - I'm thinking "Why not?" I was wondering what some of you have to say about that, particularly any severe "gotchas" you've had the unfortunate experience to contend with.
6
2625
by: goodguyjam | last post by:
Hi all, I'm having trouble with mysql. I've just finished my php coding for HTTP authentication and with some help am now getting a login window pop up whenever I click on a link on my website that directs to Auth.php. The code for this is below: <?php /* Program: Auth.php * Desc: Program that prompts for a user name and * password from the user using HTTP authentication.
1
1751
by: svsenthilkumar | last post by:
how can i add 10 days with retrieveing date using php i retrieve a date from mysql table,and i add 10 days with that date and compare with today is or not.
0
9837
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9682
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10870
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10563
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10621
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9392
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7804
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5845
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3123
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.