Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #11821 > unrolled thread
| Started by | richard <noreply@example.com> |
|---|---|
| First post | 2013-11-18 09:10 -0500 |
| Last post | 2013-11-20 16:02 +0100 |
| Articles | 20 on this page of 30 — 14 participants |
Back to article view | Back to comp.lang.php
array search part 2 richard <noreply@example.com> - 2013-11-18 09:10 -0500
Re: array search part 2 Christoph Michael Becker <cmbecker69@arcor.de> - 2013-11-18 15:32 +0100
Re: array search part 2 richard <noreply@example.com> - 2013-11-18 09:59 -0500
Re: array search part 2 richard <noreply@example.com> - 2013-11-18 09:31 -0500
Re: array search part 2 Tim Streater <timstreater@greenbee.net> - 2013-11-18 15:05 +0000
Re: array search part 2 richard <noreply@example.com> - 2013-11-18 11:06 -0500
Re: array search part 2 Christoph Michael Becker <cmbecker69@arcor.de> - 2013-11-18 17:17 +0100
Re: array search part 2 "Peter H. Coffin" <hellsop@ninehells.com> - 2013-11-18 11:08 -0600
Re: array search part 2 Doug Miller <doug_at_milmac_dot_com@example.com> - 2013-11-19 03:11 +0000
Re: array search part 2 Arno Welzel <usenet@arnowelzel.de> - 2013-11-19 09:27 +0100
Re: array search part 2 Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-18 13:08 -0500
Re: array search part 2 richard <noreply@example.com> - 2013-11-18 11:11 -0500
Re: array search part 2 "J.O. Aho" <user@example.net> - 2013-11-18 19:10 +0100
Re: array search part 2 Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-18 18:28 +0000
Re: array search part 2 "J.O. Aho" <user@example.net> - 2013-11-18 20:03 +0100
solved (was: array search part 2) richard <noreply@example.com> - 2013-11-18 21:45 -0500
Re: solved Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-19 13:50 +0000
Re: solved Scott Johnson <noonehome@chalupasworld.com> - 2013-11-19 06:16 -0800
Re: solved Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-19 16:29 +0000
Re: solved Scott Johnson <noonehome@chalupasworld.com> - 2013-11-19 10:57 -0800
Re: solved tony@mountifield.org (Tony Mountifield) - 2013-11-19 14:48 +0000
Re: solved Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-19 16:12 +0100
Re: solved Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-19 16:25 +0000
Re: solved richard <noreply@example.com> - 2013-11-19 11:51 -0500
Re: solved Christoph Michael Becker <cmbecker69@arcor.de> - 2013-11-19 18:31 +0100
Re: solved Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-19 18:15 +0000
Re: solved Arno Welzel <usenet@arnowelzel.de> - 2013-11-19 17:43 +0100
Re: solved richard <noreply@example.com> - 2013-11-19 14:41 -0500
Re: solved "Beauregard T. Shagnasty" <a.nony.mous@example.invalid> - 2013-11-19 19:52 +0000
Re: solved Arno Welzel <usenet@arnowelzel.de> - 2013-11-20 16:02 +0100
Page 1 of 2 [1] 2 Next page →
| From | richard <noreply@example.com> |
|---|---|
| Date | 2013-11-18 09:10 -0500 |
| Subject | array search part 2 |
| Message-ID | <93xuovoqvo59.1wcgm8i5gn2hb$.dlg@40tude.net> |
I am attempting to search the array for matching entries.
All matches, not just the first.
While the code works fine, the result is not what I want.
$btrack should return the value of six0[$track][0].
Instead, the result shows the array key number.
Even if I change the [0] to [1].
Why?
<?php
$track=$_GET['item'];
echo $track;
$flip=$six0[$track][1];
echo $flip;
echo "<br>";
$max=count($six0);
$arow=0;
while ($max>$arow){
$btrack=$six0[$arow][0];
if ($btrack=$track){echo $btrack;}
$arow++;
}
?>
Result example.
468The Happy Heart Of Paris
468468468468468468468468468468468468468............
[toc] | [next] | [standalone]
| From | Christoph Michael Becker <cmbecker69@arcor.de> |
|---|---|
| Date | 2013-11-18 15:32 +0100 |
| Message-ID | <528a2504$0$6558$9b4e6d93@newsspool4.arcor-online.net> |
| In reply to | #11821 |
richard wrote:
> if ($btrack=$track){echo $btrack;}
^
You may consider using a "linter".
--
Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | richard <noreply@example.com> |
|---|---|
| Date | 2013-11-18 09:59 -0500 |
| Message-ID | <1v4b6ozwbgeol$.x8nffb8psrm6$.dlg@40tude.net> |
| In reply to | #11822 |
On Mon, 18 Nov 2013 15:32:38 +0100, Christoph Michael Becker wrote:
> richard wrote:
>
>> if ($btrack=$track){echo $btrack;}
> ^
>
> You may consider using a "linter".
I changed $btrack to $bsong and still got the same result.
= or == made no difference.
[toc] | [prev] | [next] | [standalone]
| From | richard <noreply@example.com> |
|---|---|
| Date | 2013-11-18 09:31 -0500 |
| Message-ID | <1yop93z6n110$.187m5wx5zdr4q$.dlg@40tude.net> |
| In reply to | #11821 |
I realized I was searching for the wrong item. That is why $track was producing the number instead of the string. Now it works a little better.
[toc] | [prev] | [next] | [standalone]
| From | Tim Streater <timstreater@greenbee.net> |
|---|---|
| Date | 2013-11-18 15:05 +0000 |
| Message-ID | <181120131505521953%timstreater@greenbee.net> |
| In reply to | #11821 |
In article <93xuovoqvo59.1wcgm8i5gn2hb$.dlg@40tude.net>, richard
<noreply@example.com> wrote:
> I am attempting to search the array for matching entries.
> All matches, not just the first.
> While the code works fine, the result is not what I want.
> $btrack should return the value of six0[$track][0].
> Instead, the result shows the array key number.
> Even if I change the [0] to [1].
> Why?
For the 17 billionth time, you thick dope, you have used = instead of ==
> <?php
>
> $track=$_GET['item'];
> echo $track;
>
> $flip=$six0[$track][1];
> echo $flip;
> echo "<br>";
>
> $max=count($six0);
>
> $arow=0;
>
> while ($max>$arow){
>
> $btrack=$six0[$arow][0];
> if ($btrack=$track){echo $btrack;}
> $arow++;
> }
>
>
> ?>
--
Tim
"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
[toc] | [prev] | [next] | [standalone]
| From | richard <noreply@example.com> |
|---|---|
| Date | 2013-11-18 11:06 -0500 |
| Message-ID | <1effhia2fnbeo$.1ts7of1q9m0f7.dlg@40tude.net> |
| In reply to | #11826 |
On Mon, 18 Nov 2013 15:05:52 +0000, Tim Streater wrote:
> In article <93xuovoqvo59.1wcgm8i5gn2hb$.dlg@40tude.net>, richard
> <noreply@example.com> wrote:
>
>> I am attempting to search the array for matching entries.
>> All matches, not just the first.
>> While the code works fine, the result is not what I want.
>> $btrack should return the value of six0[$track][0].
>> Instead, the result shows the array key number.
>> Even if I change the [0] to [1].
>> Why?
>
> For the 17 billionth time, you thick dope, you have used = instead of ==
>
>> <?php
>>
>> $track=$_GET['item'];
>> echo $track;
>>
>> $flip=$six0[$track][1];
>> echo $flip;
>> echo "<br>";
>>
>> $max=count($six0);
>>
>> $arow=0;
>>
>> while ($max>$arow){
>>
>> $btrack=$six0[$arow][0];
>> if ($btrack=$track){echo $btrack;}
>> $arow++;
>> }
>>
>>
>> ?>
You thicker DOPE! IT MAKES NO FRICKIN DIFFERENCE!
And the examples I have seen at php.net all use a single =.
[toc] | [prev] | [next] | [standalone]
| From | Christoph Michael Becker <cmbecker69@arcor.de> |
|---|---|
| Date | 2013-11-18 17:17 +0100 |
| Message-ID | <528a3d9a$0$6556$9b4e6d93@newsspool4.arcor-online.net> |
| In reply to | #11829 |
richard wrote: > You thicker DOPE! IT MAKES NO FRICKIN DIFFERENCE! > And the examples I have seen at php.net all use a single =. Generally, there is a big difference between an assignment (=) and a equality comparison (==). A programmer should know, when to use which. -- Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | "Peter H. Coffin" <hellsop@ninehells.com> |
|---|---|
| Date | 2013-11-18 11:08 -0600 |
| Message-ID | <slrnl8kicr.qs6.hellsop@nibelheim.ninehells.com> |
| In reply to | #11829 |
On Mon, 18 Nov 2013 11:06:52 -0500, richard wrote: > You thicker DOPE! IT MAKES NO FRICKIN DIFFERENCE! > And the examples I have seen at php.net all use a single =. It only doesn't make a difference when some other problem when some other problem is *also* chewing on your butt. Just because it doesn't yell "+++ OUT OF CHEESE ERROR % REDO FROM START" doesn't mean its not a problem. -- 186,000 Miles per Second. It's not just a good idea. IT'S THE LAW.
[toc] | [prev] | [next] | [standalone]
| From | Doug Miller <doug_at_milmac_dot_com@example.com> |
|---|---|
| Date | 2013-11-19 03:11 +0000 |
| Message-ID | <XnsA27CE1C9C55F0dougmilmaccom@78.46.70.116> |
| In reply to | #11829 |
richard <noreply@example.com> wrote in news:1effhia2fnbeo$.1ts7of1q9m0f7.dlg@
40tude.net:
> You thicker DOPE! IT MAKES NO FRICKIN DIFFERENCE!
Yes, it does. The reason that it *appears* to you that it doesn't is that in this case, you have
*another* error in addition to this one, which prevents your code from working until you have
corrected *both* errors.
> And the examples I have seen at php.net all use a single =.
Post the URLs of a couple of these examples.
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2013-11-19 09:27 +0100 |
| Message-ID | <528B210F.10106@arnowelzel.de> |
| In reply to | #11829 |
richard, 2013-11-18 17:06:
> On Mon, 18 Nov 2013 15:05:52 +0000, Tim Streater wrote:
>
>> In article <93xuovoqvo59.1wcgm8i5gn2hb$.dlg@40tude.net>, richard
>> <noreply@example.com> wrote:
>>
>>> I am attempting to search the array for matching entries.
>>> All matches, not just the first.
>>> While the code works fine, the result is not what I want.
>>> $btrack should return the value of six0[$track][0].
>>> Instead, the result shows the array key number.
>>> Even if I change the [0] to [1].
>>> Why?
>>
>> For the 17 billionth time, you thick dope, you have used = instead of ==
>>
[...]
>>> $btrack=$six0[$arow][0];
>>> if ($btrack=$track){echo $btrack;}
>>> $arow++;
>>> }
>>>
>>>
>>> ?>
>
> You thicker DOPE! IT MAKES NO FRICKIN DIFFERENCE!
> And the examples I have seen at php.net all use a single =.
The examples DO NOT MATTER!
Read THIS:
<http://us3.php.net/manual/en/language.operators.php>
--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2013-11-18 13:08 -0500 |
| Message-ID | <l6dl2u$3i2$1@dont-email.me> |
| In reply to | #11826 |
On 11/18/2013 10:05 AM, Tim Streater wrote: > In article <93xuovoqvo59.1wcgm8i5gn2hb$.dlg@40tude.net>, richard > <noreply@example.com> wrote: > >> I am attempting to search the array for matching entries. >> All matches, not just the first. >> While the code works fine, the result is not what I want. >> $btrack should return the value of six0[$track][0]. >> Instead, the result shows the array key number. >> Even if I change the [0] to [1]. >> Why? > > For the 17 billionth time, you thick dope, you have used = instead of == > A bit of an exaggeration, Tim. It's only been 16,364,196,273 times. :) -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | richard <noreply@example.com> |
|---|---|
| Date | 2013-11-18 11:11 -0500 |
| Message-ID | <1shntpb6vcf5h.krh15ofjwrfm$.dlg@40tude.net> |
| In reply to | #11821 |
<?php
$track=$_GET['item'];
echo $track;
$asong=$six0[$track][0];
$flip=$six0[$track][1];
echo $flip;
echo "<br>";
$max=count($six0);
echo $max;
echo "<br>";
for ($item=0;$item<=$max;$item++)
{if ($flip==$six0[$item][0]){echo $six0[$item][0]."</br>";}}
?>
This method works, but stops searching when a match has been found.
Is there a way to continue the search when a match has been found?
There are times when songs are liste 2 or more times and with different
artists. So I need to find them all and then recover the one that matches
to the original track.
[toc] | [prev] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2013-11-18 19:10 +0100 |
| Message-ID | <bev3h1F34g9U1@mid.individual.net> |
| In reply to | #11830 |
On 18/11/13 17:11, richard wrote:
> <?php
>
> $track=$_GET['item'];
> echo $track;
>
> $asong=$six0[$track][0];
> $flip=$six0[$track][1];
> echo $flip;
> echo "<br>";
>
> $max=count($six0);
> echo $max;
> echo "<br>";
>
> for ($item=0;$item<=$max;$item++)
> {if ($flip==$six0[$item][0]){echo $six0[$item][0]."</br>";}}
>
> ?>
>
> This method works, but stops searching when a match has been found.
> Is there a way to continue the search when a match has been found?
> There are times when songs are liste 2 or more times and with different
> artists. So I need to find them all and then recover the one that matches
> to the original track.
>
It dosen't stop after finding one match, you have only one match.
Please indent your code better, makes it easier to read and a lot easier
for you to spot errors.
--
//Aho
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2013-11-18 18:28 +0000 |
| Message-ID | <l6dm7j$5ba$5@dont-email.me> |
| In reply to | #11842 |
On Mon, 18 Nov 2013 19:10:41 +0100, J.O. Aho wrote: > It dosen't stop after finding one match, you have only one match. Please > indent your code better, makes it easier to read and a lot easier for > you to spot errors. Objection m'lud. He couldn't spot an error in his code if it had a flashing neon sign pointing at it. -- Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2013-11-18 20:03 +0100 |
| Message-ID | <bev6kmF3s95U1@mid.individual.net> |
| In reply to | #11846 |
On 18/11/13 19:28, Denis McMahon wrote: > On Mon, 18 Nov 2013 19:10:41 +0100, J.O. Aho wrote: > >> It dosen't stop after finding one match, you have only one match. Please >> indent your code better, makes it easier to read and a lot easier for >> you to spot errors. > > Objection m'lud. He couldn't spot an error in his code if it had a > flashing neon sign pointing at it. I have to admit you are right about that. -- //Aho
[toc] | [prev] | [next] | [standalone]
| From | richard <noreply@example.com> |
|---|---|
| Date | 2013-11-18 21:45 -0500 |
| Subject | solved (was: array search part 2) |
| Message-ID | <1939vbqgxpb1.1ed40enyqnzu1$.dlg@40tude.net> |
| In reply to | #11821 |
<?php
$track=$_GET['item'];
$asong=$six0[$track][0];
$flip=$six0[$track][1];
$max=count($six0);
$match=0;
for ($item=0;$item<=$max;$item++){
if ($flip==$six0[$item]['0'])
{if ($six0[$item][2]=$six0[$track][2])
{$match=$item;}}
}
http://mroldies.net/list/decade60.html
The for loop searches through the array for a match first based on name.
Then further matches by label number.
[0]=charted name
[1]=flipside
[2]=label
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2013-11-19 13:50 +0000 |
| Subject | Re: solved |
| Message-ID | <0.7dbacdb97db2593ac9fc.20131119135002GMT.87bo1gpkl1.fsf@bsb.me.uk> |
| In reply to | #11848 |
richard <noreply@example.com> writes:
> <?php
>
> $track=$_GET['item'];
>
>
> $asong=$six0[$track][0];
> $flip=$six0[$track][1];
>
> $max=count($six0);
>
> $match=0;
>
> for ($item=0;$item<=$max;$item++){
> if ($flip==$six0[$item]['0'])
> {if ($six0[$item][2]=$six0[$track][2])
There's no need to assign something to itself just to test it. The
test:
if ($six0[$item][2]) ...
is probably what you want, though the assignment will create
$six0[$item][2] if it does not already exist, so the two are not exactly
the same.
> {$match=$item;}}
> }
>
> http://mroldies.net/list/decade60.html
>
> The for loop searches through the array for a match first based on name.
> Then further matches by label number.
> [0]=charted name
> [1]=flipside
> [2]=label
You can make the code more self-documenting by using defined constants
for these indexes:
define('FLIPSIDE', 1);
define('LABEL', 2);
...
if ($six0[$item][LABEL]) ...
or by using string indexes directly (e.g. if ($six0[$item]['label']) ...).
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | Scott Johnson <noonehome@chalupasworld.com> |
|---|---|
| Date | 2013-11-19 06:16 -0800 |
| Subject | Re: solved |
| Message-ID | <l6frsl$ji5$1@dont-email.me> |
| In reply to | #11859 |
On 11/19/2013 5:50 AM, Ben Bacarisse wrote:
> richard <noreply@example.com> writes:
<snip>
>> {if ($six0[$item][2]=$six0[$track][2])
<snip>
>> {$match=$item;}}
>> }
>>
>> http://mroldies.net/list/decade60.html
>>
>> The for loop searches through the array for a match first based on name.
>> Then further matches by label number.
>> [0]=charted name
>> [1]=flipside
>> [2]=label
>
> You can make the code more self-documenting by using defined constants
> for these indexes:
>
> define('FLIPSIDE', 1);
> define('LABEL', 2);
> ...
> if ($six0[$item][LABEL]) ...
>
> or by using string indexes directly (e.g. if ($six0[$item]['label']) ...).
>
Hello Ben.
Most around here are still trying to get Richard to understand and
implement the difference between 'assignment' and 'comparison'.
Now you are bringing in another level of discipline.
The next thing you will be asking is for him to proof read his code when
he has errors prior to bringing them here.
But I have to admit it does give me some humorous light reading at times.
Scotty
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2013-11-19 16:29 +0000 |
| Subject | Re: solved |
| Message-ID | <0.067c915374fed56a99df.20131119162903GMT.87fvqsnynk.fsf@bsb.me.uk> |
| In reply to | #11860 |
Scott Johnson <noonehome@chalupasworld.com> writes: <snip> > Most around here are still trying to get Richard to understand and > implement the difference between 'assignment' and 'comparison'. I try not to post to the poster if you see what I mean. The post reminded me of a way to make things clearer, and I fondly hope that it might help others who just lurk here, or who see these things in search results. <snip> -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | Scott Johnson <noonehome@chalupasworld.com> |
|---|---|
| Date | 2013-11-19 10:57 -0800 |
| Subject | Re: solved |
| Message-ID | <l6gcc3$qtq$1@dont-email.me> |
| In reply to | #11864 |
On 11/19/2013 8:29 AM, Ben Bacarisse wrote: > Scott Johnson <noonehome@chalupasworld.com> writes: > <snip> >> Most around here are still trying to get Richard to understand and >> implement the difference between 'assignment' and 'comparison'. > > I try not to post to the poster if you see what I mean. The post > reminded me of a way to make things clearer, and I fondly hope that it > might help others who just lurk here, or who see these things in search > results. > > <snip> > Agreed. I was just being facetious. Scotty
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.php
csiph-web