php-general Digest 29 Jul 2008 11:33:59 -0000 Issue 5595
Topics (messages 277405 through 277420):
Re: Web2.0 style tags - where to start?
277405 by: Paul Jinks
277416 by: Børge Holen
277417 by: Jason Norwood-Young
277418 by: Paul Jinks
Scoping?
277406 by: joshua harr
277407 by: joshua harr
PHP4 vs PHP5 classes
277408 by: jeff.mills.winsto.net
277409 by: Chris
277411 by: jeff.mills.winsto.net
277412 by: Chris
277413 by: jeff.mills.winsto.net
277414 by: jeff.mills.winsto.net
277415 by: Chris
Re: Problem with using array_diff and array_combine
277410 by: Chris
Re: Double results??
277419 by: Paul Gregg
Thumbnail through PHP RSS parser
277420 by: Lyubomir Tsvetanov
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
Jason Norwood-Young wrote:
On Mon, 2008-07-28 at 14:48 +0100, Paul Jinks wrote:
I think my first post was ambiguous. What we're thinking of is to build a
site on which people can view videos with the option to add metadata to a
video after viewing it.
We think that the content we have will be of wide interest to a lot of
people and the best way to index it is for users to 'tag' it themselves,
since it's hard for us to anticipate the uses that people may have for the
content.
How do you plan to have users enter the info? Through the Flash player,
through some kinda Ajax form, through a form in a frame or just a static
form?
Also, would the tags be predefined by you (eg. genres like the ID3 tag
genres) or would people be able to add their own tags?
The way I'd do it would be to let the users enter the info through an
Ajax form below the video, with suggestions popping up as they type.
Then save it in a separate table (I assume all your vids are in their
own table) with a link table between the vids table and the tags table
(M2M relationship). This means that if the tag is already in there and
linked to one vid, you don't replicate it for a second vid. It's also
very easy to do lookups of similar items. I'd also add a weighting to
the tags in the links table, maybe with the more people that add a
specific tag, the more weight that tag gets.
Also check out http://www.music-map.com/ as an example of showing
similar music - you might even be able to plug into this data.
Hi Jason
Hmm, food for thought. music-map is brilliant, though not what I'm
looking for graphically at the moment (was surprised to find Cesaria
Evora in close proximity to The Cardigans but I digress).
What you describe is pretty much what I'm chasing, thanks and helps me
down the road, particularly with thinking about the database set up.
They 'only' problem is, my php/mysql skills are some way behind my
javascript/actionscript knowhow (I'm pretty much a noob here); what I
could use now is a how-to tutorial to give me some code to work off,
either online or in a book. If it ain't there, I can build from scratch
but it's going to mean a lot of calls for help! =)
Many thanks
Paul
--- End Message ---
--- Begin Message ---
On Tuesday 29 July 2008 00:57:22 Paul Jinks wrote:
> Jason Norwood-Young wrote:
> > On Mon, 2008-07-28 at 14:48 +0100, Paul Jinks wrote:
> >> I think my first post was ambiguous. What we're thinking of is to build
> >> a site on which people can view videos with the option to add metadata
> >> to a video after viewing it.
> >>
> >> We think that the content we have will be of wide interest to a lot of
> >> people and the best way to index it is for users to 'tag' it themselves,
> >> since it's hard for us to anticipate the uses that people may have for
> >> the content.
> >
> > How do you plan to have users enter the info? Through the Flash player,
> > through some kinda Ajax form, through a form in a frame or just a static
> > form?
> >
> > Also, would the tags be predefined by you (eg. genres like the ID3 tag
> > genres) or would people be able to add their own tags?
> >
> > The way I'd do it would be to let the users enter the info through an
> > Ajax form below the video, with suggestions popping up as they type.
> > Then save it in a separate table (I assume all your vids are in their
> > own table) with a link table between the vids table and the tags table
> > (M2M relationship). This means that if the tag is already in there and
> > linked to one vid, you don't replicate it for a second vid. It's also
> > very easy to do lookups of similar items. I'd also add a weighting to
> > the tags in the links table, maybe with the more people that add a
> > specific tag, the more weight that tag gets.
> >
> > Also check out http://www.music-map.com/ as an example of showing
> > similar music - you might even be able to plug into this data.
>
> Hi Jason
>
> Hmm, food for thought. music-map is brilliant, though not what I'm
> looking for graphically at the moment (was surprised to find Cesaria
> Evora in close proximity to The Cardigans but I digress).
>
> What you describe is pretty much what I'm chasing, thanks and helps me
> down the road, particularly with thinking about the database set up.
> They 'only' problem is, my php/mysql skills are some way behind my
> javascript/actionscript knowhow (I'm pretty much a noob here); what I
> could use now is a how-to tutorial to give me some code to work off,
> either online or in a book. If it ain't there, I can build from scratch
> but it's going to mean a lot of calls for help! =)
http://www.google.com/search?q=mysql+php+tutorials&ie=utf-8&oe=utf-8&aq=t&rls=org.debian:en-US:unofficial&client=iceweasel-a
I like from scratch... =D I guss I can do that cuz I don't make a living out
of it ;D
>
> Many thanks
>
> Paul
--
---
Børge Holen
http://www.arivene.net
--- End Message ---
--- Begin Message ---
On Mon, 2008-07-28 at 23:57 +0100, Paul Jinks wrote:
> Jason Norwood-Young wrote:
> > On Mon, 2008-07-28 at 14:48 +0100, Paul Jinks wrote:
> >
> >> I think my first post was ambiguous. What we're thinking of is to build a
> >> site on which people can view videos with the option to add metadata to a
> >> video after viewing it.
> >>
> >> We think that the content we have will be of wide interest to a lot of
> >> people and the best way to index it is for users to 'tag' it themselves,
> >> since it's hard for us to anticipate the uses that people may have for the
> >> content.
> >>
> >
> > How do you plan to have users enter the info? Through the Flash player,
> > through some kinda Ajax form, through a form in a frame or just a static
> > form?
> >
> > Also, would the tags be predefined by you (eg. genres like the ID3 tag
> > genres) or would people be able to add their own tags?
> >
> > The way I'd do it would be to let the users enter the info through an
> > Ajax form below the video, with suggestions popping up as they type.
> > Then save it in a separate table (I assume all your vids are in their
> > own table) with a link table between the vids table and the tags table
> > (M2M relationship). This means that if the tag is already in there and
> > linked to one vid, you don't replicate it for a second vid. It's also
> > very easy to do lookups of similar items. I'd also add a weighting to
> > the tags in the links table, maybe with the more people that add a
> > specific tag, the more weight that tag gets.
> >
> > Also check out http://www.music-map.com/ as an example of showing
> > similar music - you might even be able to plug into this data.
> >
> >
> Hi Jason
>
> Hmm, food for thought. music-map is brilliant, though not what I'm
> looking for graphically at the moment (was surprised to find Cesaria
> Evora in close proximity to The Cardigans but I digress).
>
> What you describe is pretty much what I'm chasing, thanks and helps me
> down the road, particularly with thinking about the database set up.
> They 'only' problem is, my php/mysql skills are some way behind my
> javascript/actionscript knowhow (I'm pretty much a noob here); what I
> could use now is a how-to tutorial to give me some code to work off,
> either online or in a book. If it ain't there, I can build from scratch
> but it's going to mean a lot of calls for help! =)
>
> Many thanks
>
> Paul
In that case, I suggest the following solution:
1. Download the unternet into your puter
2. Open the file called mysql.com
3. Read and learn
4. Open the file called php.net
5. Read and learn
6. Rinse and repeat
In all seriousness, this is a nice, simple project to learn on. You want
to look at different types of relationships in Sql (one-to-one,
one-to-many and many-to-many) and learn a bit about basic DB
architecture; make some tables and play with getting data in and out
(get PHPMyAdmin to help you out); maybe use a nice simple framework like
CodeIgniter to get you kick-started on the PHP.
--- End Message ---
--- Begin Message ---
On Tue, July 29, 2008 9:22 am, Jason Norwood-Young wrote:
>
> On Mon, 2008-07-28 at 23:57 +0100, Paul Jinks wrote:
>> Jason Norwood-Young wrote:
>> > On Mon, 2008-07-28 at 14:48 +0100, Paul Jinks wrote:
>> >
>> >> I think my first post was ambiguous. What we're thinking of is to
>> build a
>> >> site on which people can view videos with the option to add metadata
>> to a
>> >> video after viewing it.
>> >>
>> >> We think that the content we have will be of wide interest to a lot
>> of
>> >> people and the best way to index it is for users to 'tag' it
>> themselves,
>> >> since it's hard for us to anticipate the uses that people may have
>> for the
>> >> content.
>> >>
>> >
>> > How do you plan to have users enter the info? Through the Flash
>> player,
>> > through some kinda Ajax form, through a form in a frame or just a
>> static
>> > form?
>> >
>> > Also, would the tags be predefined by you (eg. genres like the ID3 tag
>> > genres) or would people be able to add their own tags?
>> >
>> > The way I'd do it would be to let the users enter the info through an
>> > Ajax form below the video, with suggestions popping up as they type.
>> > Then save it in a separate table (I assume all your vids are in their
>> > own table) with a link table between the vids table and the tags table
>> > (M2M relationship). This means that if the tag is already in there and
>> > linked to one vid, you don't replicate it for a second vid. It's also
>> > very easy to do lookups of similar items. I'd also add a weighting to
>> > the tags in the links table, maybe with the more people that add a
>> > specific tag, the more weight that tag gets.
>> >
>> > Also check out http://www.music-map.com/ as an example of showing
>> > similar music - you might even be able to plug into this data.
>> >
>> >
>> Hi Jason
>>
>> Hmm, food for thought. music-map is brilliant, though not what I'm
>> looking for graphically at the moment (was surprised to find Cesaria
>> Evora in close proximity to The Cardigans but I digress).
>>
>> What you describe is pretty much what I'm chasing, thanks and helps me
>> down the road, particularly with thinking about the database set up.
>> They 'only' problem is, my php/mysql skills are some way behind my
>> javascript/actionscript knowhow (I'm pretty much a noob here); what I
>> could use now is a how-to tutorial to give me some code to work off,
>> either online or in a book. If it ain't there, I can build from scratch
>> but it's going to mean a lot of calls for help! =)
>>
>> Many thanks
>>
>> Paul
>
> In that case, I suggest the following solution:
> 1. Download the unternet into your puter
> 2. Open the file called mysql.com
> 3. Read and learn
> 4. Open the file called php.net
> 5. Read and learn
> 6. Rinse and repeat
>
LOL
> In all seriousness, this is a nice, simple project to learn on. You want
> to look at different types of relationships in Sql (one-to-one,
> one-to-many and many-to-many) and learn a bit about basic DB
> architecture; make some tables and play with getting data in and out
> (get PHPMyAdmin to help you out); maybe use a nice simple framework like
> CodeIgniter to get you kick-started on the PHP.
>
Right, from scratch it is then (installs xampp, starts up PSPad, and
cancels all meetings)... =)
Cheers
Paul
--- End Message ---
--- Begin Message ---
I'm new to php. My understanding of php scoping in v5 is that within a file
there are only two scopes, main and in function.
Why doesn't this work?
-------
$err = "original value";
$page = "<html><font color=\"red\"> {$err} </font>Some more HTML</html>";
if(something)
{
$err = "this error";
// $err retains original value instead of becoming "this error"
print $page;
}
else(something else)
{
$err = "that error";
// $err retains original value instead of becoming "that error"
print $page;
}
--------
Thanks much!
--- End Message ---
--- Begin Message ---
Never mind. Gotta lay off the dumb juice.
--- End Message ---
--- Begin Message ---
I have the following code in part of a loop:
$max = $players->max();
Important parts of players class:
class Players extends dynamicTable {
var $setup;
var $lid;
var $size;
var $max;
var $data;
var $data_result;
var $data_index;
var $player_stats_result;
var $player_stats_data;
var $player_stats_index;
var $player_stats_start;
var $player_type_result;
function Players($lid) {
global $prefix, $db;
/*
* Find max size of rows
*/
$this->lid = $lid;
$this->max=0;
echo "$this->index";
$result = $db->sql_query("select * from " . $prefix .
"_league_games_setup where lid = $lid");
while (($rows = $db->sql_fetchrow($result))) {
$c=0;
for ($i=3; $i < 23; $i++) {
if ($rows[$i] != "")
$c++;
}
if ($c > $this->max)
$this->max = $c;
}
$this->index = 3;
}
function max() {
return ($this->max);
The most important part of this code to me is:
$this->index = 3;
It is important that this is reset to 3 for the rest of the loop to work
properly.
In PHP4, $this->index is reset to 3 each time the loop happens, but in
PHP5 it is not.
It appears that after the first loop, PHP5 seems to "remember" the value
of $this->max and therefore does not enter the Players function to set
$this->index = 3. I have run through the script with a debugger, and sure
enough, we only enter function Players once.
Is this normal behaviour for PHP5 vs PHP4?
Is there a way for me to force $this->max to be calculated each time
function max is called?
--- End Message ---
--- Begin Message ---
> I have run through the script with a debugger, and sure
> enough, we only enter function Players once.
>
> Is this normal behaviour for PHP5 vs PHP4?
> Is there a way for me to force $this->max to be calculated each time
> function max is called?
Since the Players method is a constructor, it's more about how you set
the object(s) up.
What does the loop look like before you create a new object?
--
Postgresql & php tutorials
http://www.designmagick.com/
--- End Message ---
--- Begin Message ---
>
> Since the Players method is a constructor, it's more about how you set
> the object(s) up.
>
> What does the loop look like before you create a new object?
>
Well see here is where it gets messy! This is not my code - I've ported a
phpnuke module over to dragonflycms.
The $players object is created before the loop:
$players = new Players($lid);
The loop is quite big, but here is the important part:
-------------SNIP-------------
while (list($pid, $name, $gsid, $stat) = $players->fetchSelectData()) {
if (DEBUG_LEAGUE == "YES") echo "<tr><td colspan=\"22\">\$maxcol =
$maxcol | \$pid = $pid | \$name = $name | \$gsid = $gsid | \$stat =
$stat</td></tr>\$
$noplayer=0;
if ($prevgsid != $gsid) {
$prevgsid = $gsid;
$players->selectHeaders($gsid);
if (DEBUG_LEAGUE == "YES") var_dump($players);
displayPlayerSetupRow($players,
"".getlink("$module")."&&file=index&mode=$mode&lid=$lid&sid=$sid&gsid=$gsid",
$order);
}
-------------SNIP-------------
function displayPlayerSetupRow is also very big, but here it is up to the
troublesome $players->max call:
-------------SNIP-------------
function displayPlayerSetupRow($players, $go="", $prevorder=0) {
global $bgcolor2;
if ($prevorder=="")
$prevorder=0;
$urlstart="";
$urlend="";
$max = $players->max();
-------------SNIP-------------
Then we enter class Players as previously mentioned:
-------------SNIP-------------
class Players extends dynamicTable {
var $setup;
var $lid;
var $size;
var $max;
var $data;
var $data_result;
var $data_index;
var $player_stats_result;
var $player_stats_data;
var $player_stats_index;
var $player_stats_start;
var $player_type_result;
function Players($lid) {
global $prefix, $db;
/*
* Find max size of rows
*/
$this->lid = $lid;
$this->max=0;
$result = $db->sql_query("select * from " . $prefix .
"_league_games_setup where lid = $lid");
while (($rows = $db->sql_fetchrow($result))) {
$c=0;
for ($i=3; $i < 23; $i++) {
if ($rows[$i] != "")
$c++;
}
if ($c > $this->max)
$this->max = $c;
}
$this->index = 3;
}
function name() {
return ($this->setup['name']);
}
function max() {
return ($this->max);
}
-------------SNIP-------------
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>
> --
> This email has been scanned for viruses and dangerous content by
> Sydney Technology Solutions MailMaster Email Protection Services.
>
> For more information please visit http://www.sydneytech.com.au
> :Scanned by MailMaster1:
>
>
--- End Message ---
--- Begin Message ---
[EMAIL PROTECTED] wrote:
>> Since the Players method is a constructor, it's more about how you set
>> the object(s) up.
>>
>> What does the loop look like before you create a new object?
>>
>
> Well see here is where it gets messy! This is not my code - I've ported a
> phpnuke module over to dragonflycms.
>
> The $players object is created before the loop:
> $players = new Players($lid);
<snip>
Which means the code is only executed once since it's in the
constructor. It's not changing per loop because you're not calling the code.
Maybe setting $this->max should be done in
fetchSelectData
since that's what is causing/creating your loop.
--
Postgresql & php tutorials
http://www.designmagick.com/
--- End Message ---
--- Begin Message ---
>>
>> The $players object is created before the loop:
>> $players = new Players($lid);
>
> <snip>
>
> Which means the code is only executed once since it's in the
> constructor. It's not changing per loop because you're not calling the
> code.
>
> Maybe setting $this->max should be done in
>
> fetchSelectData
>
> since that's what is causing/creating your loop.
Thanks Chris, I will give that a shot.
Just to confirm, this script works just fine in php4, so do we put that
down to pure luck, or has there been a change in php5 that will be causing
it?
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>
> --
> This email has been scanned for viruses and dangerous content by
> Sydney Technology Solutions MailMaster Email Protection Services.
>
> For more information please visit http://www.sydneytech.com.au
> :Scanned by MailMaster1:
>
>
--- End Message ---
--- Begin Message ---
> Maybe setting $this->max should be done in
>
> fetchSelectData
>
> since that's what is causing/creating your loop.
>
Thanks Chris, I copied the code into the fetchSelectData function and it
seems to be working fine now!
Just need to test removing the code from the constructor to make sure its
still working, and also test that php4 is still working.
I'm just concerned that the code might also be called from somewhere else.
You've cured my headache!
--- End Message ---
--- Begin Message ---
[EMAIL PROTECTED] wrote:
>>> The $players object is created before the loop:
>>> $players = new Players($lid);
>> <snip>
>>
>> Which means the code is only executed once since it's in the
>> constructor. It's not changing per loop because you're not calling the
>> code.
>>
>> Maybe setting $this->max should be done in
>>
>> fetchSelectData
>>
>> since that's what is causing/creating your loop.
>
> Thanks Chris, I will give that a shot.
> Just to confirm, this script works just fine in php4, so do we put that
> down to pure luck, or has there been a change in php5 that will be causing
> it?
No idea why it works in php4 - if you're only calling the "Players"
method once (or through the constructor) it should have behaved the same
in php4.
--
Postgresql & php tutorials
http://www.designmagick.com/
--- End Message ---
--- Begin Message ---
Richard Kurth wrote:
> I hope I can explain what I am trying to do.
> I have two tables the first one has the custom form elements
>
>
> elements_id elements_field_type elements_field_caption members_id
> 35 text test 8
> 36 text test2 8
>
>
> The second one has the customer id and the field value withe the field name
>
> dbelements_field_name dbelements_field_value members_id customer_id
> 35 Test This Field 8 346
> 36 8 346
> 36 Test2 8 347
>
>
> If you look at the second table you will see that one field name is
> related to two different customers and one field name on relates to one
> customer.
> I am trying to look at these two tables and find customer that do not
> have a row for each field name.
>
> I have been trying with
>
> array_combine($dbelements_field_array,$dbelements_id_array)
> and also array_diff($customf_array,$dbelements_field_array)
You can do it in sql.
// find customer_id's who don't have all fields filled in
$subquery = "
select
customer_id
from
customformelements cfe
left join
dbelements de on (cfe.elements_id=de.dbelements_field_name and
de.members_id=cfe.members_id)
where
cfe.members_id=8
and
de.dbelements_field_name is null
";
Then get your customers:
select
c.*
from
contacts
where
customer_id in
(
$subquery
);
Also for array_diff you have to check it both ways:
$ cat diff.php
<?php
$array_one = array (1,2,3,4,5);
$array_two = array (2,3,4);
$diff_one = array_diff($array_one, $array_two);
echo "diff 1:\n";
print_r($diff_one);
$diff_two = array_diff($array_two, $array_one);
echo "diff 2:\n";
print_r($diff_two);
$ php diff.php
diff 1:
Array
(
[0] => 1
[4] => 5
)
diff 2:
Array
(
)
--
Postgresql & php tutorials
http://www.designmagick.com/
--- End Message ---
--- Begin Message ---
In mail.php.general, Dan Shirah <[EMAIL PROTECTED]> wrote:
> $name_result = ifx_query ($name_query, $connect_id);
> while ($name = ifx_fetch_row($name_result)) {
> $party_name = TRIM($name['caa44240004']);
> print_r($name);
> }
>
> print_r($name) will return:
> John
> John
> Mary
> Mary
> Cindy
> Cindy
I don't know anything about the Informix functions, but in other database
types fetch_row can return "doubly indexed" entries. e.g.
array(
0 => 'John',
'name' => 'John',
)
I would suggest you use var_dump() or var_export() to get a better idea of
what is in $name - you might find if this is the case that your code
is not necessarily wrong because you are getting the right number of rows.
Note it is hard to tell from your code - because your code would run
print_r() for every loop - but that isn't what your suggested output is.
Regards,
PG
--- End Message ---
--- Begin Message ---
Hello, folks!
I'm trying to parse RSS feed and display it on my own page.
MagpieRSS looks good enough for me, but I have a little problem.
http://magpierss.sourceforge.net/
I want to display not only the title and description of each article,
but the thumbnail as well.
For example, I tried to do that with this feed.
http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml
Everything is alright with the title and the description, but I can't
do the thumbnail thing. What I've tried is the following:
foreach ($rss->items as $item ) {
$title = $item[title];
$url = $item[link];
$description = $item[description];
$thumbnail = $item['media:thumbnail'];
echo "<a href=$url>$title</a></li><br>";
echo $description;
echo "<img $thumbnail>";
}
As I said before, the other things are fine, but it's not showing the
thumbnail. This is the structure:
<title>txt</title>
<description>txt</description>
<media:thumbnail width="X" height="Y" url="url"/>
And the following line of the php code returns blank result.
(probably because we require parameter of media:thumbnail, not
the value 'inside' it):
$thumbnail = $item['media:thumbnail'];
So I am interested in that parameter url, but I do not know how
can we get it.
Thanks in advance for any help!
--- End Message ---