roipatrick Posted February 27, 2014 Share Posted February 27, 2014 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 Quote Link to comment Share on other sites More sharing options...
Barand Posted February 27, 2014 Share Posted February 27, 2014 You can select and write to outout file all in a single query with SELECT...INTO OUTFILE http://dev.mysql.com/doc/refman/5.6/en/select-into.html Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.