FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » array search part 2
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
array search part 2 [message #183752] Mon, 18 November 2013 14:10 Go to next message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma: 0
Senior Member
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............
Re: array search part 2 [message #183753 is a reply to message #183752] Mon, 18 November 2013 14:32 Go to previous messageGo to next message
Christoph Michael Bec is currently offline  Christoph Michael Bec
Messages: 207
Registered: June 2013
Karma: 0
Senior Member
richard wrote:

> if ($btrack=$track){echo $btrack;}
^

You may consider using a "linter".

--
Christoph M. Becker
Re: array search part 2 [message #183754 is a reply to message #183752] Mon, 18 November 2013 14:31 Go to previous messageGo to next message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma: 0
Senior Member
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.
Re: array search part 2 [message #183756 is a reply to message #183753] Mon, 18 November 2013 14:59 Go to previous messageGo to next message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma: 0
Senior Member
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.
Re: array search part 2 [message #183757 is a reply to message #183752] Mon, 18 November 2013 15:05 Go to previous messageGo to next message
Tim Streater is currently offline  Tim Streater
Messages: 328
Registered: September 2010
Karma: 0
Senior Member
In article <93xuovoqvo59(dot)1wcgm8i5gn2hb$(dot)dlg(at)40tude(dot)net>, richard
<noreply(at)example(dot)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
Re: array search part 2 [message #183760 is a reply to message #183757] Mon, 18 November 2013 16:06 Go to previous messageGo to next message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma: 0
Senior Member
On Mon, 18 Nov 2013 15:05:52 +0000, Tim Streater wrote:

> In article <93xuovoqvo59(dot)1wcgm8i5gn2hb$(dot)dlg(at)40tude(dot)net>, richard
> <noreply(at)example(dot)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 =.
Re: array search part 2 [message #183761 is a reply to message #183752] Mon, 18 November 2013 16:11 Go to previous messageGo to next message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma: 0
Senior Member
<?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.
Re: array search part 2 [message #183762 is a reply to message #183760] Mon, 18 November 2013 16:17 Go to previous messageGo to next message
Christoph Michael Bec is currently offline  Christoph Michael Bec
Messages: 207
Registered: June 2013
Karma: 0
Senior Member
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
Re: array search part 2 [message #183771 is a reply to message #183760] Mon, 18 November 2013 17:08 Go to previous messageGo to next message
Peter H. Coffin is currently offline  Peter H. Coffin
Messages: 245
Registered: September 2010
Karma: 0
Senior Member
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.
Re: array search part 2 [message #183772 is a reply to message #183757] Mon, 18 November 2013 18:08 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 11/18/2013 10:05 AM, Tim Streater wrote:
> In article <93xuovoqvo59(dot)1wcgm8i5gn2hb$(dot)dlg(at)40tude(dot)net>, richard
> <noreply(at)example(dot)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(at)attglobal(dot)net
==================
Re: array search part 2 [message #183773 is a reply to message #183761] Mon, 18 November 2013 18:10 Go to previous messageGo to next message
J.O. Aho is currently offline  J.O. Aho
Messages: 194
Registered: September 2010
Karma: 0
Senior Member
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
Re: array search part 2 [message #183777 is a reply to message #183773] Mon, 18 November 2013 18:28 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
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(at)gmail(dot)com
Re: array search part 2 [message #183778 is a reply to message #183777] Mon, 18 November 2013 19:03 Go to previous messageGo to next message
J.O. Aho is currently offline  J.O. Aho
Messages: 194
Registered: September 2010
Karma: 0
Senior Member
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
solved (was: array search part 2) [message #183780 is a reply to message #183752] Tue, 19 November 2013 02:45 Go to previous messageGo to next message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma: 0
Senior Member
<?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
Re: array search part 2 [message #183781 is a reply to message #183760] Tue, 19 November 2013 03:11 Go to previous messageGo to next message
Doug Miller is currently offline  Doug Miller
Messages: 171
Registered: August 2011
Karma: 0
Senior Member
richard <noreply(at)example(dot)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.
Re: array search part 2 [message #183784 is a reply to message #183760] Tue, 19 November 2013 08:27 Go to previous messageGo to next message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma: 0
Senior Member
richard, 2013-11-18 17:06:

> On Mon, 18 Nov 2013 15:05:52 +0000, Tim Streater wrote:
>
>> In article <93xuovoqvo59(dot)1wcgm8i5gn2hb$(dot)dlg(at)40tude(dot)net>, richard
>> <noreply(at)example(dot)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
Re: solved [message #183785 is a reply to message #183780] Tue, 19 November 2013 13:50 Go to previous messageGo to next message
Ben Bacarisse is currently offline  Ben Bacarisse
Messages: 82
Registered: November 2013
Karma: 0
Member
richard <noreply(at)example(dot)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.
Re: solved [message #183786 is a reply to message #183785] Tue, 19 November 2013 14:16 Go to previous messageGo to next message
Scott Johnson is currently offline  Scott Johnson
Messages: 196
Registered: January 2012
Karma: 0
Senior Member
On 11/19/2013 5:50 AM, Ben Bacarisse wrote:
> richard <noreply(at)example(dot)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
Re: solved [message #183787 is a reply to message #183785] Tue, 19 November 2013 14:48 Go to previous messageGo to next message
tony is currently offline  tony
Messages: 19
Registered: December 2010
Karma: 0
Junior Member
In article <0(dot)7dbacdb97db2593ac9fc(dot)20131119135002GMT(dot)87bo1gpkl1(dot)fsf(at)bsb(dot)me(dot)uk>,
Ben Bacarisse <ben(dot)usenet(at)bsb(dot)me(dot)uk> wrote:
> richard <noreply(at)example(dot)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.

It's not being assigned to itself. The destination is indexed by $item
and the source is indexed by $track.

Cheers
Tony
--
Tony Mountifield
Work: tony(at)softins(dot)co(dot)uk - http://www.softins.co.uk
Play: tony(at)mountifield(dot)org - http://tony.mountifield.org
Re: solved [message #183788 is a reply to message #183787] Tue, 19 November 2013 15:12 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Tony Mountifield wrote:

> Ben Bacarisse <ben(dot)usenet(at)bsb(dot)me(dot)uk> wrote:
>> richard <noreply(at)example(dot)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.
>
> It's not being assigned to itself. The destination is indexed by $item
> and the source is indexed by $track.

It is still richard^Wnonsense.


PointedEars
--
When all you know is jQuery, every problem looks $(olvable).
Re: solved [message #183789 is a reply to message #183787] Tue, 19 November 2013 16:25 Go to previous messageGo to next message
Ben Bacarisse is currently offline  Ben Bacarisse
Messages: 82
Registered: November 2013
Karma: 0
Member
tony(at)mountifield(dot)org (Tony Mountifield) writes:

> In article <0(dot)7dbacdb97db2593ac9fc(dot)20131119135002GMT(dot)87bo1gpkl1(dot)fsf(at)bsb(dot)me(dot)uk>,
> Ben Bacarisse <ben(dot)usenet(at)bsb(dot)me(dot)uk> wrote:
>> richard <noreply(at)example(dot)com> writes:
<snip>
>>> 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.
>
> It's not being assigned to itself. The destination is indexed by $item
> and the source is indexed by $track.

Good spot, thanks. I wonder if that was intended. Probably not.

--
Ben.
Re: solved [message #183790 is a reply to message #183786] Tue, 19 November 2013 16:29 Go to previous messageGo to next message
Ben Bacarisse is currently offline  Ben Bacarisse
Messages: 82
Registered: November 2013
Karma: 0
Member
Scott Johnson <noonehome(at)chalupasworld(dot)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.
Re: solved [message #183791 is a reply to message #183780] Tue, 19 November 2013 16:43 Go to previous messageGo to next message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma: 0
Senior Member
Am 19.11.2013 03:45, schrieb richard:
> <?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;}}
> }

PLEASE format your code properly!

for($item=0; $item <= $max; $item++)
{
if($flip == $six0[$item]['0'])
{
if($six0[$item][2] = $six0[$track][2])
{
$match = $item;
}
}
}

And why this?

if($six0[$item][2] = $six0[$track][2])

Please note: "=" is NOT the same as "=="!

If you want to COMPARE $six0[$item][2] and $six0[$track][2] you MUST write:

if($six0[$item][2] == $six0[$track][2])



--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
Re: solved [message #183792 is a reply to message #183785] Tue, 19 November 2013 16:51 Go to previous messageGo to next message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma: 0
Senior Member
On Tue, 19 Nov 2013 13:50:02 +0000, Ben Bacarisse wrote:

> richard <noreply(at)example(dot)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 you'd bother to comprehend what is happening, it is not assigning
itself.
$item is the value derived from the loop.
$track is the fixed valued assigned at the time of $_GET.
so if $item and $track are equal then the statement is true and the result
assigns the value to $match and that is what is used to display the proper
item.

If $track=1 and $item=101 and the pairs match in value, then $match gets
the number to use.
Re: solved [message #183793 is a reply to message #183792] Tue, 19 November 2013 17:31 Go to previous messageGo to next message
Christoph Michael Bec is currently offline  Christoph Michael Bec
Messages: 207
Registered: June 2013
Karma: 0
Senior Member
richard wrote:

> On Tue, 19 Nov 2013 13:50:02 +0000, Ben Bacarisse wrote:
>
>> richard <noreply(at)example(dot)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 you'd bother to comprehend what is happening, it is not assigning
> itself.
> $item is the value derived from the loop.
> $track is the fixed valued assigned at the time of $_GET.
> so if $item and $track are equal then the statement is true

No. The _expression_ evaluates to true, if $six[0][$track][2] evaluates
to true. *Please*, note the difference between assignment and comparison.

> and the result
> assigns the value to $match and that is what is used to display the proper
> item.
>
> If $track=1 and $item=101 and the pairs match in value, then $match gets
> the number to use.

--
Christoph M. Becker
Re: solved [message #183794 is a reply to message #183792] Tue, 19 November 2013 18:15 Go to previous messageGo to next message
Ben Bacarisse is currently offline  Ben Bacarisse
Messages: 82
Registered: November 2013
Karma: 0
Member
richard <noreply(at)example(dot)com> writes:

> On Tue, 19 Nov 2013 13:50:02 +0000, Ben Bacarisse wrote:
>
>> richard <noreply(at)example(dot)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 you'd bother to comprehend what is happening, it is not assigning
> itself.

Clam down. I miss-read the line, it's not a question of not bothering.

> $item is the value derived from the loop.
> $track is the fixed valued assigned at the time of $_GET.
> so if $item and $track are equal then the statement is true and the result
> assigns the value to $match and that is what is used to display the proper
> item.

No, that's not what happens. The condition is true if and only if
$six0[$track][2] is considered to be true (i.e. not null, false, 0, 0.0,
"", "0", array() or an empty object).

As a side effect, one or more elements of $six0 have their [2] component
set to $six0[$track][2] depending on exactly what data there is in the
array.

Two other points: (1) you access outside the array but running the loop up
to and including $max, and (2) using '0' when you mean 0 is confusing.
It works, but it's not as clear as it should be.

> If $track=1 and $item=101 and the pairs match in value, then $match gets
> the number to use.

--
Ben.
Re: solved [message #183795 is a reply to message #183790] Tue, 19 November 2013 18:57 Go to previous messageGo to next message
Scott Johnson is currently offline  Scott Johnson
Messages: 196
Registered: January 2012
Karma: 0
Senior Member
On 11/19/2013 8:29 AM, Ben Bacarisse wrote:
> Scott Johnson <noonehome(at)chalupasworld(dot)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
Re: solved [message #183796 is a reply to message #183791] Tue, 19 November 2013 19:41 Go to previous messageGo to next message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma: 0
Senior Member
On Tue, 19 Nov 2013 17:43:25 +0100, Arno Welzel wrote:

> Am 19.11.2013 03:45, schrieb richard:
>> <?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;}}
>> }
>
> PLEASE format your code properly!
>
> for($item=0; $item <= $max; $item++)
> {
> if($flip == $six0[$item]['0'])
> {
> if($six0[$item][2] = $six0[$track][2])
> {
> $match = $item;
> }
> }
> }
>
> And why this?
>
> if($six0[$item][2] = $six0[$track][2])
>
> Please note: "=" is NOT the same as "=="!
>
> If you want to COMPARE $six0[$item][2] and $six0[$track][2] you MUST write:
>
> if($six0[$item][2] == $six0[$track][2])

The script works if it were on one line or 100 lines.

You've never seen a page where the source code was 10,000 characters long
all on one single line?
Re: solved [message #183797 is a reply to message #183796] Tue, 19 November 2013 19:52 Go to previous messageGo to next message
Beauregard T. Shagnas is currently offline  Beauregard T. Shagnas
Messages: 154
Registered: September 2010
Karma: 0
Senior Member
richard the sto0pid wrote:

> The script works if it were on one line or 100 lines.
>
> You've never seen a page where the source code was 10,000 characters
> long all on one single line?

Of course we have. However, they were not *written* that way. They were
only compressed into that hopelessly unreadable jumble after, and _only_
after they were fully debugged and completely tested for operation. *Then*
they were compressed. And that's only what you see on the web site; the
developer's source remains well-spaced and indented.

You can't do that. "Debug" is not in your vocabulary.

--
-bts
- = != ==
Re: solved [message #183806 is a reply to message #183796] Wed, 20 November 2013 15:02 Go to previous message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma: 0
Senior Member
Am 19.11.2013 20:41, schrieb richard:
> On Tue, 19 Nov 2013 17:43:25 +0100, Arno Welzel wrote:
>
>> Am 19.11.2013 03:45, schrieb richard:
>>> <?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;}}
>>> }
>>
>> PLEASE format your code properly!
>>
>> for($item=0; $item <= $max; $item++)
>> {
>> if($flip == $six0[$item]['0'])
>> {
>> if($six0[$item][2] = $six0[$track][2])
>> {
>> $match = $item;
>> }
>> }
>> }
>>
>> And why this?
>>
>> if($six0[$item][2] = $six0[$track][2])
>>
>> Please note: "=" is NOT the same as "=="!
>>
>> If you want to COMPARE $six0[$item][2] and $six0[$track][2] you MUST write:
>>
>> if($six0[$item][2] == $six0[$track][2])
>
> The script works if it were on one line or 100 lines.

READ what I wrote. I said nothing about the question, if your code works
or not - but I doubt, that you really *know* what the difference is between:

if($six0[$item][2] = $six0[$track][2])

and

if($six0[$item][2] == $six0[$track][2])

Do you? Can you explain, why your code uses the assignement and not the
comparison?

Some how it feels if I already explained this a dozen times and I just
forgot that...

> You've never seen a page where the source code was 10,000 characters long
> all on one single line?

I did. And you don't see any difference in readability above in your
version and my formatted version?

Also see here:

<http://arnowelzel.de/wiki/lib/exe/js.php>

But this does not mean, that such code is *readable* nor that I
recommend to write code this way.

In this special case (<http://arnowelzel.de/wiki/lib/exe/js.php>) it is
a "compressed" JavaScript to save bandwidth and lower the number of HTTP
requests needed. But this is constructed dynamically by js.php which
takes the local JavaScript files and creates a big "compressed" version
of them in one single block.

But for scripts which remains on the server and will never be
transmitted to the client it should be *readable* for *humans*.


--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: searching an array
Next Topic: Perform maths based on a number in a text file
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri May 17 07:33:22 GMT 2024

Total time taken to generate the page: 0.03440 seconds