473,404 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Foreach displaying data twice

I must be missing something rather obvious. I have the following
snippet of code that echo's my result twice when it should be echoing
just once (only one element in the array). What am I overlooking?
********************************
$OpenQ = mysql_query("SELECT column FROM table WHERE q_uid =
$_SESSION[userid] AND status = 1",$db); // SQL query on DB returns 1
result

$Qresult = mysql_fetch_array($OpenQ); // Fetch the array

if ($_GET['OQ']) { // If the get variable is recieved
foreach ($Qresult as $Q) {
echo "<br>" . $Q;
}
}

*********************************

TY.

Jun 1 '07 #1
16 4474
Akhenaten kirjoitti:
I must be missing something rather obvious. I have the following
snippet of code that echo's my result twice when it should be echoing
just once (only one element in the array). What am I overlooking?
********************************
$OpenQ = mysql_query("SELECT column FROM table WHERE q_uid =
$_SESSION[userid] AND status = 1",$db); // SQL query on DB returns 1
result

$Qresult = mysql_fetch_array($OpenQ); // Fetch the array
This returns an array that has both index and associative keys. Ie. what
you get is array(0=>'something','column'=>'something');
>
if ($_GET['OQ']) { // If the get variable is recieved
foreach ($Qresult as $Q) {
When you loop thru the array, naturally you'll go thru both the index
and the associative key, which both point to the same value. Instead of
foreaching, you could just echo $Qresult[0] or use mysql_fetch_row or
mysql_fetch_assoc.
echo "<br>" . $Q;
}
}

*********************************

TY.

--
Ra*********@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
Jun 1 '07 #2
At Fri, 01 Jun 2007 07:59:11 -0700, Akhenaten let h(is|er) monkeys type:
I must be missing something rather obvious. I have the following
snippet of code that echo's my result twice when it should be echoing
just once (only one element in the array). What am I overlooking?
********************************
$OpenQ = mysql_query("SELECT column FROM table WHERE q_uid =
$_SESSION[userid] AND status = 1",$db); // SQL query on DB returns 1
result
Rami has answered your question. I just wondered whether:
a) userid is a defined constant. If not, it should be in quotes.
b) $_SESSION[userid] (and q_uid) is a numerical or a string. If the
latter, it should be in quotes.

Just my 2cts.

Sh.
Jun 1 '07 #3
Schraalhans Keukenmeester kirjoitti:
At Fri, 01 Jun 2007 07:59:11 -0700, Akhenaten let h(is|er) monkeys type:
>I must be missing something rather obvious. I have the following
snippet of code that echo's my result twice when it should be echoing
just once (only one element in the array). What am I overlooking?
********************************
$OpenQ = mysql_query("SELECT column FROM table WHERE q_uid =
$_SESSION[userid] AND status = 1",$db); // SQL query on DB returns 1
result

Rami has answered your question. I just wondered whether:
a) userid is a defined constant. If not, it should be in quotes.
I used to think this too, but after reading the manual once again
carefully, I discovered that this is not the case. Singlequotes in array
keys aren't required when inside double quotes. It will not look for the
constant, _unless_ you also use curly braces around it.

$foo = "$array[key]"; // This is right, assumes key is a string

$foo = "{$array[key]}"; // this assumes key is a constant, then falls
back to string, so it'll trigger some stupid notice..

$foo = "{$array['key']}"; // This again is right

$foo = "$array['key']"; // quotes without curly braces is wrong, parse
error.

The thing is, if you're calling a multidimensional array, you gotta use
the curly braces, and that forces you to use the single quotes:
$foo = "{$array[0]['key']}";

It's all here in the better book:
http://fi.php.net/manual/en/language.types.string.php

--
Ra*********@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
Jun 1 '07 #4
I have an upload script which I want to use to upload word documents.
This works fine on my Gradwell account. However on the client's
(windows) hosting it fails.

C:\WINDOWS\TEMP\php29D.tmp
Warning: copy(papers/1180718015test.doc) [function.copy]: failed to open
stream: Permission denied in
\\nas01\nas\i\s\isbe2007.org\web\uploaddoc.php on line 22

I emailed support (Namesco) and received this reply
>There is no need to change permissions on Windows hosting. Your files by
default have the permissions to write to directories owned by your own
user.
Any suggestions?

--
Regards,

Geoff Berrow
Jun 1 '07 #5
At Fri, 01 Jun 2007 19:29:46 +0300, Rami Elomaa let h(is|er) monkeys type:
Schraalhans Keukenmeester kirjoitti:
>>********************************
$OpenQ = mysql_query("SELECT column FROM table WHERE q_uid =
$_SESSION[userid] AND status = 1",$db); // SQL query on DB returns 1
result

Rami has answered your question. I just wondered whether:
a) userid is a defined constant. If not, it should be in quotes.

I used to think this too, but after reading the manual once again
carefully, I discovered that this is not the case. Singlequotes in array
keys aren't required when inside double quotes. It will not look for the
constant, _unless_ you also use curly braces around it.

$foo = "$array[key]"; // This is right, assumes key is a string

$foo = "{$array[key]}"; // this assumes key is a constant, then falls
back to string, so it'll trigger some stupid notice..

$foo = "{$array['key']}"; // This again is right

$foo = "$array['key']"; // quotes without curly braces is wrong, parse
error.

The thing is, if you're calling a multidimensional array, you gotta use
the curly braces, and that forces you to use the single quotes:
$foo = "{$array[0]['key']}";

It's all here in the better book:
http://fi.php.net/manual/en/language.types.string.php
Thanks for setting me straight Rami! Just checked and found it works the
other way around as well: if you DO use single quotes around an array
index inside a double-quoted string curly's are required, lest php throws
an error.
$arr = array('foo'=>'bar');
echo "I met my friends in the $arr[foo]";
I met my friends in the bar
echo "I met my friends in the $arr['foo']";
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE,
expecting T_STRING or T_VARIABLE or T_NUM_STRING
echo "I met my friends in the {$arr['foo']}";
I met my friends in the bar

SOmehow I never thought about the reason why I had to em-brace
one-dimensional array references inside "strings" or heredoc, which also
expands variables of course.

I think I prefer consistent use of curly braces in these situations, and
have the same syntax with any kind of array. Personal taste & habit I
guess.

Never too old to learn.
Rgds

--
Schraalhans Keukenmeester - sc*********@the.Spamtrapexample.nl
[Remove the lowercase part of Spamtrap to send me a message]

"strcmp('apples','oranges') < 0"

Jun 1 '07 #6
Geoff Berrow wrote:
I have an upload script which I want to use to upload word documents.
This works fine on my Gradwell account. However on the client's
(windows) hosting it fails.

C:\WINDOWS\TEMP\php29D.tmp
Warning: copy(papers/1180718015test.doc) [function.copy]: failed to open
stream: Permission denied in
\\nas01\nas\i\s\isbe2007.org\web\uploaddoc.php on line 22

I emailed support (Namesco) and received this reply
>>There is no need to change permissions on Windows hosting. Your files by
default have the permissions to write to directories owned by your own
user.

Any suggestions?
They don't have any idea what they're talking about? You may be able to
write to them as your user - but you need to be able to write them them
as the web server's user. Completely separate requirements.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 2 '07 #7
Message-ID: <wt******************************@comcast.comfro m Jerry
Stuckle contained the following:
>Any suggestions?

They don't have any idea what they're talking about? You may be able to
write to them as your user - but you need to be able to write them them
as the web server's user. Completely separate requirements.
Thanks Jerry, I suspected I was being fobbed off and told them so.

An equally unhelpful reply followed:-

"Dear customer,

The script might work elsewhere, but that is on a different server with
a different configuration. We will not assist you with troubleshooting
your scripts. You will need to establish the cause of the problem
yourself and resolve it accordingly. "

Perhaps they just don't want the business?
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jun 2 '07 #8
Try www.technetcenter.com - they aren't perfect, but they are very
helpful and the hosting packages are really great.

T

Geoff Berrow wrote:
Message-ID: <wt******************************@comcast.comfro m Jerry
Stuckle contained the following:
>>Any suggestions?
They don't have any idea what they're talking about? You may be able to
write to them as your user - but you need to be able to write them them
as the web server's user. Completely separate requirements.

Thanks Jerry, I suspected I was being fobbed off and told them so.

An equally unhelpful reply followed:-

"Dear customer,

The script might work elsewhere, but that is on a different server with
a different configuration. We will not assist you with troubleshooting
your scripts. You will need to establish the cause of the problem
yourself and resolve it accordingly. "

Perhaps they just don't want the business?

Jun 2 '07 #9
Geoff Berrow wrote:
Message-ID: <wt******************************@comcast.comfro m Jerry
Stuckle contained the following:
>>Any suggestions?
They don't have any idea what they're talking about? You may be able to
write to them as your user - but you need to be able to write them them
as the web server's user. Completely separate requirements.

Thanks Jerry, I suspected I was being fobbed off and told them so.

An equally unhelpful reply followed:-

"Dear customer,

The script might work elsewhere, but that is on a different server with
a different configuration. We will not assist you with troubleshooting
your scripts. You will need to establish the cause of the problem
yourself and resolve it accordingly. "

Perhaps they just don't want the business?

It sure looks like it. I'd write them back and tell them that since
they can't configure their servers properly and don't even want to know
they have a problem, you're moving to another hosting company.

And then I'd go to www.webhostingtalk.com and let people know about this
company (including name). We don't need any more incompetent, uncaring
hosting companies.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 2 '07 #10
Message-ID: <MM******************@bignews3.bellsouth.netfrom tomb
contained the following:
>Try www.technetcenter.com - they aren't perfect, but they are very
helpful and the hosting packages are really great.
Changing to a more helpful host is probably the best idea but it's not
really an option at the moment.
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jun 2 '07 #11
Geoff Berrow wrote:
Message-ID: <MM******************@bignews3.bellsouth.netfrom tomb
contained the following:
>Try www.technetcenter.com - they aren't perfect, but they are very
helpful and the hosting packages are really great.

Changing to a more helpful host is probably the best idea but it's not
really an option at the moment.
Changing hosts is *always* an option.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 2 '07 #12
At Sat, 02 Jun 2007 10:57:13 +0100, Geoff Berrow let h(is|er) monkeys
type:
Message-ID: <wt******************************@comcast.comfro m Jerry
Stuckle contained the following:
>>Any suggestions?
Thanks Jerry, I suspected I was being fobbed off and told them so.

An equally unhelpful reply followed:-

"Dear customer,

The script might work elsewhere, but that is on a different server with
a different configuration. We will not assist you with troubleshooting
your scripts. You will need to establish the cause of the problem
yourself and resolve it accordingly. "
Aha, the typical "Not my problem" approach. Goes hand in hand with "We
don't make any mistakes. Your fault". Change hosts. ASAP. Waste of money &
energy. And tell them why you leave. And make sure you tell everyone about
this utterly poor service. Take your losses, and if they sold you a
product including service, just don't pay for what they don't deliver.

Good luck.
--
Schraalhans Keukenmeester - sc*********@the.Spamtrapexample.nl
[Remove the lowercase part of Spamtrap to send me a message]

"strcmp('apples','oranges') < 0"

Jun 2 '07 #13
Geoff Berrow kirjoitti:
I have an upload script which I want to use to upload word documents.
This works fine on my Gradwell account. However on the client's
(windows) hosting it fails.

C:\WINDOWS\TEMP\php29D.tmp
Warning: copy(papers/1180718015test.doc) [function.copy]: failed to open
stream: Permission denied in
\\nas01\nas\i\s\isbe2007.org\web\uploaddoc.php on line 22

I emailed support (Namesco) and received this reply
>>There is no need to change permissions on Windows hosting. Your files by
default have the permissions to write to directories owned by your own
user.

Any suggestions?
Did you try move_uploaded_file() instead of copy()? If the host has
configured php to safe mode, this might make a difference.

It also might be that the host company are wankers who don't know their
heads from their asses, but the basic thing is that when you handle
uploaded files, you should always use move_uploaded_file() instead of
copy, and it's worth testing at least.

--
Ra*********@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
Jun 2 '07 #14
Message-ID: <x4******************************@comcast.comfro m Jerry
Stuckle contained the following:
>Changing to a more helpful host is probably the best idea but it's not
really an option at the moment.

Changing hosts is *always* an option.
It may come to that but the possible disruption would not be welcome at
the moment as the site is in active use.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jun 2 '07 #15
Geoff Berrow wrote:
Message-ID: <x4******************************@comcast.comfro m Jerry
Stuckle contained the following:
>>Changing to a more helpful host is probably the best idea but it's not
really an option at the moment.
Changing hosts is *always* an option.

It may come to that but the possible disruption would not be welcome at
the moment as the site is in active use.
And when will it never be "in active use"? Once a site is exposed to
the internet, it's ALWAYS considered active.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 3 '07 #16
Message-ID: <a7***************************@news.speedlinq.nlfr om
Schraalhans Keukenmeester contained the following:
>The script might work elsewhere, but that is on a different server with
a different configuration. We will not assist you with troubleshooting
your scripts. You will need to establish the cause of the problem
yourself and resolve it accordingly. "

Aha, the typical "Not my problem" approach. Goes hand in hand with "We
don't make any mistakes. Your fault". Change hosts. ASAP. Waste of money &
energy. And tell them why you leave. And make sure you tell everyone about
this utterly poor service. Take your losses, and if they sold you a
product including service, just don't pay for what they don't deliver.
I've had an apology and personal phone call from a senior developer.
They are blaming on 'a bug in FrontPage that causes it to remove the
permissions required for uploading from a script when it is installed'.

In addition we are also moving the site to Linux hosting as soon as
possible.

So, a result. Thanks for all your help and support guys.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jun 4 '07 #17

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

Similar topics

2
by: Mountain Man | last post by:
Hi, I'm having trouble with the foreach function. I'm using it twice inside a user defined function with two different arrays, and in the second instance it's returning the value of the first...
3
by: pmud | last post by:
Hi, I have 4 columns in my sql database table. I added a data adapter , data set & a data grid to view this information. But the data grid is displaying those 4 columns TWICE , i.e in the data...
7
by: Phil | last post by:
Hi, I read somewhere that the new version (v1.1) has improved the performance of 'foreach' over 'for'. Is that true? I did some measurements and I still think for has an upperhand... ? Phil
104
by: cody | last post by:
What about an enhancement of foreach loops which allows a syntax like that: foeach(int i in 1..10) { } // forward foeach(int i in 99..2) { } // backwards foeach(char c in 'a'..'z') { } // chars...
2
by: RAJ | last post by:
In our multi-tier application, we have several ASP.NET user controls which will update the same data source provided by middle tier logic. In this particular scenario we have one user control...
4
by: Jack | last post by:
Hi, I have the following Access DDL statment from which I generated a access table: CREATE TABLE TEST1 (ID COUNTER, NAME TEXT(50), STORAGESPACEASSIGNED TEXT(50) )
3
by: monomaniac21 | last post by:
//this loop doesnt work as intended, each row displays twice, once with a number as $key and again with key name as $key!? Any ideas why? $result = mysql_query("SELECT * FROM tbl WHERE id =...
0
by: arunpulikkan | last post by:
hi,guys im new to asp.in my option list one value is displaying twice.following is the code if not rs1.eof then thispagesForm = rs1(0) sql2 = "select formname, local_url from...
4
by: Peter Morris | last post by:
I am not sure what you are asking. You seem to be asking how to implement a plain IEnumerable on a composite structure, but then your example shows a flat structure using "yield". Your subject...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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...

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.