PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > SELECT'ing from an arry?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
SELECT'ing from an arry?

Réponse
 
LinkBack Outils de la discussion
Vieux 06/11/2007, 23h32   #1
Austin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut SELECT'ing from an arry?


$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

  Réponse avec citation
Vieux 07/11/2007, 00h15   #2
The Natural Philosopher
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: SELECT'ing from an arry?

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'?
  Réponse avec citation
Vieux 07/11/2007, 00h37   #3
Darko
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: SELECT'ing from an arry?

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

  Réponse avec citation
Vieux 07/11/2007, 00h41   #4
Austin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: SELECT'ing from an arry?

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.

  Réponse avec citation
Vieux 07/11/2007, 00h44   #5
x.OutThisLife@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: SELECT'ing from an arry?

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


lol@you

  Réponse avec citation
Vieux 07/11/2007, 01h00   #6
The Natural Philosopher
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: SELECT'ing from an arry?

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?
  Réponse avec citation
Vieux 07/11/2007, 01h11   #7
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: SELECT'ing from an arry?

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

  Réponse avec citation
Vieux 07/11/2007, 01h27   #8
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: SELECT'ing from an arry?

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

  Réponse avec citation
Vieux 07/11/2007, 05h19   #9
The Natural Philosopher
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: SELECT'ing from an arry?

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?
  Réponse avec citation
Vieux 07/11/2007, 12h08   #10
Nilesh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: SELECT'ing from an arry?

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

  Réponse avec citation
Vieux 07/11/2007, 12h53   #11
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: SELECT'ing from an arry?

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

  Réponse avec citation
Vieux 07/11/2007, 13h29   #12
dave
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: SELECT'ing from an arry?

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.

  Réponse avec citation
Vieux 07/11/2007, 13h46   #13
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: SELECT'ing from an arry?

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
=================
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 03h40.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,24697 seconds with 21 queries