Jump to content
Larry Ullman's Book Forums

newbie3

Members
  • Content Count

    16
  • Joined

  • Last visited

  • Days Won

    1

newbie3 last won the day on February 3 2012

newbie3 had the most liked content!

Community Reputation

4 Neutral

About newbie3

  • Rank
    Newbie
  1. Hello The first solution works but not good enough. We need to download the good csv file to a local PC but the csv file stays on the web server in the directory where the script is run. We got the second solution working now. The amended script that work is as follows: header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename=data.csv'); $fpw = fopen('datag.csv', 'wt'); $query = "SELECT * FROM table" ; $result = mysqli_query($dbc, $query) ; while($row = mysqli_fetch_assoc($result)) { fputcsv($fpw, $row); } readfile ('datag.csv') ; Two lines of the script in the second solution that is working now are $fpw = fopen('datag.csv', 'wt'); (Note : changed from $fpw = fopen('php://output', 'wt') readfile ('datag.csv') ; ( a new line added) Thanks for taking time to contribute your opinion. Regards Newbie3
  2. Hello The following scripts work (good csv file) $fpw = fopen('datab.csv', 'wt'); $query = "SELECT * FROM table" ; $result = mysqli_query($dbc, $query) ; while($row = mysqli_fetch_assoc($result)) { fputcsv($fpw, $row); } The following scripts fail to work ( produces bad csv file) header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename=data.csv'); $fpw = fopen('php://output', 'wt'); $query = "SELECT * FROM table" ; $result = mysqli_query($dbc, $query) ; while($row = mysqli_fetch_assoc($result)) { fputcsv($fpw, $row); } Therefore, the different is between $fpw = fopen('datab.csv', 'wt') which works ; and the 3 lines below (which do not work). header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename=data.csv'); $fpw = fopen('php://output', 'wt'); It appears that it has nothing to do with fputcsv. Regards Newbie3
  3. Hello Although Microsoft Access is able to read the bad csv file successfully, we are not so lucky when we tried to use other off the shelf application to read the bad csv file. It appears as a long string of characters in other applications, and therefore we are not able to use the bad csv as a source to import data into the other applications. Any suggestion or comment is much appreciated. Regards Newbie3
  4. Hi HartleySan You are great. What we gain most from you is the guidance and the directions you offer on solving the problem. Those are the most valuable. This is not the first time we gain somethings from you. It did not occur to us that being able to read the data correctly from the csv file is more important that how the csv file is being displayed by Notepad. We thought that not being able to display correctly in Notepad means not being able to be read correctly by other applications. You are right, it is about rendering. We tried as you suggested and Microsoft Access is able to read the "bad" csv file successfully. Being able to read correctly by Microsoft Access solves the most parts of our problem. We will try other applications to read the bad csv file. Thank you again and very much appreciated. Regards Newbie3
  5. Hello Just wonder if anyone has generated a good csv file successfully using php function of fputcsv in Windows environment. By a good csv file we mean there are clear multiple separate lines view in notepad. A bad csv file means there is no separate line view in notepad. What we see is only one line with a very long string of characters. It appears that the small rectangles in between the very long string of characters mark the end of lines. Any comment, assistance is very much appreciated. Regards Newbie3
  6. Hi helpful readers From fputcsv, we keep getting improper end of line in a .csv file view from Notepad. We spent quite a fair bit of time but still to no avail, hope someone could assist, thanks in advance. We execute the following lines: header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename=data.csv'); $fs = fopen('php://output', 'wt'); // In addition to 'wt', we have also tried ,'w' and 'wb', no different in output. $query = "SELECT * FROM table" ; $result = mysqli_query($dbc, $query) ; while($row = mysqli_fetch_assoc($result)) { fputcsv($fs, $row, ','); } Regards Newbie3
  7. Hi I found the codes. I overlooked this. Please ignore my previous question, sorry. Regards Newbie3
  8. Hi helpful readers The codes for pagination in chapter 10 are not available in the download link below. Am I missing something? http://www.larryullman.com/books/php-and-mysql-for-dynamic-web-sites-visual-quickpro-guide-4th-edition/ (phpmysql4_scripts.zip) I am learning pagination now.. Thanks in advance for assistance Regards Newbie3
  9. Thank You HartleySan, much appreciated. Resolved. Running "http://localhost/ajax/add_employee_xml.php" gave me a clue where the problem was. The problem was in "mysql.inc.php" which contains scripts to connect to MySQL. Never suspected that the problem could be in that script. The mistake I made was that I included basic HTML tags in the "mysql.inc.php" script. The file "mysql.inc.php" should contain only PHP scripts. Refer page 18 for more details. These HTML tags in the "mysql.inc.php" work fine in all my other testings until this ResponseXML property comes into picture. As you said, slight error will stop EVERYTHING from working. Thanks again.
  10. Thank you HartleySan The book uses responseXML property and show no message. I expect to see some messages as I add an employee. I insert responseText property into the codes and I got messages back because of the responseText property. The question I have is that how come the codes in the book (which uses responseXML) did not work for me? I made no changes to the codes in the book. Regards
  11. Hi Larry The problem has not been resolved yet. When we add an employee, there is no message return. Regards
  12. Hi there Thanks for the trouble shooting steps recommended (.innerHTML etc) which highlighted that date.time zone was not set correctly. Corrected the date.time zone via php.ini, it works fine only when ajax.responseText is in place. If we remove the trouble shooting statements (<div id=message_xml></div> ; <div id=message_text></div> ; the ajax.responseXML and ajax.responseText) and purely rely on the codes as written in the book (var data = ajax.responseXML; etc), we get no message at all. Trouble shooting statements: 1. add the following in "add_employee.html" <div id=message_xml></div> <div id=message_text></div> 2. add the following in "add_employee.js" document.getElementById('message_xml').innerHTML = ajax.responseXML; document.getElementById('message_text').innerHTML = ajax.responseText; Results : [object XMLDocument] (ajax.responseXML) last_name email phone_ext Please correct problems with the highlighted field(s) below. (ajax.responseText) . This is as expected as we key in the first name only. Regards
  13. Hi there Thank you very much, we see it now, as the components are : 'Click <a href="thanks.php?name=' $name '&email=' $email ' ">here</a>to continue.' With that, $variable, instead of literal (eg $name) is printed. Regards
  14. Hi there According to the book, the two print statements below are the same. 1. (On page 104) print "<p>Click <a href=\"thanks.php?name=$name&email=$email\">here</a>to continue.</p>" ; 2. (On page 105) print 'Click <a href="thanks.php?name=' . $name . '&email=' . $email . ' ">here</a>to continue.' ; What we don't understand is that why use concatenation, why not the print statement (on page 105) looks like below (without concatenation) print 'Click <a href="thanks.php?name=$name&email=$email">here</a>to continue.' ; Note: the print above contains double quotes for the url and because the single quotes of the print are used, no escape of double quote is required. We believe we miss something but not sure what it is. Thanks in advance for any explanation. Regards
  15. Hi there Ajax Status 200 & 304 is now successful and record has been added to the database. However, there is no message on the screen that say record has been added. Regards newbie3
×