Jump to content

kristian_gl

Members
  • Posts

    22
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

kristian_gl's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello I have a table in mysql database that I wish to export to a CSV file, I've found a script that does this, but all the fieldnames show up in one cell in Excel, and the rows in one other single cell. I want it to look something like this when I open Excel: Colname1 | Colname2 |Colname3 rowvalue1 | rowvalue2 | rowvalue3 rowvalue4 | rowvalue5 | rowvalue6 Kristian
  2. thanks, that worked just fine. just one tiny problem, in the list/meny, there are some empty spaces, which you can select where the tables that are not showing just to be
  3. can you show me in the code where to put it. Sorry, but i'm not that good with PHP
  4. Hello, need to show some of the tables in my database in a list/meny. At any given time I don't know how many tables there are in the DB, and what names they got, only which tables I don't wanna show (which are always the same). In the code below, I manage to show all the tables: $sql = "SHOW TABLES FROM oddl"; $result = mysql_query($sql); ?> <form method="POST" action ="../admin/forhaandsvisning.php"> <p><select name="undersokelser" size="15" id="undersokelser"> <?php while($row = mysql_fetch_row($result)) { ?> <option value="<?php echo $row[0];?>"><?php echo $row[0];?></option> <?php } ?> </select> Any ideas?
  5. Hey guys, I'm trying to export a table in a mysql database. But i can't seem to get it to work. Instead of a "save as - popup message" when I run the code I get some errors: Notice: Undefined variable: csv_output in /home/stud/oddl/public_html/admin/export.php on line 22 Warning: Cannot modify header information - headers already sent by (output started at /home/stud/oddl/public_html/admin/exporter.php:2) in /home/stud/oddl/public_html/admin/export.php on line 38 Warning: Cannot modify header information - headers already sent by (output started at /home/stud/oddl/public_html/admin/exporter.php:2) in /home/stud/oddl/public_html/admin/export.php on line 39 Warning: Cannot modify header information - headers already sent by (output started at /home/stud/oddl/public_html/admin/exporter.php:2) in /home/stud/oddl/public_html/admin/export.php on line 40 And the content of the table shows in export.php, but it will not automatically save to a CVS.file. I have also tried to put this: header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); header( "Content-disposition: filename=".$filename.".csv"); at the top of the document, and managed to remove the: "Warning: Cannot modify header information" errors, but with still no saving to CVS. CODE: <?php ini_set('display_errors', 1); error_reporting(E_ALL); $host = 'db.stud.aitel.hist.no'; $user = 'oddl'; $pass = 'EgjdlAQk'; $db = 'oddl'; $table = 'svar'; $file = 'test'; $link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error()); mysql_select_db($db) or die("Can not connect."); $result = mysql_query("SHOW COLUMNS FROM ".$table.""); $i = 0; if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { $csv_output .= $row['Field'].";"; $i++; } } $csv_output .= "\n"; $values = mysql_query("SELECT * FROM ".$table.""); while ($rowr = mysql_fetch_row($values)) { for ($j=0;$j<$i;$j++) { $csv_output .= $rowr[$j].";"; } $csv_output .= "\n"; } $filename = $file."_".date("d-m-Y_H-i",time()); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); header( "Content-disposition: filename=".$filename.".csv"); print $csv_output; exit; ?> Kristian
  6. preview.php: <form id="form100" name="form100" method="POST" action="preview.php"> <input type="submit" name="back" id="tilbake" value="Back" /> <input type="submit" name="finish" id="lagre" value="Finished" /> <input type="submit" name="publish" id="publiser" value="Publish" /> </form> <br /> <?php $finish= $_POST['finish']; $back= $_POST['back']; $publish= $_POST['publish']; if (isset($finish)) { setcookie("navn_cookie", "", time()-3600); header('Location: http://stud.aitel.hist.no/~oddl/admin/admin.php'); } elseif (isset($back)) { header('Location: http://stud.aitel.hist.no/~oddl/admin/leggtilspm.php'); } elseif (isset($publish)) { $drop_table = "DROP TABLE `svar`"; mysql_query($drop_table); $create_table = 'CREATE TABLE `svar` (' . ' `id` INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY' . ' )' . ' ENGINE = myisam;'; mysql_query($create_table); header('Location: http://stud.aitel.hist.no/~oddl/admin/undersokelse.php'); } ?> When I click on any of the submitbuttons, the page just refreshes itself, and doing what I've haved specified in the if-loop
  7. thank you, it worked
  8. Hello I have a website which i've been developing locally(localhost), but when I put on the web I get this error when I try to load a page that calls to a function: Fatal error: require_once() [function.require]: Failed opening required 'http://stud.aitel.hist.no/~oddl/admin/auth.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/stud/oddl/public_html/admin/admin.php on line2 Or: Fatal error: Call to undefined function kobleTil() in /home/stud/oddl/public_html/public/public_undersokelse.php on line 1 When i run the website on localhost, everything works just fine, any tips?
  9. Hey guys and girls I need to modify a string that look like this: "yes no yes" into a string that look like this: "NULL, \'yes\', \'no\', \'yes\'" so far I got this code: $arr= $_POST; $string = implode (" ", $arr); $string = ", \'" . $string . "\'"; $string = "NULL" . $string; echo $string; but it's output is: "NULL, \'yes no yes\'" Any help would be much appreciated Kristian
  10. thanks Mchl, just what I was looking for
  11. yes I know that my design is not optimal, but it's just for a school project, and I can live with some flaws (better that then going back to change the whole setup). So if anybody could help me with: 1. get column names from table "answers" 2. put each column name in a variable (maybe $col1, $col2, $col3 and so on..) it would be extremely helpful
  12. Pseudo code: 1. get column names from table "answers" 2. put each column name in a variable (maybe $col1, $col2, $col3 and so on..) 3. use these variables in a SQL-query ( something like this: $sql = "INSERT INTO $db. `answers( `$col1`, `$col2``$col3`) VALUES (NULL, \'hei\', \'\', NULL);";
  13. yes, I have looked at extract(), but I can't seem to make it work. If somebody could show me exactly how to give each value in: $columns[0] a different variable it would be really helpful. Remember that I dont know the what the values are, and how many of they there are at any given time, so it makes it a bit more complicated.
  14. It wasn't exactly what I was looking for. I need to give the different values in the array different variables, which only contain one of each value in the array
  15. thanks guys, I will try your suggestions tomorrow
×
×
  • 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.