0

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

4
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by diafol
1

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

Votes + Comments
Time for you to be green again. :)
0

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.

Edited by diafol: n/a

0

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

0

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

Edited by diafol: n/a

0
$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>";
}
0

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?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.