TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Programing Languages > PHP

Notices

resultset and two tables in sql query

PHP


Reply
 
Thread Tools Display Modes
Old 04-12-2007, 10:14 AM   #1
bender
Guest
 
Posts: n/a
resultset and two tables in sql query

Is possible to read variable using table.fieldName like in example?

example query: SELECT table1.*, table2.* FROM teble1, table2 WHERE
table1.id = table2.id;

$rs = $this->dbc->query($sql->createSelect());
while($row=$rs->fetch_array()){
$retVal[]=$row[table.fieldName] // doesnt work, $row[fieldName] //does
work
}
  Reply With Quote
Old 07-12-2007, 04:57 PM   #2
michael@greenquery.com
Guest
 
Posts: n/a
Re: resultset and two tables in sql query

Hi,

Yes you can get the tablename from any table even without writing the
SQL.

$sql = "select * from tablea a1,tableb b1 where b1.id = a1.id";
$result = mysql_query($sql);

//read meta data
for ($i=0;$i<mysql_num_fields($result);$i++){
$field = mysql_fetch_field($result,$i);
$meta[$field->name] = $field->table;
}

// now loop throw the resultset like you normally do.
now you can check the column name in your meta data to get the table
name.

var_dump($meta);

I hope this helps you
//Michael

On 3 Dec., 21:23, bender <> wrote:
> Is possible to read variable using table.fieldName like in example?
>
> example query: SELECT table1.*, table2.* FROM teble1, table2 WHERE
> table1.id = table2.id;
>
> $rs = $this->dbc->query($sql->createSelect());
> while($row=$rs->fetch_array()){
> $retVal[]=$row[table.fieldName] // doesnt work, $row[fieldName] //does
> work
>
> }


  Reply With Quote
Old 07-12-2007, 04:57 PM   #3
michael@greenquery.com
Guest
 
Posts: n/a
Re: resultset and two tables in sql query

Hi,

Yes you can get the tablename from any table even without writing the
SQL.

$sql = "select * from tablea a1,tableb b1 where b1.id = a1.id";
$result = mysql_query($sql);

//read meta data
for ($i=0;$i<mysql_num_fields($result);$i++){
$field = mysql_fetch_field($result,$i);
$meta[$field->name] = $field->table;
}

// now loop throw the resultset like you normally do.
now you can check the column name in your meta data to get the table
name.

var_dump($meta);

I hope this helps you
//Michael

On 3 Dec., 21:23, bender <> wrote:
> Is possible to read variable using table.fieldName like in example?
>
> example query: SELECT table1.*, table2.* FROM teble1, table2 WHERE
> table1.id = table2.id;
>
> $rs = $this->dbc->query($sql->createSelect());
> while($row=$rs->fetch_array()){
> $retVal[]=$row[table.fieldName] // doesnt work, $row[fieldName] //does
> work
>
> }


  Reply With Quote
Old 07-12-2007, 04:57 PM   #4
michael@greenquery.com
Guest
 
Posts: n/a
Re: resultset and two tables in sql query

Hi,

Yes you can get the tablename from any table even without writing the
SQL.

$sql = "select * from tablea a1,tableb b1 where b1.id = a1.id";
$result = mysql_query($sql);

//read meta data
for ($i=0;$i<mysql_num_fields($result);$i++){
$field = mysql_fetch_field($result,$i);
$meta[$field->name] = $field->table;
}

// now loop throw the resultset like you normally do.
now you can check the column name in your meta data to get the table
name.

var_dump($meta);

I hope this helps you
//Michael

On 3 Dec., 21:23, bender <> wrote:
> Is possible to read variable using table.fieldName like in example?
>
> example query: SELECT table1.*, table2.* FROM teble1, table2 WHERE
> table1.id = table2.id;
>
> $rs = $this->dbc->query($sql->createSelect());
> while($row=$rs->fetch_array()){
> $retVal[]=$row[table.fieldName] // doesnt work, $row[fieldName] //does
> work
>
> }


  Reply With Quote
Old 07-12-2007, 05:03 PM   #5
michael@greenquery.com
Guest
 
Posts: n/a
Re: resultset and two tables in sql query

Hi,

Yes you can get the tablename from any table even without writing the
SQL.

$sql = "select * from tablea a1,tableb b1 where b1.id = a1.id";
$result = mysql_query($sql);

//read meta data
for ($i=0;$i<mysql_num_fields($result);$i++){
$field = mysql_fetch_field($result,$i);
$meta[$field->name] = $field->table;
}

// now loop throw the resultset like you normally do.
now you can check the column name in your meta data to get the table
name.

var_dump($meta);

I hope this helps you
//Michael

On 3 Dec., 21:23, bender <> wrote:
> Is possible to read variable using table.fieldName like in example?
>
> example query: SELECT table1.*, table2.* FROM teble1, table2 WHERE
> table1.id = table2.id;
>
> $rs = $this->dbc->query($sql->createSelect());
> while($row=$rs->fetch_array()){
> $retVal[]=$row[table.fieldName] // doesnt work, $row[fieldName] //does
> work
>
> }


  Reply With Quote
Old 07-12-2007, 05:10 PM   #6
michael@greenquery.com
Guest
 
Posts: n/a
Re: resultset and two tables in sql query

Hi,

Yes you can get the tablename from any table even without writing the
SQL.

$sql = "select * from tablea a1,tableb b1 where b1.id = a1.id";
$result = mysql_query($sql);

//read meta data
for ($i=0;$i<mysql_num_fields($result);$i++){
$field = mysql_fetch_field($result,$i);
$meta[$field->name] = $field->table;
}

// now loop throw the resultset like you normally do.
now you can check the column name in your meta data to get the table
name.

var_dump($meta);

I hope this helps you
//Michael

On 3 Dec., 21:23, bender <> wrote:
> Is possible to read variable using table.fieldName like in example?
>
> example query: SELECT table1.*, table2.* FROM teble1, table2 WHERE
> table1.id = table2.id;
>
> $rs = $this->dbc->query($sql->createSelect());
> while($row=$rs->fetch_array()){
> $retVal[]=$row[table.fieldName] // doesnt work, $row[fieldName] //does
> work
>
> }


  Reply With Quote
Reply

Thread Tools
Display Modes



< Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT +5.5. The time now is 03:55 AM.


vBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2009, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional