Jump to content


Photo

Column Alias


  • Please log in to reply
4 replies to this topic

#1 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 03 June 2006 - 08:15 PM

Trying to do a join on a query via odbc with PHP...

Problem: Both tables have a column name of the same name.
The Database is FoxPro

It would seem that ODBC for foxpro doesn't allow the column_name as alias_name
SO...

And to boot, PHP has a bug? that makes the array not associative, so I can't just use $row[0]...
it comes up as Undefined Index: 0...

If I echo it out as $row['column name'], it works like normal, but each time I get to the second tables
identical name, it echo the value from the first table's column...

Any suggestion for a work around????????????????????????????????????

Is there a way to dump the array en mass into another array then pull it out from there???

HelP!

#2 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 03 June 2006 - 08:30 PM

// Edit

This doesn't fix it only partly - see last post for solution...

// End Edit

Well, it's ugly, but I found a way around it...

Someone might want to make a note of it (Barand?)
Please let me know if there is a prettier solution...
I know I'll use this again...

WHILE($row=ODBC_fetch_array($result)){

    foreach ($row as $temp[]);
    echo $temp[0]."   ".$temp[1]."   ".$temp[3]."   ".$temp[4]."   ".$temp[5]."   ".$temp[6]."   ".$temp[7]."   ".$temp[8]."   ".$temp[9]."   ".$temp[10]."   ".$temp[11]."   ".$temp[12]."\n";



-Ciao



[!--quoteo(post=379723:date=Jun 3 2006, 04:15 PM:name=AV1611)--][div class=\'quotetop\']QUOTE(AV1611 @ Jun 3 2006, 04:15 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Trying to do a join on a query via odbc with PHP...

Problem: Both tables have a column name of the same name.
The Database is FoxPro

It would seem that ODBC for foxpro doesn't allow the column_name as alias_name
SO...

And to boot, PHP has a bug? that makes the array not associative, so I can't just use $row[0]...
it comes up as Undefined Index: 0...

If I echo it out as $row['column name'], it works like normal, but each time I get to the second tables
identical name, it echo the value from the first table's column...

Any suggestion for a work around????????????????????????????????????

Is there a way to dump the array en mass into another array then pull it out from there???

HelP!
[/quote]

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 03 June 2006 - 08:40 PM

I'd do a print_r($row) just see what data and keys are there, just in case it is in the array but with another key name.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#4 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 05 June 2006 - 02:12 PM

//edit

see next post



#5 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 05 June 2006 - 02:34 PM

FORGET IT!

JUST FORGET IT ALL!!!

I feel like an idiot...

Here is the problem... When I aliased, I did it like this:

serialnum as SN

but in the array the key was sn

SO...

when I went

echo $row['SN']

it didn't find it, because is should have been

$row['sn']

I don't think MySQL does it, just happens to do it in Foxpro via ODBC...

OUCH!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


Thanks, Barand, for leading me to the answer...





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users