Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have to display data consisting of approx. 1000 character.
Right now, I am using a text file and fetching it from there line by line till end of file and displaying it through AJAX.
But its quite slow.
I wanted to know if i store that data in database as text would it make difference ?
Yes. It does depend on how many lines there are tho. If there aren't many lines, it won't make much of a difference.
I would recommend (for something small) a txt file on the server and directly getting it directly with AJAX, without the addition step of php and sql.
You shouldn't need to read line by line. You can read the full string with:
file_get_contents('/path/to/file')
I cannot foresee storing the text in a single database row/field will improve efficiency at all.
actually storing text in database can slowdown performance, looks like your problem is in line-by-line reading, read about file_get_contents or file or the best way readfile
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I just received a source from my customer (it's written by PHP Generally), I try to read it and glance at database. I realize that it's very mess, some webpage's content is also saved in database. So, I want to find files are using by browser and I mean that php files, I want to edit them. Can I do that?
P/S: I'm sorry if this article bother you
Hi At any point you need to know what functions, what includes and what arguments are being passed just use debug_print_backtrace() function in your code.
for further reading follow http://www.php.net/manual/en/function.debug-print-backtrace.php
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I got it from MaxMind
And this is how the data looks like:
Country,City,AccentCity,Region,Population,Latitude,Longitude
ad,aixas,AixĂ s,06,,42.4833333,1.4666667
ad,aixirivali,Aixirivali,06,,42.4666667,1.5
ad,aixirivall,Aixirivall,06,,42.4666667,1.5
ad,aixirvall,Aixirvall,06,,42.4666667,1.5
ad,aixovall,Aixovall,06,,42.4666667,1.4833333
ad,andorra,Andorra,07,,42.5,1.5166667
I want to convert the structure of this unknown type data into MySQL query language so that I can insert it into my MySQL database. Is it possible?
The data is about 145 MB!! I can paste the whole data code if required.
Alternative required solution: What should I do to insert it in my database?
that looks like a regular CSV to me, and PHPMyAdmin is capable of handling such format in the import menu
The problem I see there is that you've got a large file to upload and most php configurations won't allow you such big upload. Why not try it with, say, the first 1000 lines of your file?
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am trying to read a file, but it keeps printing all of the data to the page without my asking it to do so.
The code is:
<?php
$htmlAppointmentPage = readfile('AppointmentPageTemplate.html');
?>
That's all of the code. For some reason it's echoing the contents of AppointmentPageTemplate.html.
You want file_get_contents() and not readfile().
From the Manual:
This function is similar to file(), except that file_get_contents()
returns the file in a string, starting at the specified offset up to
maxlen bytes. On failure, file_get_contents() will return FALSE.
file_get_contents() is the preferred way to read the contents of a
file into a string. It will use memory mapping techniques if supported
by your OS to enhance performance.
Please note that if your file is very large, it would take a lot of memory (= the file's size) to place it into a variable. Make sure you don't go over the limit set in php.ini.
readfile reads the contents of a file and outputs them to the page.
To get the contents of a file as string (and assign them to a variable), use file_get_contents
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a folder which contains several html files: 1.html, 2.html, 3.html, etc., etc. in sequential order.
I would like for PHP to randomly load in these files into a PHP webpage that I have. How can I go about doing this?
Also -- is PHP the most efficient way to do this? Would jQuery be better?
jquery could do it, but you'd have to send a list of the available files to the client beforehand, so it has a list to choose from. This would be required if you can't guaranteed there'll never be "holes" in the files, e.g. 1,2,4,5 (hey, where's 3?).
PHP can deal with the raw filesystem, and can always get the list of files, e.g.
<?php
$files = glob('*.html');
$random_file = $files[array_rand($files)];
include($random_file);
This will handle any .html file, regardless of holes in the numbering sequence, or even if they're numbered at all.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am a new user of php.
I have one table in mysql database. I have a form which the users use to query the mysql database. I am testing my html form page on my linux laptop which has APACHE server.
I am able to make a connection to the mysql database and display results in the browser.
I am not sure how to capture the results from the variable which has query results which has several rows of data and be able to write the results to a text file in /var/www/
Thank you
I noticed every time you check if the POST variable is set you use something like
if(isset($POST["submit"])){
Was that a typo in this post or are you forgetting the underscore?
if(isset($_POST["submit"])){
Also try to use mysql_fetch_assoc instead of mysql_fetch_array.
And always prepare the variabes for usage in a query if you do not want to get hacked instantly.