Hi, getting a little stuck, been doing quite well with the old mysql php thingy. But i need a little help exporting data. The following code shows the results of a search rather nicely however i would also like to export the contents (+ address fields stored in the database) to a csv file created by a browse button next to the 'New search' button, searched high and low and not had much joy, here's the code, any help would really be appreciated,
<?
// mysql connection
$connection = mysql_connect("localhost", "admin", "password");
$db_name = "slipsey";
$table_name = "contact";
$db = mysql_select_db($db_name, $connection);
// check for required fields
$sql = "SELECT `contactid` , `firstname` , `surname` , `shareholder` , `country` FROM $table_name WHERE `firstname` LIKE '$_POST[firstname]%' OR `surname` LIKE '$_POST[surname]%' OR `shareholder` LIKE '$_POST[shareholder]' ORDER BY `shareholder`";
$result = mysql_query($sql, $connection);
?>
<SCRIPT LANGUAGE="Javascript">
function gotourl() {window.location = "http://ukintranet/slipsey/main/contact/searchcontact.php";}
</script>
<html>
<head>
<!-- #BeginEditable "Add shareholder contact" -->
<title>Display Search Results</title>
<!-- #EndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body link="#000000" vlink="#000000" alink="#000000">
<table width="600" border="0" cellspacing="2">
<tr bgcolor="#000099">
<td colspan="7">
<div align="center"><font face="sans-serif" size="4" color="#FFFFFF">Contact
Search Results</font></div>
</td>
</tr>
<tr bgcolor="#CCCCCC">
<td colspan="7">
<div align="right"><strong><font face="sans-serif" size="2" color="#FFFFFF"> Returned <? echo mysql_num_rows($result) ?> results</td></strong></font>
</div>
</td>
</tr>
<tr bgcolor="#CCCCCC" align="center" valign="middle">
<td bgcolor="#9999FF"><font size="2" face="sans-serif"><b>Firstname</b></font></td>
<td bgcolor="#9999FF"><font size="2" face="sans-serif"><b>Surname</b></font></td>
<td bgcolor="#9999FF"><font size="2" face="sans-serif"><b>Shareholder</b></font></td>
<td bgcolor="#9999FF"><font size="2" face="sans-serif"><b>Country</b></font></td>
<td bgcolor="#FFFF00"><font size="2" face="sans-serif"><b>View</b></font></td>
<td bgcolor="#FFFF00"><font size="2" face="sans-serif"><b>Modify</b></font></td>
<td bgcolor="#FFFF00"><font size="2" face="sans-serif"><b>Delete</b></font></td>
</tr>
<?
// PHP generated options from shareholder table
for($i= 0; $i<mysql_num_rows($result); $i++) {
$var1[$i] = mysql_result($result,$i,"contactid");
$var2[$i] = mysql_result($result,$i,"firstname");
$var3[$i] = mysql_result($result,$i,"surname");
$var4[$i] = mysql_result($result,$i,"shareholder");
$var5[$i] = mysql_result($result,$i,"country");
echo "<tr><td bgcolor=\"#CCCCFF\"><font size=\"2\" face=\"sans-serif\">".$var2[$i]."</font></td>";
echo "<td bgcolor=\"#CCCCFF\"><font size=\"2\" face=\"sans-serif\">".$var3[$i]."</font></td>";
echo "<td bgcolor=\"#CCCCFF\"><font size=\"2\" face=\"sans-serif\">".$var4[$i]."</font></td>";
echo "<td bgcolor=\"#CCCCFF\"><font size=\"2\" face=\"sans-serif\">".$var5[$i]."</font></td>";
echo "<td bgcolor=\"#FFFF99\"><font link=\"#000000\" vlink=\"#000000\" alink=\"#000000\" size=\"2\" face=\"sans-serif\"><a href=\"/Slipsey/Main/contact/do_displaycontact.php? id=$var1[$i]\">View</a></font></td>";
echo "<td bgcolor=\"#FFFF99\"><font link=\"#000000\" vlink=\"#000000\" alink=\"#000000\" size=\"2\" face=\"sans-serif\"><a href=\"/Slipsey/Main/contact/modifycontact.php? id=$var1[$i]\">Modify</a></font></td>";
echo "<td bgcolor=\"#FFFF99\"><font link=\"#000000\" vlink=\"#000000\" alink=\"#000000\" size=\"2\" face=\"sans-serif\"><a href=\"/Slipsey/Main/contact/deletecontact.php? id=$var1[$i]\">Delete</a></font></td></tr>";
}
?>
<tr bgcolor="#CCCCCC" align="right" valign="middle">
<td colspan="7"><strong>
</tr>
<tr bgcolor="#000099" align="center" valign="middle">
<td colspan="7">
<input type="button" value="New Search" onClick="gotourl()" name="button">
</td>
</tr>
</table>
</body>
</html>
Thanks again for any help you can give