
nicholasstephan
Members-
Posts
25 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
nicholasstephan's Achievements

Member (2/5)
0
Reputation
-
ok - a little more digging and I found bug report #24608, and the php dev teams response: [2004-01-05 05:53 UTC] [email protected] OK, this code actually cannot work (since __set cannot receive the right data to set style['temp'] - it gets only property name, and style['temp'] is not a name). However, you certailnly can make array beforenahd and then assign it to $test->style and it will go through the accessor. I have fixed it to give an error in this case and not to do things which it is not supposed to do. so it is behaving as it should, just not very intuitively... anybody know a workaround to get to work like you'd think it would? cheers
-
very simple getter/setter in a class: class Foo { private $vars; public function __set($key, $val) { $this->vars[$key] = $val ; } public function __get($key) { return $this->vars[$key]; } } but $bar = new Foo(); $bar->poetry = array(); $bar->poetry[] = "mary had a little lamb"; $bar->poetry[] = "fleece as white as snow"; print_r($bar->poetry); // Array ( ) It kind of makes sense that the $bar->poetry[] = ... assignments aren't hitting the setter, so $vars is never updated beyond $bar->poetry = array(), and you can always $poetry = array("mary had a little lamb", "fleece as white as snow"); $bar->poetry = $poetry; but it's still kind of annoying. Is there any way of setting it up so you can work with arrays in Foo directly? Thanks.
-
that's a good idea... I took out all but the form elements to take a look, but everything looks fine. So I copied the code over to my MAMP dir to test locally and what do you know... it works. Hours of fiddling and it's a server issue. It looks like the server is allowing 20 file inputs through, but no more than that. Is that something in php configs? How do I get around this? thanks.
-
That's the weirdest way to store quantities dude... take a look at the php array functions (http://us.php.net/manual/en/ref.array.php) you've got, you should be able to figure something out. But I'd recommend that to turn your array into something more like: $cart = array( '2' => '1', // id => quantity '34' => '1', '55' => '2', '67' => '1', '101' => '1' ); Then all you'd have to do to increase a value in the array is: $cart[$id]++; Also - look into making your <input/> tags arrays too to save yourself all that string manipulation: Instead of having the input be named "qty23" you could name it "qty[23]"... then in php it's simply $_POST['qty']['23']... Then you could update your quantities like: foreach($_POST['qty'] as $id => $qty) $cart[$id] = $qty;
-
you can do the same thing using phpMyAdmin (www.phpmyadmin.net).
-
Hi, I've written some image gallery CMS software and I'm having some strange results with the $_FILE uploads. I have recurring html fields that look like: <input type="file" name="large[]"/> when I submit the form the $_FILE array looks like the following. But there should be about 15 files in the array, not 5 (in the case of 'medium' images) or 4 (in the case of 'large' images)... Why are these arrays being truncated? thanks . . . [medium] => Array ( [name] => Array ( [0] => [1] => [2] => [3] => [4] => [5] => sigline_maltese_chairs_01.jpg ) [type] => Array ( [0] => [1] => [2] => [3] => [4] => [5] => image/jpeg ) [tmp_name] => Array ( [0] => [1] => [2] => [3] => [4] => [5] => /tmp/phpuKDwYq ) [error] => Array ( [0] => 4 [1] => 4 [2] => 4 [3] => 4 [4] => 4 [5] => 0 ) => Array ( [0] => 0 [1] => 0 [2] => 0 [3] => 0 [4] => 0 [5] => 21562 ) ) [large] => Array ( [name] => Array ( [0] => [1] => [2] => [3] => [4] => ) [type] => Array ( [0] => [1] => [2] => [3] => [4] => ) [tmp_name] => Array ( [0] => [1] => [2] => [3] => [4] => ) [error] => Array ( [0] => 4 [1] => 4 [2] => 4 [3] => 4 [4] => 4 ) => Array ( [0] => 0 [1] => 0 [2] => 0 [3] => 0 [4] => 0 ) ) )
-
pretty cool. I might default to this. I'd like to keep as much of it in the database as I can... this method would either require pulling the whole database into a php array and then recurse through it, or there'd be a huge number of sql queries. seems like a lot of overhead either way.
-
I'd agree with this. It might make sense to limit this client to four levels, and build the database accordingly... but if possible I'd rather build something more generic. Another trick up my sleeve that I can pull out of my hat if I need it again. akitchin: that article is SWEET! The only problem I'm seeing with the Nested Set model is in ordering the nodes. The structure is so dependent on the nodes' placement relative to each other that it seems like it would be difficult to alphabetize the list by name or price, for example. I've also found this: http://www.artfulsoftware.com/mysqlbook/sampler/mysqled1ch20.html Am reading it now, so not sure if it applies, but it looks promising....
-
ok - I've got a bit of a puzzle here. I've got a client that is insisting on like 15 levels (ok, only 4) of navigation for an online store. And that's not even constant across the site. For example: You've got a Furniture section; in that you have Bedroom, Bathroom, etc..; in that you have Sofas, Tables, etc...; inside that you have Slipcovers, Sleepers, etc... etc... etc.. But then garden furniture only is only 2 levels deep. Accessories only 1. So what I'm thinking is to make a generic sections table with a parent_id field and make a tree; Furniture would have an id of 1 and a parent of null (signifying a top level section), Bedroom would be a child of Furniture... you get the idea. The puzzle is in how to find products for each section. I want to be able to query all products in Bedroom, for example. A Sofa (for example) will have a section_id linking it to Sleepers, which is within Sofas, which is in Bedroom. So I have to somehow query: Every product with a section_id = the Bedroom section's id, or any child of Bedroom's id, or any child of that's id... I recognize this as a recursive loop and could probably do it by finagling some php, but that seems horribly inefficient. How would I got about it with in MySQL? Do I have to create a procedure, or is there some trick to it? Sorry for the wordy post. Any help would be appreciated. Thanks Nick
-
Ok - a bit of a boggle for the mind here: I'm implementing arrayaccess and Iterator to create a class that mimics array functionality, and works in loops (http://us.php.net/manual/en/class.arrayaccess.php and http://us.php.net/manual/en/class.iterator.php). This works great most of the time, you can traverse the tree with []'s and plug it into a foreach loop and control the output with rewind(), valid(), current()... functions. Where the thing is falling over is when I try to encode it as JSON. Does anybody know how json_encode() is gathering it's data. It's not looping through the content the same way foreach does. What it ends up doing is giving me a json string representing all the public internal variables in my class, rather than the data the class is supposed to hold. WTF
-
[SOLVED] type checking (is_numeric vs. is_string)
nicholasstephan replied to nicholasstephan's topic in PHP Coding Help
is_int seems to do it! Why is_int seems to strictly type the input, while is_numeric doesn't, I don't know. By it works. thanks -
I'm writing a class that implements Php's Iterator interface. Where I'm running into trouble is in the keys. I'd like to be able to respond differently to associative vs index keys, basically strings vs integers. Is there any way to check the input to the offsetGet() function. Using is_string and is_numeric don't work, because any string that happens to be numeric is treated as a numbered key, rather than an associative attribute name... So for example: echo $arr['hello']; works fine, 'hello' is a string, and the value matching that key is returned. echo $arr[23]; does alright, 23 is a number, and the 23rd value is returned. but what about: echo $arr["1231231234"]; I have no idea why you'd make a phone number an associative key, but nevertheless, I'd like it to return the correct response... the value associated with that key, and not look for the one billion two hundred thirty million...th entry. I'm a bit baffled. Cheers
-
So - The goal is pretty simple, but the application is proving harder than I thought it would be. I'd like to let people type in (and see) friendly looking URLs, but have them load dynamic content. For example: instead of http://www.mysite.com/article.php?id=1234?uid=4321 (whatever), I'd like to see http://www.mysite.com/articles/ArticleTitle. To do this, I'm thinking: 1) with .htaccess, I shunt Apache 404 errors to a page that uses Php's $_SERVER global to grab the url and split it up into variables. 2) I use those variables to run MySQL queries, read files, build and populate pages, etc... 3) and output the results. If the exact article is found, display it. If it's not, be able to say "did you mean... " and treat it like a search. This seems to be all well and good, but then you try to click on something and you find that because you haven't redirected the user, all your relative links are relative to a non-existing directory! :'( So href="about.php" goes to "whatever_the_user_typed/about.php"... not exactly a good situation, considering this just leads back to the 404 page and everything gets very confused. I can put a redirect in there, so the user types /team/john and gets forwarded onto /team.php?id=123, but that kind of defeats the purpose as you want them to be able to look up and see something they might remember and tell others. I've looked into redirecting, then using a apache mod_rewrite, but it seems stupid redirect (changing the url), then manually change it back again... :-\ Am I going about this entirely the wrong way. There must be a solution out there... Anyone have any advice. I don't need someone to write the code for me, I can muddle through it, just some direction... maybe a couple of links... Thanks