Jump to content

I want to export mysql table based on the value selected in combobox/dropbox


roipatrick

Recommended Posts

I don't know if I'm posting in the right section since I'm so new here and in php as well. Please help me with my problem.

 

Ill paste my code.

 

<div>
<button style="height: 21px; width: 100px;margin-top: 4px;">
 
<?php
 
// Connect and query the database for the users
$conn = new PDO("mysql:host=localhost;dbname=mydatabase", 'myuser', 'mypassword');
$sql = "SELECT * FROM users ORDER BY username";
$results = $conn->query($sql);
 
// Pick a filename and destination directory for the file
// Remember that the folder where you want to write the file has to be writable
$filename = "/tmp/db_user_export_".time().".csv";
 
// Actually create the file
// The w+ parameter will wipe out and overwrite any existing file with the same name
$handle = fopen($filename, 'w+');
 
// Write the spreadsheet column titles / labels
fputcsv($handle, array('Username','Email'));
 
// Write all the user records to the spreadsheet
foreach($results as $row)
{
fputcsv($handle, array($row['username'], $row['email']));
}
 
// Finish writing the file
fclose($handle);
 
?>
 
</button>
</div>
 
There my code. now i have a dropdown like this.
 
<div>
<Select type="text" id="cboTable"  style="width:220px; height: 30px;">
 
<?php
$dbname = 'juice';
 
if (!mysql_connect('localhost', 'sample', 'sample')) {
echo 'Could not connect to mysql';
 
}
mysql_select_db($dbname);
$sql = "SHOW TABLES";
$result = mysql_query($sql);
 
if (!$result) {
echo "DB Error, could not list tables\n";
echo 'MySQL Error: ' . mysql_error();
 
}
 
while ($row = mysql_fetch_row($result)) {
//echo '<select>';
//echo "Table: {$row[0]}\n";
$tables = $row['0'];
echo '<option>'.$tables.'</option>';
}
 
 
mysql_free_result($result);
//echo '</select>';
 
?>
 
 
</select>
</div>
 
 
 
 
Now my problem is, I want to export the value selected on the dropdown when i click the button. I dont know how.
 
many thanks to whoever will help

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.