I just started using both PHP and MYSQL and i have this SQL statement that get record from three tables ie

Select name,age, datejoind, active, avrage_time_in,avreagework_duration from Personalrecord Union Activestaff Union Timetable

but i need to be able to get a the list of Returnd field name into a PHP array so that i can daynamically load into a CSV file. I know i would have used show columns but that works only with a single table so i hope any of you web Geeks could help me as i am helpless and i am to present a term paper and this is the only thing delaying me

You can use mysql_fetch_array() or mysqli_fetch_array() to return the result as an array.

commented: Time for you to be green again. :) +9
Member Avatar for diafol

UNION means that all the returned fields in the tables must be the same, e.g.
TABLE 1
id name description
TABLE 2
id name description
TABLE 3
id name description

If they are called something different, you'll have to give them aliases with the 'AS' keyword.

UNION means that all the returned fields in the tables must be the same, e.g.
TABLE 1
id name description
TABLE 2
id name description
TABLE 3
id name description

If they are called something different, you'll have to give them aliases with the 'AS' keyword.

sorry about that i mean join

Member Avatar for diafol

I thought perhaps you did. So what is the query you want to check? I can't build one for you.

$connection=mysql_connect("localhost","username","password") or die(mysql_error());

mysql_select_db("databasename") or die( mysql_error());

$result = mysql_query("Select field1,field2,... from Table") or die(mysql_error());

if( !mysql_num_rows($result) )
{
 echo "No records  found";
}
else
{
  $row=mysql_fetch_assoc($result);

  /* here $fieldNames is an array that contains the field names of the records returned by your query */
  $fieldNames = array_keys($row);
echo "<table border='1'> ";
echo "<tr><th>" . implode( "</th><th>", $fieldNames) . "</th></tr>";
do{
  echo "<tr><td>" . implode("</td><td>", array_values($row) ) . "</td></tr>";
 }
 while( $row=mysql_fetch_assoc($result) );
echo "</table>";
}
Member Avatar for diafol

Sorry, I'm still none the wiser.

Returnd field name into a PHP array so that i can daynamically load into a CSV file

Which fields from which tables? Have you checked out the MySQL manual w.r.t CSV files?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.