![]() |
|
|||||||
| Notices |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
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 } |
|
|
|
#2 |
|
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 > > } |
|
|
|
#3 |
|
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 > > } |
|
|
|
#4 |
|
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 > > } |
|
|
|
#5 |
|
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 > > } |
|
|
|
#6 |
|
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 > > } |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
< Windows Help - MS Office Help - Hardware Support >
| New To Site? | Need Help? |