Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #9505 > unrolled thread

values not changing

Started byrichard <noreply@example.com>
First post2013-05-21 14:17 -0400
Last post2013-05-22 10:02 +0930
Articles 12 — 8 participants

Back to article view | Back to comp.lang.php


Contents

  values not changing richard <noreply@example.com> - 2013-05-21 14:17 -0400
    Re: values not changing Christoph Becker <cmbecker69@gmx.de> - 2013-05-21 20:45 +0200
    Re: values not changing Denis McMahon <denismfmcmahon@gmail.com> - 2013-05-21 21:17 +0000
      Re: values not changing Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-22 00:22 +0200
      Re: values not changing Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-22 00:30 +0200
        Re: values not changing Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-22 00:32 +0200
    Re: values not changing Doug Miller <doug_at_milmac_dot_com@example.com> - 2013-05-21 22:23 +0000
      Re: values not changing "Peter H. Coffin" <hellsop@ninehells.com> - 2013-05-21 21:46 -0500
      Re: values not changing richard <noreply@example.com> - 2013-05-21 23:40 -0400
        Re: values not changing Doug Miller <doug_at_milmac_dot_com@example.com> - 2013-05-22 10:34 +0000
        Re: values not changing Scott Johnson <noonehome@chalupasworld.com> - 2013-05-22 05:41 -0700
    Re: values not changing David Robley <me@home.invalid> - 2013-05-22 10:02 +0930

#9505 — values not changing

Fromrichard <noreply@example.com>
Date2013-05-21 14:17 -0400
Subjectvalues not changing
Message-ID<14jsq8i4oxkxn.r427ym6k6zgn$.dlg@40tude.net>
www.mroldies.net

I am attempting to change the play list given the year selected.
However, regardless of which year is chosen, the code selects only the
originally loaded playlist.

What am I missing?



<?php

$year=$_GET["year"];
if (empty($year)) {$year=1900;}
$year=(int)$year;

echo $year;

if ($year=1900)
   {echo '<iframe width="800" height="800" src="test2.php"
frameborder="0"></iframe>';}

if ($year>1900)  
   {
   /* connect to the db */
$con = mysql_connect('localhost','user','pass');


if (!$con){die("can not connect: " . mysql_error());}

mysql_select_db('richbull_top100',$con);

while ($number<=10):
$result = mysql_query("SELECT atitle,artist,avid FROM A$year WHERE id =
$number");
if (!$result) { echo 'Could not run query: ' . mysql_error();  exit; }
$vid = mysql_fetch_row($result);


echo "{";

echo 'image:';
echo '""';
echo ",";

echo "title:";
echo '"';
echo $vid[0];
echo '",';

echo 'file:"http://www.youtube.com/watch?v=';
echo $vid[2];
echo '",';

echo 'description:';
echo '"';
echo $year." # ".$number." - ".$vid[1];
echo '"';

echo "},";
echo "\n";
$number++;
endwhile;

   
   
   
   
   }
  
?>

[toc] | [next] | [standalone]


#9506

FromChristoph Becker <cmbecker69@gmx.de>
Date2013-05-21 20:45 +0200
Message-ID<kngf9l$l75$1@speranza.aioe.org>
In reply to#9505
richard wrote:
> if ($year=1900)

That is an assignment to $year; instead you'll want to use:

  if ($year == 1900)

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#9509

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2013-05-21 21:17 +0000
Message-ID<kngo8r$e55$5@dont-email.me>
In reply to#9505
On Tue, 21 May 2013 14:17:13 -0400, richard wrote:

> What am I missing?

Pick from:

1) A possible issue with using attribute names instead of attribute name 
strings that has already been mentioned to you once.

2) A broken numeric comparison that's been explained elsewhere.

3) Sufficient understanding of php and javascript to safely generate the 
latter using the former.

4) All of the above.

My money is on 4.

The data you are assembling looks like json data. For json data, you need 
to quote the attribute name string. The json needs double quoted strings, 
so as you also need to use php double quoted strings to preserve variable 
substitution, you need to use escaped double quoted strings for the json 
string values.

echo "{\"image\":\"\",";
echo "\"title\":\"{$vid[0]}\",";
echo "\"file\":\"http://www.youtube.com/watch?v={$vid[2]}\",";
echo "\"description\":\"{$year} # {$number} - {$vid[1]}\"},";

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#9510

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-05-22 00:22 +0200
Message-ID<1409136.kVRb9uC88x@PointedEars.de>
In reply to#9509
Denis McMahon wrote:

> On Tue, 21 May 2013 14:17:13 -0400, richard wrote:
>> What am I missing?
> 
> Pick from:
> 
> 1) A possible issue with using attribute names instead of attribute name
> strings that has already been mentioned to you once.

There still is no such issue here, and there are still no “attribute names” 
in ECMAScript implementations.  Which has already been explained to you as 
well.


PointedEars
-- 
> If you get a bunch of authors […] that state the same "best practices"
> in any programming language, then you can bet who is wrong or right...
Not with javascript. Nonsense propagates like wildfire in this field.
  -- Richard Cornford, comp.lang.javascript, 2011-11-14

[toc] | [prev] | [next] | [standalone]


#9512

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-05-22 00:30 +0200
Message-ID<2898756.xqxexv6urH@PointedEars.de>
In reply to#9509
Denis McMahon wrote:

> The data you are assembling looks like json data. For json data, you need
> to quote the attribute name string. The json needs double quoted strings,
> so as you also need to use php double quoted strings to preserve variable
> substitution, you need to use escaped double quoted strings for the json
> string values.
> 
> echo "{\"image\":\"\",";
> echo "\"title\":\"{$vid[0]}\",";
> echo "\"file\":\"http://www.youtube.com/watch?v={$vid[2]}\",";
> echo "\"description\":\"{$year} # {$number} - {$vid[1]}\"},";

Assuming JSON, it is much better (if not even the only *correct* way) to 
write

  echo json_encode(array(
    'image' => '',
    'title' => $vid[0],
    'file'  => "http://www.youtube.com/watch?v={$vid[2]}",
    'description' => "{$year} # {$number} - {$vid[1]}"
  ));

Because you cannot simply insert arbitrary strings in a generated string 
literal and hope the outcome will be correct JSON; *at least* you would have 
to escape slashes in the inserted strings, and you do not have to do that by 
yourself if you use json_encode() in the first place.  AISB.


PointedEars
-- 
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee

[toc] | [prev] | [next] | [standalone]


#9513

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-05-22 00:32 +0200
Message-ID<2336919.POkQNuqQtL@PointedEars.de>
In reply to#9512
Thomas 'PointedEars' Lahn wrote:

> Assuming JSON, it is much better (if not even the only *correct* way) to
> write
> 
>   echo json_encode(array(
>     'image' => '',
>     'title' => $vid[0],
>     'file'  => "http://www.youtube.com/watch?v={$vid[2]}",
>     'description' => "{$year} # {$number} - {$vid[1]}"
>   ));
> 
> Because you cannot simply insert arbitrary strings in a generated string
> literal and hope the outcome will be correct JSON; *at least* you would
> have to escape slashes in the inserted strings, and you do not have to do
                ^ with back-
> that by yourself if you use json_encode() in the first place.  AISB.

-- 
    realism:    HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness:    XHTML 1.1 as application/xhtml+xml
                                                    -- Bjoern Hoehrmann

[toc] | [prev] | [next] | [standalone]


#9511

FromDoug Miller <doug_at_milmac_dot_com@example.com>
Date2013-05-21 22:23 +0000
Message-ID<XnsA1C7BBA8298B3dougmilmaccom@78.46.70.116>
In reply to#9505
richard <noreply@example.com> wrote in news:14jsq8i4oxkxn.r427ym6k6zgn$.dlg@
40tude.net:

> www.mroldies.net
> 
> I am attempting to change the play list given the year selected.
> However, regardless of which year is chosen, the code selects only the
> originally loaded playlist.
[...]
> $result = mysql_query("SELECT atitle,artist,avid FROM A$year WHERE id =
> $number");

You have a separate table for each year!? Why?

[toc] | [prev] | [next] | [standalone]


#9518

From"Peter H. Coffin" <hellsop@ninehells.com>
Date2013-05-21 21:46 -0500
Message-ID<slrnkpoccr.msg.hellsop@nibelheim.ninehells.com>
In reply to#9511
On Tue, 21 May 2013 22:23:08 +0000 (UTC), Doug Miller wrote:
> richard <noreply@example.com> wrote in news:14jsq8i4oxkxn.r427ym6k6zgn$.dlg@
> 40tude.net:
>
>> www.mroldies.net
>> 
>> I am attempting to change the play list given the year selected.
>> However, regardless of which year is chosen, the code selects only the
>> originally loaded playlist.
> [...]
>> $result = mysql_query("SELECT atitle,artist,avid FROM A$year WHERE id =
>> $number");
>
> You have a separate table for each year!? Why?

It's richard. 

-- 
The trouble with things that extend your lifespan is that they happen 
at wrong end. I'd hate to be wearing Depends at 85 and thinking "I gave
up booze and cigarettes for three more years of this."

[toc] | [prev] | [next] | [standalone]


#9519

Fromrichard <noreply@example.com>
Date2013-05-21 23:40 -0400
Message-ID<1hd4q922lq4b8$.puef8n3pevc9$.dlg@40tude.net>
In reply to#9511
On Tue, 21 May 2013 22:23:08 +0000 (UTC), Doug Miller wrote:

> richard <noreply@example.com> wrote in news:14jsq8i4oxkxn.r427ym6k6zgn$.dlg@
> 40tude.net:
> 
>> www.mroldies.net
>> 
>> I am attempting to change the play list given the year selected.
>> However, regardless of which year is chosen, the code selects only the
>> originally loaded playlist.
> [...]
>> $result = mysql_query("SELECT atitle,artist,avid FROM A$year WHERE id =
>> $number");
> 
> You have a separate table for each year!? Why?

To me, it's easier keeping track of the data.
Sure I could easily do it all in one table, adding in yet another column
for the year.

When I finish entering ALL of the data I need, there will be around 7,000
records to deal with.

[toc] | [prev] | [next] | [standalone]


#9523

FromDoug Miller <doug_at_milmac_dot_com@example.com>
Date2013-05-22 10:34 +0000
Message-ID<XnsA1C84388B901Edougmilmaccom@78.46.70.116>
In reply to#9519
richard <noreply@example.com> wrote in news:1hd4q922lq4b8$.puef8n3pevc9$.dlg@
40tude.net:

> On Tue, 21 May 2013 22:23:08 +0000 (UTC), Doug Miller wrote:
> 
>> richard <noreply@example.com> wrote in news:14jsq8i4oxkxn.r427ym6k6zgn$.dlg@
>> 40tude.net:
>> 
>>> www.mroldies.net
>>> 
>>> I am attempting to change the play list given the year selected.
>>> However, regardless of which year is chosen, the code selects only the
>>> originally loaded playlist.
>> [...]
>>> $result = mysql_query("SELECT atitle,artist,avid FROM A$year WHERE id =
>>> $number");
>> 
>> You have a separate table for each year!? Why?
> 
> To me, it's easier keeping track of the data.

???

How on earth is fifty separate tables "easier" than ONE table??

> Sure I could easily do it all in one table, adding in yet another column
> for the year.

Well, yes, you could -- after all, that's the way such things are normally done.
> 
> When I finish entering ALL of the data I need, there will be around 7,000
> records to deal with.

And -- ?

As databases go, seven thousand rows is tiny.

[toc] | [prev] | [next] | [standalone]


#9525

FromScott Johnson <noonehome@chalupasworld.com>
Date2013-05-22 05:41 -0700
Message-ID<knie6m$9a2$1@dont-email.me>
In reply to#9519
On 5/21/2013 8:40 PM, richard wrote:
> On Tue, 21 May 2013 22:23:08 +0000 (UTC), Doug Miller wrote:
>
>> richard <noreply@example.com> wrote in news:14jsq8i4oxkxn.r427ym6k6zgn$.dlg@
>> 40tude.net:
>>
>>> www.mroldies.net
>>>
>>> I am attempting to change the play list given the year selected.
>>> However, regardless of which year is chosen, the code selects only the
>>> originally loaded playlist.
>> [...]
>>> $result = mysql_query("SELECT atitle,artist,avid FROM A$year WHERE id =
>>> $number");
>>
>> You have a separate table for each year!? Why?
>
> To me, it's easier keeping track of the data.
> Sure I could easily do it all in one table, adding in yet another column
> for the year.

Or why not have a 'single' column of Year and then just change the value 
of the year for each year record/item

With a separate table per year, among other issues, what if you 
want/need to add an extra data column to the table, you now have to do 
it for each year table to ensure they are all consistent.

It just seems that you are going to have a maintenance & update 
nightmare ahead of you.

>
> When I finish entering ALL of the data I need, there will be around 7,000
> records to deal with.

Another good idea to not separate your tables

[toc] | [prev] | [next] | [standalone]


#9514

FromDavid Robley <me@home.invalid>
Date2013-05-22 10:02 +0930
Message-ID<knh3mq$4ae$1@news.albasani.net>
In reply to#9505
richard wrote:

> www.mroldies.net
> 
> I am attempting to change the play list given the year selected.
> However, regardless of which year is chosen, the code selects only the
> originally loaded playlist.
> 
> What am I missing?
> 
> 
> 
> <?php
> 
> $year=$_GET["year"];
> if (empty($year)) {$year=1900;}
> $year=(int)$year;
> 
> echo $year;
> 
> if ($year=1900)
>    {echo '<iframe width="800" height="800" src="test2.php"
> frameborder="0"></iframe>';}
> 
> if ($year>1900)
>    {
>    /* connect to the db */
> $con = mysql_connect('localhost','user','pass');
> 
> 
> if (!$con){die("can not connect: " . mysql_error());}
> 
> mysql_select_db('richbull_top100',$con);
> 
> while ($number<=10):
> $result = mysql_query("SELECT atitle,artist,avid FROM A$year WHERE id =
> $number");
> if (!$result) { echo 'Could not run query: ' . mysql_error();  exit; }

<SNIP> rest of script

In addition to the problems mentioned by others:

you haven't initialised $number for use in the while loop;

the above while loop causes a number of queries to be run, instead you could 
use BETWEEN in the query to select matching records for values of id BETWEEN 
n and 10;

you have no graceful handling of an error when running a query - the script 
just dies

-- 
Cheers
David Robley

Useless Invention: Soap Dissolver.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web