SELECT"ing from an arry?

SELECT"ing from an arry?

am 07.11.2007 00:32:53 von Austin

$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

Re: SELECT"ing from an arry?

am 07.11.2007 01:15:01 von Courtney

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'?

Re: SELECT"ing from an arry?

am 07.11.2007 01:37:49 von darko

On Nov 7, 12:32 am, Austin 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

Re: SELECT"ing from an arry?

am 07.11.2007 01:41:55 von Austin

On Nov 6, 7:15 pm, The Natural Philosopher 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.

Re: SELECT"ing from an arry?

am 07.11.2007 01:44:22 von x.OutThisLife

> I am completely baffled. What makes you think that Mysql has anything to
> do with a file called 'list.txt'?

lol@you

Re: SELECT"ing from an arry?

am 07.11.2007 02:00:58 von Courtney

Austin wrote:
> On Nov 6, 7:15 pm, The Natural Philosopher 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?

Re: SELECT"ing from an arry?

am 07.11.2007 02:11:30 von Jerry Stuckle

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
==================

Re: SELECT"ing from an arry?

am 07.11.2007 02:27:04 von Jerry Stuckle

The Natural Philosopher wrote:
> Austin wrote:
>> On Nov 6, 7:15 pm, The Natural Philosopher 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
==================

Re: SELECT"ing from an arry?

am 07.11.2007 06:19:35 von Courtney

Jerry Stuckle wrote:
> The Natural Philosopher wrote:
>> Austin wrote:
>>> On Nov 6, 7:15 pm, The Natural Philosopher 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?

Re: SELECT"ing from an arry?

am 07.11.2007 13:08:12 von Nilesh India

This is completely irrelevant with each other. What does that file has
to do with MySQL ? Lol

Re: SELECT"ing from an arry?

am 07.11.2007 13:53:39 von Jerry Stuckle

The Natural Philosopher wrote:
> Jerry Stuckle wrote:
>> The Natural Philosopher wrote:
>>> Austin wrote:
>>>> On Nov 6, 7:15 pm, The Natural Philosopher 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
==================

Re: SELECT"ing from an arry?

am 07.11.2007 14:29:49 von dave

On Nov 6, 4:15 pm, The Natural Philosopher 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.

Re: SELECT"ing from an arry?

am 07.11.2007 14:46:47 von Jerry Stuckle

dave wrote:
> On Nov 6, 4:15 pm, The Natural Philosopher 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 Corpjstucklex@attglobal.net
=================