Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

php sql server, left join, join query retrieving variables

Posted on 2014-12-06
7
Medium Priority
?
141 Views
Last Modified: 2014-12-12
A query with a join as such


$sql = "SELECT * FROM tableA
		LEFT JOIN tableB ON (tableA.customerid=tableB .Id)";
 
//---prepare query above
$stmt=sqlsrv_query( $conn, $sql, $params, array( "Scrollable" => 'keyset' ));

Open in new window


in a loop where this drives it

while ($row = sqlsrv_fetch_array($stmt)){ 

 

Open in new window


trying to pull the Id which both tableA and tableB have

  
$Id=$row[Id];

Open in new window

Gets only tableA's Id of course, I need both Ids

I am used to MySQL/PHP where I can specify as

$IdA=$row[tableA.Id];
$IdB=$row[tableB.Id];

Open in new window


but I am having now luck
0
Comment
Question by:Zipbang
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 4

Accepted Solution

by:
Zsolt Pribusz earned 2000 total points
ID: 40484946
Try to use alias for ID's.

For example:

$sql = "SELECT tableA.id as IdA, tableB.id as IdB, * FROM tableA
            LEFT JOIN tableB ON (tableA.customerid=tableB.Id)";

Then you can get IDs

$IdA=$row[IdA];
$IdB=$row[IdB];
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40484976
To understand why this is an antipractice, please read about the use of quotes in PHP.

$IdA=$row[IdA]; // What is the defined constant named IdA?

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12241-Quotation-Marks-in-PHP.html
0
 

Author Comment

by:Zipbang
ID: 40492880
Ok, I have one suggestion and one comment that the suggestion is the antipractice.  

Zsolt's comment will solve the problem, but if it is the wrong way, please tell me the correct method to solve my problem.

thank you.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40495423
The correct way is written in the article.  If you still have questions after reading the article, please post back and make reference to the part of the article that is unclear to you.  I will answer your questions and update the article to clarify it.

If you're new to PHP and want to get a good foundation for learning, this might help:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html

Best of luck with your project, ~Ray
0
 

Author Comment

by:Zipbang
ID: 40496131
Ray,

I pay for this service for quick solutions.  While an article on the foundations of PHP is a good resource, it is not a solution.  In this context, it is simply link bait to get me to read your article.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40497437
link bait
Ha!  That might make sense if I get paid when you read my articles.  Like I said, "Best of luck..."
0
 

Author Comment

by:Zipbang
ID: 40497540
It's not about luck, but thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question