|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
$lines = file("list.txt"); $l_count = count($lines); for($i = 0; $i < 3; $i++) { $var = $lines[$i]; } mysql_query("SELECT name FROM list WHERE name='$var'"); In the list.txt it would have data like: Code: One Two Three And "echo $list[0];" would come up as "one". I need to SELECT the name "one" and return the column data. It doesn't select anything, even though it does get the data correctly when echo'd. What's wrong? OR am I going the wrong way w/ this? :x |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Austin wrote:
> $lines = file("list.txt"); > $l_count = count($lines); > > for($i = 0; $i < 3; $i++) { > $var = $lines[$i]; > } > > mysql_query("SELECT name FROM list WHERE name='$var'"); > > > > In the list.txt it would have data like: > Code: > > One > Two > Three > > > > And "echo $list[0];" would come up as "one". > > I need to SELECT the name "one" and return the column data. > > It doesn't select anything, even though it does get the data correctly > when echo'd. What's wrong? > > OR am I going the wrong way w/ this? :x > I am completely baffled. What makes you think that Mysql has anything to do with a file called 'list.txt'? |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Nov 7, 12:32 am, Austin <phr...@gmail.com> wrote:
The way > $lines = file("list.txt"); > $l_count = count($lines); > > for($i = 0; $i < 3; $i++) { > $var = $lines[$i]; > > } > > mysql_query("SELECT name FROM list WHERE name='$var'"); > > In the list.txt it would have data like: > Code: > > One > Two > Three > > And "echo $list[0];" would come up as "one". > > I need to SELECT the name "one" and return the column data. > > It doesn't select anything, even though it does get the data correctly > when echo'd. What's wrong? > > OR am I going the wrong way w/ this? :x This is the way I see this code: $lines = file("list.txt"); // lines are read into $lines $l_count = count($lines); // useless variable for($i = 0; $i < 3; $i++) { // read three lines, each into $var, overwriting the previous $var = $lines[$i]; } // at the end, the last line read is held in $var // give me all names from list where name is equal to the last line read // (you say it's "three"), and lose the return value (you didn't assign it to anything) mysql_query("SELECT name FROM list WHERE name='$var'"); // you should have at least do: $results = mysql_query("SELECT name FROM list WHERE name='$var'"); // then you could use mysql_fetch_array to fetch the results from the $results resource Resume: * you didn't echo anything in the given example, although you say "it does get the data correctly when echo'd" * you don't get "one", but "three" in $var after the loop * you don't use your mysql_query() result in any way (you should use mysql_fetch_array()) * you shouldn't just include $var in the query, it is very bad security-wise - you should do something like this: $results = mysql_query( sprintf( "select name from list where name='%s'", mysql_real_escape_string( $var ) ) ); (having in mind, of course, that you've properly stripped slashes if get_magic_quotes_gpc() returned true) * the last, but not the least, you're very vague about what you're trying to do Regards, Darko |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Nov 6, 7:15 pm, The Natural Philosopher <a...@b.c> wrote:
> Austin wrote: > > $lines = file("list.txt"); > > $l_count = count($lines); > > > for($i = 0; $i < 3; $i++) { > > $var = $lines[$i]; > > } > > > mysql_query("SELECT name FROM list WHERE name='$var'"); > > > In the list.txt it would have data like: > > Code: > > > One > > Two > > Three > > > And "echo $list[0];" would come up as "one". > > > I need to SELECT the name "one" and return the column data. > > > It doesn't select anything, even though it does get the data correctly > > when echo'd. What's wrong? > > > OR am I going the wrong way w/ this? :x > > I am completely baffled. What makes you think that Mysql has anything to > do with a file called 'list.txt'? Well if you flatfile something then sure it does... Now ignore the irrelevant and input something useful. |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
> I am completely baffled. What makes you think that Mysql has anything to
> do with a file called 'list.txt'? lol@you |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
Austin wrote:
> On Nov 6, 7:15 pm, The Natural Philosopher <a...@b.c> wrote: >> Austin wrote: >>> $lines = file("list.txt"); >>> $l_count = count($lines); >>> for($i = 0; $i < 3; $i++) { >>> $var = $lines[$i]; >>> } >>> mysql_query("SELECT name FROM list WHERE name='$var'"); >>> In the list.txt it would have data like: >>> Code: >>> One >>> Two >>> Three >>> And "echo $list[0];" would come up as "one". >>> I need to SELECT the name "one" and return the column data. >>> It doesn't select anything, even though it does get the data correctly >>> when echo'd. What's wrong? >>> OR am I going the wrong way w/ this? :x >> I am completely baffled. What makes you think that Mysql has anything to >> do with a file called 'list.txt'? > > Well if you flatfile something then sure it does... > Now ignore the irrelevant and input something useful. > I wansn't aware that Mysql dealt with flat files. I cant see the point of using it with a flat file that has already been opened another way.. I didnt think a mysql query worked without opening a connection to a database. Now, what am I missing here? |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
Austin wrote:
> $lines = file("list.txt"); > $l_count = count($lines); > > for($i = 0; $i < 3; $i++) { > $var = $lines[$i]; > } > > mysql_query("SELECT name FROM list WHERE name='$var'"); > > > > In the list.txt it would have data like: > Code: > > One > Two > Three > > > > And "echo $list[0];" would come up as "one". > > I need to SELECT the name "one" and return the column data. > > It doesn't select anything, even though it does get the data correctly > when echo'd. What's wrong? > > OR am I going the wrong way w/ this? :x > > You don't show any place where you're are actually getting the data. How about posting all of your code? -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
The Natural Philosopher wrote:
> Austin wrote: >> On Nov 6, 7:15 pm, The Natural Philosopher <a...@b.c> wrote: >>> Austin wrote: >>>> $lines = file("list.txt"); >>>> $l_count = count($lines); >>>> for($i = 0; $i < 3; $i++) { >>>> $var = $lines[$i]; >>>> } >>>> mysql_query("SELECT name FROM list WHERE name='$var'"); >>>> In the list.txt it would have data like: >>>> Code: >>>> One >>>> Two >>>> Three >>>> And "echo $list[0];" would come up as "one". >>>> I need to SELECT the name "one" and return the column data. >>>> It doesn't select anything, even though it does get the data correctly >>>> when echo'd. What's wrong? >>>> OR am I going the wrong way w/ this? :x >>> I am completely baffled. What makes you think that Mysql has anything to >>> do with a file called 'list.txt'? >> >> Well if you flatfile something then sure it does... >> Now ignore the irrelevant and input something useful. >> > I wansn't aware that Mysql dealt with flat files. > > I cant see the point of using it with a flat file that has already been > opened another way.. > > I didnt think a mysql query worked without opening a connection to a > database. > > Now, what am I missing here? > You're missing the fact he only showed maybe 2% of his code, and that he's querying a MySQL database for rows that match the contents of the flat file. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
Jerry Stuckle wrote:
> The Natural Philosopher wrote: >> Austin wrote: >>> On Nov 6, 7:15 pm, The Natural Philosopher <a...@b.c> wrote: >>>> Austin wrote: >>>>> $lines = file("list.txt"); >>>>> $l_count = count($lines); >>>>> for($i = 0; $i < 3; $i++) { >>>>> $var = $lines[$i]; >>>>> } >>>>> mysql_query("SELECT name FROM list WHERE name='$var'"); >>>>> In the list.txt it would have data like: >>>>> Code: >>>>> One >>>>> Two >>>>> Three >>>>> And "echo $list[0];" would come up as "one". >>>>> I need to SELECT the name "one" and return the column data. >>>>> It doesn't select anything, even though it does get the data correctly >>>>> when echo'd. What's wrong? >>>>> OR am I going the wrong way w/ this? :x >>>> I am completely baffled. What makes you think that Mysql has >>>> anything to >>>> do with a file called 'list.txt'? >>> >>> Well if you flatfile something then sure it does... >>> Now ignore the irrelevant and input something useful. >>> >> I wansn't aware that Mysql dealt with flat files. >> >> I cant see the point of using it with a flat file that has already >> been opened another way.. >> >> I didnt think a mysql query worked without opening a connection to a >> database. >> >> Now, what am I missing here? >> > > You're missing the fact he only showed maybe 2% of his code, and that > he's querying a MySQL database for rows that match the contents of the > flat file. > Now by what leap of faith did you arrive at that conclusion? |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
This is completely irrelevant with each other. What does that file has
to do with MySQL ? Lol |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
The Natural Philosopher wrote:
> Jerry Stuckle wrote: >> The Natural Philosopher wrote: >>> Austin wrote: >>>> On Nov 6, 7:15 pm, The Natural Philosopher <a...@b.c> wrote: >>>>> Austin wrote: >>>>>> $lines = file("list.txt"); >>>>>> $l_count = count($lines); >>>>>> for($i = 0; $i < 3; $i++) { >>>>>> $var = $lines[$i]; >>>>>> } >>>>>> mysql_query("SELECT name FROM list WHERE name='$var'"); >>>>>> In the list.txt it would have data like: >>>>>> Code: >>>>>> One >>>>>> Two >>>>>> Three >>>>>> And "echo $list[0];" would come up as "one". >>>>>> I need to SELECT the name "one" and return the column data. >>>>>> It doesn't select anything, even though it does get the data >>>>>> correctly >>>>>> when echo'd. What's wrong? >>>>>> OR am I going the wrong way w/ this? :x >>>>> I am completely baffled. What makes you think that Mysql has >>>>> anything to >>>>> do with a file called 'list.txt'? >>>> >>>> Well if you flatfile something then sure it does... >>>> Now ignore the irrelevant and input something useful. >>>> >>> I wansn't aware that Mysql dealt with flat files. >>> >>> I cant see the point of using it with a flat file that has already >>> been opened another way.. >>> >>> I didnt think a mysql query worked without opening a connection to a >>> database. >>> >>> Now, what am I missing here? >>> >> >> You're missing the fact he only showed maybe 2% of his code, and that >> he's querying a MySQL database for rows that match the contents of the >> flat file. >> > Now by what leap of faith did you arrive at that conclusion? > I read what he said. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|
|
#12 |
|
Messages: n/a
Hébergeur: |
On Nov 6, 4:15 pm, The Natural Philosopher <a...@b.c> wrote:
> Austin wrote: > > $lines = file("list.txt"); > > $l_count = count($lines); > > > for($i = 0; $i < 3; $i++) { > > $var = $lines[$i]; > > } > > > mysql_query("SELECT name FROM list WHERE name='$var'"); > > > In the list.txt it would have data like: > > Code: > > > One > > Two > > Three > > > And "echo $list[0];" would come up as "one". > > > I need to SELECT the name "one" and return the column data. > > > It doesn't select anything, even though it does get the data correctly > > when echo'd. What's wrong? > > > OR am I going the wrong way w/ this? :x > > I am completely baffled. What makes you think that Mysql has anything to > do with a file called 'list.txt'? i'm confused why he expects $var to equal anything but the last element in the array $list. |
|
|
|
#13 |
|
Messages: n/a
Hébergeur: |
dave wrote:
> On Nov 6, 4:15 pm, The Natural Philosopher <a...@b.c> wrote: >> Austin wrote: >>> $lines = file("list.txt"); >>> $l_count = count($lines); >>> for($i = 0; $i < 3; $i++) { >>> $var = $lines[$i]; >>> } >>> mysql_query("SELECT name FROM list WHERE name='$var'"); >>> In the list.txt it would have data like: >>> Code: >>> One >>> Two >>> Three >>> And "echo $list[0];" would come up as "one". >>> I need to SELECT the name "one" and return the column data. >>> It doesn't select anything, even though it does get the data correctly >>> when echo'd. What's wrong? >>> OR am I going the wrong way w/ this? :x >> I am completely baffled. What makes you think that Mysql has anything to >> do with a file called 'list.txt'? > > i'm confused why he expects $var to equal anything but the last > element in the array $list. > > Just a misplaced right brace... -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp\0\0\0jstucklex@attglobal.net ================= |
|
![]() |
| Outils de la discussion | |
|
|