Jul 20, 2008

Question : Read Line And Post To Sql - Help

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Question : Read Line And Post To Sql - Help

farsiscript
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 :

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 sad.gif

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

Reply

Spectre
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:
CODE
<?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]) . '\')');
}
?>

 

 

 


Reply

farsiscript
thanks dear Spectre
i have one problem i need sort database in ascendant format
for example my table has many row and i want show big value in row
for example 2 : like ranking
show and sorting big ranks on top of page
i dont know how can i show this search result
plz help me
thanks

Reply

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

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


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

Reply

farsiscript
i thanks for your help
my code is :
CODE
<?php
include "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

Reply

Spectre
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.

Reply

farsiscript
Yes Dear Spectre
i use this code for show top rating :
CODE
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

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics
Looking for read, line, post, sql

Searching Video's for read, line, post, sql
advertisement



Question : Read Line And Post To Sql - Help



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE