Hi,
I would like to know how to export the results from the following page into a csv file please.
Thank you in advance.
<?php
include("Connections/conn.php");
include ("Connections/functions.php");
// Inside this if statement the results of the search are displayed
// The else if below has the checkboxes for the search.
if ($display)
{
$totalFound = 0;
echo "<tr><td><p class='bodytext'>";
$result = mysql_query("SELECT skills.skills_id,skills.skills_title FROM skills LEFT JOIN skills_hierarchy ON skills_hierarchy.child = skills.skills_id WHERE skills_hierarchy.parent IS NULL") or die(mysql_error());
//GET THE NAMES OF THE SKILL AREAS
$skills = array();
if (mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_assoc($result))
{
$stitle = $row['skills_title'];
$skills[$stitle] = array();
//CREATE AN ARRAY FILLED WITH SKILL AREAS AS KEYS
$query2 = "SELECT skills.skills_id,skills.skills_title FROM skills LEFT JOIN skills_hierarchy ON skills_hierarchy.child = skills.skills_id WHERE skills_hierarchy.parent = ".$row['skills_id'];
$result2 = mysql_query($query2) or die (mysql_error()." Query: $query2");
if (mysql_num_rows($result2) > 0)
{
while ($row2 = mysql_fetch_assoc($result2))
{
$skills[$stitle][] = array("id" => $row2['skills_id'], "title" => $row2['skills_title']);
//ADD THE SKILLS TO THEIR RESPECTIVE SKILLS AREAS AS AN ARRAY CONTAINING ID AND NAME
}
echo "<p>";
}
}
//dump($skills);
foreach ($skills as $key => $value)
{
if (empty($value) || $key != $area)
continue; //IF NO SKILLS ARE AVAILABLE FOR A SKILL AREA SKIP THE SKILL AREA OUTPUT
else
{
foreach ($value as $value2)
{
$found = false;
$val = $value2['id'];
$title = $value2['title'];
for ($i=0; $i<count($_POST['skills']); $i++)
{
$skills_req = addslashes($_POST['skills'][$i]);
if($skills_req == $val)
{
$query1 = "SELECT DISTINCT member.lastName, member.firstName, member.loginName, member.city, member.orgName FROM member LEFT JOIN memberskills ON memberskills.memberloginName = member.loginName LEFT JOIN login ON login.loginName = member.loginName WHERE skills_id = ".$value2['id']." ORDER BY login.loginTime DESC, member.lastName ASC";
$result1 = mysql_query($query1) or die(mysql_error(). "Query: $query1");
if(mysql_num_rows($result1) > 0)
{
echo "<h4>$title</h4><br>";
echo '<table width="90%">';
echo '<tr>';
echo '<th width="30%">Name</th>';
echo '<th width="30%">Region</th>';
echo '<th width="30%">Type </th>';
echo '</tr>';
while ($row3 = mysql_fetch_array($result1))
{
$totalFound++;
$memberid = $row3[2];
$regionQuery = "SELECT name FROM region LEFT JOIN memberregion ON memberregion.regionid = region.id WHERE memberregion.memberloginName='$memberid'";
$regionResult = mysql_query($regionQuery);
$regionRow = mysql_fetch_row($regionResult);
$regionid = $regionRow[0];
echo "<td>";
echo "<a href='resume_search.php?id=".$row3[2]."'>";
echo "$row3[0] $row3[1] </a> </td>";
echo "</a>";
echo "<td>$regionid</td>";
if($row3[4])
{
echo "<td>Organisation</td>";
}
else
{
echo "<td>Individual</td>";
}
echo "</tr>";
}
echo "</table>";
echo "<br>";
}
}
}//end loop
}
}
}
}
if($totalFound == 0)
{
echo "Sorry your search returned no results.<br><br>";
}
$id = $_GET['id'];
echo "<a href='search2.php?id=$id'> Search again </a>";
}
else if ($area)
{
echo "<tr><td><p class='bodytext'><a href=\"search2.php?id=$logname\">Search again</a>";
echo "<form name=\"skill\" action=\"search_results_skills2.php?id=".$_GET['id']."\" method=\"POST\">\n";
$result = mysql_query("SELECT skills.skills_id,skills.skills_title FROM skills LEFT JOIN skills_hierarchy ON skills_hierarchy.child = skills.skills_id WHERE skills_hierarchy.parent IS NULL") or die(mysql_error());
//GET THE NAMES OF THE SKILL AREAS
$skills = array();
if (mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_assoc($result))
{
$stitle = $row['skills_title'];
$skills[$stitle] = array();
//CREATE AN ARRAY FILLED WITH SKILL AREAS AS KEYS
$query2 = "SELECT skills.skills_id,skills.skills_title FROM skills LEFT JOIN skills_hierarchy ON skills_hierarchy.child = skills.skills_id WHERE skills_hierarchy.parent = ".$row['skills_id'];
$result2 = mysql_query($query2) or die (mysql_error()." Query: $query2");
if (mysql_num_rows($result2) > 0)
{
while ($row2 = mysql_fetch_assoc($result2))
{
$skills[$stitle][] = array("id" => $row2['skills_id'], "title" => $row2['skills_title']);
//ADD THE SKILLS TO THEIR RESPECTIVE SKILLS AREAS AS AN ARRAY CONTAINING ID AND NAME
}
echo "<p>";
}
}
//dump($skills);
foreach ($skills as $key => $value)
{
if (empty($value) || $key != $area)
continue; //IF NO SKILLS ARE AVAILABLE FOR A SKILL AREA SKIP THE SKILL AREA OUTPUT
else
{
echo "<table>\n";
echo "<tr><th colspan=\"4\">{$key}:</th>\n"; //OUTPUT SKILL AREA TITLE
$counter = 0;
echo "<tr>\n";
foreach ($value as $value2)
{
echo "<td>".quote_smart($value2['title'])."</td><td><input type=\"checkbox\" value=\"{$value2['id']}\" name=\"skills[]\""; //LIST SKILL AND CHECKBOX
echo "></td>\n";
$counter++;
if ($counter % 2 == 0) //LIMIT OUTPUT TO TWO SKILLS PER LINE
echo "</tr><tr>\n";
}
echo "</tr>";
echo "</table>";
}
}
echo "<p><input type=\"submit\" value=\"Search Skill(s)\">";
echo "<input type=\"reset\" value=\"Reset Form\">";
}
echo "<input type=\"hidden\" name=\"display\" value=\"$area\">";
echo "<input type=\"hidden\" name=\"area\" value=\"$area\">";
echo "<input type=\"hidden\" name=\"title\" value=\"$area\">";
echo "<input type=\"hidden\" name=\"user\" value=\"$logname\">";
echo "</p>";
echo "</form>";
}
?>