473,657 Members | 2,496 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 1229
= 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
2021
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
3940
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
3035
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
2613
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
1742
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
8425
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
8845
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...
1
8522
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
7355
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
6177
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
5647
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2745
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.