Jump to content
xisto Community
Sign in to follow this  
farsiscript

Question : Read Line And Post To Sql Help

Recommended Posts

Hi all
I need php script to read file like this :

file.txt :
farsi1
farsi2
farsi3
farsi4
farsi5
farsi6
farsi7

and then put one line at 1 row sql i know i can read all data in file by this code :

$fd = fopen ($urladd, "r");while (!feof ($fd)) {$sou = fgets($fd, 4096);}fclose ($fd);
But this code read all file and put in $sou string
after while is finish $sou is null :rolleyes:

I Dont Want $sou string is null
i want save $sou at Sql

i want line by line can input in another row to sql
thanks
sorry my en is not very good
Edited by farsiscript (see edit history)

Share this post


Link to post
Share on other sites

PHP comes equipped with a host of very useful filesystem functions. file_get_contents() (PHP >= 4.3.0 only) is basically a shorter method of what you are trying to do - it reads an entire file into a string, but with one simple function. You can then do with the string as you will. The file() function is also a useful method for reading a file into an array line by line.

I'm not 100% sure what you are attempting to do, but if it's what I think it is, try something like this:

<?php$sou = file_get_contents($urladd);$sou = str_replace("\r\n","\n",$sou);$sou_a = explode("\n",$sou);for( $i=0;$i<count($sou_a);$i++ ) {  mysql_query('INSERT INTO table (field) VALUES (\'' . @mysql_escape_string($sou_a[$i]) . '\')');}?>

Share this post


Link to post
Share on other sites

thanks dear Spectrei have one problem i need sort database in ascendant formatfor example my table has many row and i want show big value in rowfor example 2 : like rankingshow and sorting big ranks on top of page i dont know how can i show this search resultplz help methanks

Share this post


Link to post
Share on other sites

MySQL allows you to sort results in either ascending or descending order. For example:

mysql_query('SELECT field FROM table ORDER BY field2 DESC');

Where 'field2' contains the values you want all rows to be sorted by.

Share this post


Link to post
Share on other sites

i thanks for your help
my code is :

<?phpinclude "class/config.php";$result = mysql_query('SELECT * FROM `member` ORDER BY `rate` DESC LIMIT 0 , 30');while($r=mysql_fetch_array($result)){$userid=$r["userid"];$rate=$r["rate"];echo " $userid : $rate <br> ";}?>
I want show top rate user
rates are save in rate column
But when my user rate are 1000 my code dosent show at top
plz help me thanks

Share this post


Link to post
Share on other sites

It should work fine, assuming you've connected to your MySQL host and defined a database to use via mysql_connect() and mysql_select_db() respectively (or used other appropriate functions) prior to executing the query. You might want to check the data in the database, and that you are referencing all fields correctly.Note also that 'LIMIT' starts at the first record (record 0) by default; so although it really doesn't matter, using 'LIMIT 0,X' will produce identical results as just using 'LIMIT X'. I tend to use the mysql_fetch_assoc() function as well instead of mysql_fetch_array() when requiring an associative array; but that doesn't really matter either.

Share this post


Link to post
Share on other sites

Yes Dear Spectre
i use this code for show top rating :

mysql_query('SELECT * FROM `member` ORDER BY `rate` DESC LIMIT 0 , 30');

thanks to You and an other friend
i finding this code here and in phpmyadmin

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.