473,813 Members | 3,307 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SELECT'ing from an arry?


$lines = file("list.txt" );
$l_count = count($lines);

for($i = 0; $i < 3; $i++) {
$var = $lines[$i];
}

mysql_query("SE LECT 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

Nov 6 '07 #1
12 1377
Austin wrote:
$lines = file("list.txt" );
$l_count = count($lines);

for($i = 0; $i < 3; $i++) {
$var = $lines[$i];
}

mysql_query("SE LECT 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'?
Nov 7 '07 #2
On Nov 7, 12:32 am, Austin <phr...@gmail.c omwrote:
The way
$lines = file("list.txt" );
$l_count = count($lines);

for($i = 0; $i < 3; $i++) {
$var = $lines[$i];

}

mysql_query("SE LECT 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("SE LECT name FROM list WHERE name='$var'");
// you should have at least do:
$results = mysql_query("SE LECT name FROM list WHERE name='$var'");
// then you could use mysql_fetch_arr ay 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_arr ay())
* 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_esca pe_string( $var ) )
);
(having in mind, of course, that you've properly stripped slashes if
get_magic_quote s_gpc() returned true)
* the last, but not the least, you're very vague about what you're
trying to do

Regards,
Darko

Nov 7 '07 #3
On Nov 6, 7:15 pm, The Natural Philosopher <a...@b.cwrot e:
Austin wrote:
$lines = file("list.txt" );
$l_count = count($lines);
for($i = 0; $i < 3; $i++) {
$var = $lines[$i];
}
mysql_query("SE LECT 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.

Nov 7 '07 #4
I am completely baffled. What makes you think that Mysql has anything to
do with a file called 'list.txt'?
lol@you

Nov 7 '07 #5
Austin wrote:
On Nov 6, 7:15 pm, The Natural Philosopher <a...@b.cwrot e:
>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?
Nov 7 '07 #6
Austin wrote:
$lines = file("list.txt" );
$l_count = count($lines);

for($i = 0; $i < 3; $i++) {
$var = $lines[$i];
}

mysql_query("SE LECT 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.
js*******@attgl obal.net
=============== ===

Nov 7 '07 #7
The Natural Philosopher wrote:
Austin wrote:
>On Nov 6, 7:15 pm, The Natural Philosopher <a...@b.cwrot e:
>>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.
js*******@attgl obal.net
=============== ===

Nov 7 '07 #8
Jerry Stuckle wrote:
The Natural Philosopher wrote:
>Austin wrote:
>>On Nov 6, 7:15 pm, The Natural Philosopher <a...@b.cwrot e:
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?
Nov 7 '07 #9
This is completely irrelevant with each other. What does that file has
to do with MySQL ? Lol

Nov 7 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
22963
by: Robert Chares | last post by:
Hello, I'm sure it has been asked a thousand times before, but still: How can I access a particular row in my MySQL table via PHP? The background is just to update the values of one row in the table via a html form with the old values already filled in. What I tried so far ist sth like this: $row=mysql_query('SELECT * FROM names WHERE ID=$entry');
6
1341
by: Jack | last post by:
Hello, <%@ Language=VBScript %> <% Response.Write "<FORM name=form1>" Response.Write "<select name=""select1"">" Response.Write "<option value=1>One</option>" Response.Write "<option value=2>Two</option>" Response.Write "<option value=3>Three</option>" Response.Write "</select>" Response.Write "</FORM>"
3
2410
by: Michael Qiu | last post by:
I hava a select component on my form. the width of the select component is fixed,so if the length of the option's shown string larger than the select component's width,how can i make the shown string wrap to next line? <select name=123 style="width:100px;height:200px"> <option value=1>abcdefghijklmnopqrstuvwxyz</option> </select> select component's width is 100px, the option's shown sring is abcdefghijklmnopqrstuvwxyz,if shown string's...
1
11345
by: John Hall | last post by:
We need to read a SQL database containing a mix of English words and Chinese Characters. We think we need to use the N'xxxx' to read the Unicode. We have one place where the SELECT statement works fine. Here is that statement: dim objCmdCategories as new SQLDataAdapter ("select distinct N'product_category' from " & _ "tblproducts where product_status=1 order by product_category", objConn) However, we can't seem to get another SELECT...
7
2291
by: brian.ackermann | last post by:
Hello all, I'm currently writing a tiny little bit of navigation to a page, and I've come across this stumbling block: Goto Page&nbsp;&nbsp; <select name="page"> <SCRIPT LANGUAGE="JavaScript1.2" > for ( var inc = 1; inc <= <%=nPages%>; inc++ ){ document.PageForm.page = new Option(inc, inc, ((inc ==
1
11586
by: Ahmet Karaca | last post by:
Hi. myds.Reset(); mycommand.SelectCommand.CommandText= "Select att1 from Ing as Ingredient, Pro as Product "+ "where Pro.ad='apple' and Pro.id=Ing.id"; mycommand.Fill(myds, "Product"); // Here is the problem listbox.DataSource = myds.Tables.DefaultView; // Here again listbox.DataTextField = "invid"; // Here again listbox.DataBind(); mycon.Close()
6
13030
by: Chris Fink | last post by:
Does anyone know it is possible to include a small image(.gif .jpeg) within a <SELECT><option> so that the user would see the option text as well as a little image(icon) in the option? I know this is not an ASP.NET related question, but I know this group is knowledgeable and quick with responses. Thanks
6
28742
by: mabond | last post by:
Hi Is it possible to compare a vaule for a select case statement using a wildcard. e.g. somthing like Select case myValue case like "*ing" end select
1
8165
by: Veeru71 | last post by:
When I am SELECT'ing a CLOB column from command prompt, the output is getting truncated after a certail limit (8 K ??) How do I get the full data out of a CLOB column? Are there any string manipuration functions for CLOB fields to read it in multiple chunks ? Thanks in advance.
0
9734
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10408
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10426
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10141
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7686
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3886
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3030
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.