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

Home » Imported messages » comp.lang.php » values not changing
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
values not changing [message #181557] Tue, 21 May 2013 18:17 Go to next message
richard is currently offline  richard   
Messages: 213
Registered: June 2013
Karma: 0
Senior Member
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;





}

?>
Re: values not changing [message #181558 is a reply to message #181557] Tue, 21 May 2013 18:45 Go to previous messageGo to next message
Christoph Becker is currently offline  Christoph Becker
Messages: 91
Registered: June 2012
Karma: 0
Member
richard wrote:
> if ($year=1900)

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

if ($year == 1900)

--
Christoph M. Becker
Re: values not changing [message #181561 is a reply to message #181557] Tue, 21 May 2013 21:17 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
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(at)gmail(dot)com
Re: values not changing [message #181562 is a reply to message #181561] Tue, 21 May 2013 22:22 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
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
Re: values not changing [message #181563 is a reply to message #181557] Tue, 21 May 2013 22:23 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: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?
Re: values not changing [message #181564 is a reply to message #181561] Tue, 21 May 2013 22:30 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
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
Re: values not changing [message #181565 is a reply to message #181564] Tue, 21 May 2013 22:32 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
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
Re: values not changing [message #181566 is a reply to message #181557] Wed, 22 May 2013 00:32 Go to previous messageGo to next message
David Robley is currently offline  David Robley
Messages: 23
Registered: March 2013
Karma: 0
Junior Member
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.
Re: values not changing [message #181570 is a reply to message #181563] Wed, 22 May 2013 02:46 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 Tue, 21 May 2013 22:23:08 +0000 (UTC), Doug Miller wrote:
> richard <noreply(at)example(dot)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."
Re: values not changing [message #181571 is a reply to message #181563] Wed, 22 May 2013 03:40 Go to previous messageGo to next message
richard is currently offline  richard   
Messages: 213
Registered: June 2013
Karma: 0
Senior Member
On Tue, 21 May 2013 22:23:08 +0000 (UTC), Doug Miller wrote:

> richard <noreply(at)example(dot)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.
Re: values not changing [message #181575 is a reply to message #181571] Wed, 22 May 2013 10:34 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:1hd4q922lq4b8$.puef8n3pevc9$.dlg@
40tude.net:

> On Tue, 21 May 2013 22:23:08 +0000 (UTC), Doug Miller wrote:
>
>> richard <noreply(at)example(dot)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.
Re: values not changing [message #181577 is a reply to message #181571] Wed, 22 May 2013 12:41 Go to previous message
Scott Johnson is currently offline  Scott Johnson
Messages: 196
Registered: January 2012
Karma: 0
Senior Member
On 5/21/2013 8:40 PM, richard wrote:
> On Tue, 21 May 2013 22:23:08 +0000 (UTC), Doug Miller wrote:
>
>> richard <noreply(at)example(dot)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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: insert PDF table in database
Next Topic: Got it working finally
Goto Forum:
  

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

Current Time: Thu Dec 19 15:01:46 GMT 2024

Total time taken to generate the page: 0.02366 seconds