It is possible to get the tablenames of all tabels within a database, by using the mysql_list_tables function.... but how do you identify it from within a query....
For Example
$query=do_query("SELECT company FROM suppliers");
$i=1;
$count=mysql_num_rows($query);
while($company=mysql_fetch_assoc($query))
{
foreach($company as $table)
{
$qu .= "(SELECT * FROM ".$table;
if ($category!="")
{
$qu .=" WHERE category='".$category."')";
}
elseif ($model!="")
{
$qu .=" WHERE modelnumber LIKE '%".$model."%')";
}
elseif ($name!="")
{
$qu .=" WHERE productname LIKE '%".$name."%')";
}
else
{
$qu .=")";
}
if ($i!=$count) {
$qu .= " UNION ";
}
$i++;
}
}
$qu .= " LIMIT ".$offset.",".$limit;
$query=do_query($qu);
//gives you (SELECT * FROM company1) UNION (SELECT * FROM company2) LIMIT $offset,$limit
OK - so we have the query, which is a combination of multiple tables... so how can you identify which row comes from which table, and output the table name from this ?
Using mysql_tablename($query, $x) doesn't work as all I get is the ID number of that particular table, not the table name.
Any clues / ideas ?