Jump to content

antmeeks

Members
  • Posts

    21
  • Joined

  • Last visited

Everything posted by antmeeks

  1. I've been stuck on this for a couple of hours now & I'd really appreciate some help(!) I have 2 tables: entries +----+--------+------+-------+------------+ ¦ id ¦ status ¦ type ¦ order ¦ date ¦ +----+--------+------+-------+------------+ ¦ 1 ¦ 1 ¦ term ¦ 4 ¦ 0000-00-00 ¦ ¦ 2 ¦ 0 ¦ item ¦ 6 ¦ 0000-00-00 ¦ ¦ 3 ¦ 1 ¦ term ¦ 1 ¦ 0000-00-00 ¦ ¦ 4 ¦ 1 ¦ term ¦ 7 ¦ 0000-00-00 ¦ ¦ 5 ¦ 0 ¦ item ¦ 5 ¦ 0000-00-00 ¦ ¦ 6 ¦ 1 ¦ term ¦ 8 ¦ 0000-00-00 ¦ ¦ 7 ¦ 1 ¦ term ¦ 3 ¦ 0000-00-00 ¦ ¦ 8 ¦ 0 ¦ item ¦ 2 ¦ 0000-00-00 ¦ +----+--------+------+-------+------------+ entry_text +----+----------+----------+---------+---------+ ¦ id ¦ entry_id ¦ language ¦ name ¦ value ¦ +----+----------+----------+---------+---------+ ¦ 1 ¦ 7 ¦ en ¦ title ¦ varchar ¦ ¦ 2 ¦ 7 ¦ en ¦ content ¦ varchar ¦ ¦ 3 ¦ 7 ¦ fr ¦ title ¦ varchar ¦ ¦ 4 ¦ 7 ¦ fr ¦ content ¦ varchar ¦ ¦ 5 ¦ 3 ¦ en ¦ title ¦ varchar ¦ ¦ 6 ¦ 3 ¦ en ¦ content ¦ varchar ¦ ¦ 7 ¦ 3 ¦ fr ¦ title ¦ varchar ¦ ¦ 8 ¦ 3 ¦ fr ¦ content ¦ varchar ¦ ¦ 9 ¦ 6 ¦ en ¦ title ¦ varchar ¦ ¦ 10 ¦ 6 ¦ en ¦ content ¦ varchar ¦ ¦ 11 ¦ 6 ¦ fr ¦ title ¦ varchar ¦ ¦ 12 ¦ 6 ¦ fr ¦ content ¦ varchar ¦ ¦ 13 ¦ 2 ¦ en ¦ title ¦ varchar ¦ ¦ 14 ¦ 2 ¦ en ¦ content ¦ varchar ¦ ¦ 15 ¦ 2 ¦ fr ¦ title ¦ varchar ¦ ¦ 16 ¦ 2 ¦ fr ¦ content ¦ varchar ¦ +----+----------+----------+---------+---------+ What I'm trying to do is some sort of join statement like: select * from entries where status = 1 and type = term join name,value from entry_text where entry_id = entries.id and language = en order by entries.order, entries.date ASC where I end up with an associative result, indexed by entries.id with the result from entry_text being a name/val pair nested array: array( [3] => array( [id] => 3 [status] => 1 [type] => term [order] => 1 [date] => 0000-00-00 [text] => array( [title] => varchar [content] => varchar ) ) [7] => array( [id] => 7 [status] => 1 [type] => term [order] => 3 [date] => 0000-00-00 [text] => array( [title] => varchar [content] => varchar ) ) [1] => array( [id] => 1 [status] => 1 [type] => term [order] => 4 [date] => 0000-00-00 [text] => array( [title] => varchar [content] => varchar ) ) etc... ) Doable...? (sorry for the wonky formatting - I can't get the editor to preserve my spacing)
  2. Yes, I have... And for my needs, that's like bringing a bulldozer to dig a flower bed... I'm really kinda looking for something more compact & straightforward... more along the lines of ezSQL (http://justinvincent.com/ezsql).
  3. I'm making the switch from years of using plain-jane 'deprecated' MySQL functions to PDO in a lot of my scripts. Consequently, I'm looking for a good, well-known & well-liked PDO wrapper / extension class. Something that automates some common db access functions (CRUD), handles try/catch/exceptions, and keeps track of metrics (query count, memory usage, etc.)... If anyone can point me in a direction, I'd really appreciate it!!
  4. I did have them organized in a separate files, but wanted to eliminate as many manual includes/requires as possible. Sigh... Yes, you are probably right - that's the best approach... I guess I was just trying to be too clever... I suspected it was dumb, which is why I posted it, lol.
  5. Lol, I knew that question would come up... I have two reasons for doing this: 1. To keep the functions organized in a meaningful way. 2. To load the files dynamically with spl_autoload_register().
  6. So I've decided to put several disparate but related functions into helper classes. Here's an example of what such a class would look like (with obviously more involved methods), and I'd like a critique on it's structure. class MyHelpers { public $str; public $Array; private $Params; public function __construct($method, $Params) { $method = '_' . $method; $this->Params = (is_array($Params)) ? $Params : NULL; $result = (method_exists($this, $method)) ? $this->$method() : NULL; (is_array($result)) ? $this->Array = $result : $this->str = $result; } private function _outputString() { if(is_array($this->Params)) : return (isset($this->Params['str'])) ? $this->Params['str'] : NULL; endif; } private function _makeArray() { if(is_array($this->Params)) : $str = (isset($this->Params['array'])) ? $this->Params['array'] : NULL; return explode(',', $str); endif; } } And here's how you would instantiate and use it: $GetResult = new MyHelpers('outputString', array('str'=>'This is a string.')); $str = $GetResult->str; $GetResult = new MyHelpers('makeArray', array('array'=>'1,2,3')); $Array = $GetResult->Array; Thoughts?
  7. You just need to write a recursive file finder/includer to traverse the subdirectories. There's a ton of them out there already written... just google it.
  8. Doh! I just figured that out right before your post.... You know it's getting late when you post in a forum before even trying it out first... What I wanted to do was nest the arrays into one var - which, as you say, my original post was a completely valid example of: $d=$Array3[$Array2[$Array1[$a]]]; Time for bed.
  9. Sorry, I guess I wasn't clear... I'm not trying to make a multidimensional array out of 3 other arrays, I'm trying to consolidate the compounding of multiple array key values into one variable. Literal from my example: variable '$b' = the value of array1's key that equals whatever is assigned to '$a': $b=$Array1[$a] variable '$c' = the value of array2's key named the value of variable '$b': $c=$Array2[$b] variable '$d' = the value of array3's key named the value of variable '$c': $d=$Array3[$c] So... is it possible to build up the value of var $d with one statement instead of 3?
  10. The most aesthetically pleasing thing is to keep all your scripting out of your html. You could do something like this: <script language="php">include('my_fantastic_script.php');</script> <html> <head> <title><?=$title?></title> <link rel="stylesheet" href="<?=$stylesheet?>" type="text/css" /> <script type="text/javascript" src="<?=$javascript?>"></script> </head> <body> <div id="wrapper"> <div id="left_col"> <h1><?=$h1_title?></h1> <?=$content?> </div> <div id="right_col"> <?=col_content?> </div> </div> </body> </html>
  11. These statements... $b=$Array1[$a]; $c=$Array2[$b]; $d=$Array3[$c]; combined into one statement like: $d=$Array3[$Array2[$Array1[$a]]] ??? I know my example isn't valid, but is it possible to do this kind of consolidation?
  12. If all your trying to do is pass a value from one page to the next, you should do that in a SESSION var, not POST and definitely not GET.
  13. This is why I hate Wordpress... it's promotion of spaghetti-style coding. Ugh, it hurts my eyes to see all that php inline with html.
  14. @ thorpe: I'm curious about Git... Can it integrate with Eclipse like Subversion?
  15. Subversion. http://subversion.apache.org/features.html Quoted from their site: "File locking. Subversion supports (but does not require) locking files so that users can be warned when multiple people try to edit the same file. A file can be marked as requiring a lock before being edited, in which case Subversion will present the file in read-only mode until a lock is acquired."
  16. How do you keep overwriting each other's work? Are you not using a check out/in system... versioning... CVS... a repository...?
  17. Ok, took a nap & solved my own problem... Forget about all the other stuff about turning a string into a var, etc. Wrote this function to run on my original array and it works exactly as I want: function arrayGetNestedByInt($int, $Array) { foreach ($Array as $key => $val) { if(array_key_exists('children', $Array[$key])) { if($key == $int) return $Array[$key]['children']; else return arrayGetNestedByInt($int, $Array[$key]['children']); } } } It's so stupidly obvious I can't believe it took me this long to get there. Sheesh, I need to go to bed earlier at night... What's even worse is that no one here even bothered with it... I hope I joined the right forum.
  18. No input at all from anyone on this? Is it because I'm a newb on this forum?
  19. Ok so with the "NewArray" above, I'm running this loop: $str = NULL; foreach ($NewArray as $key => $var) { if(is_integer($var)) $var = "[".$var."]"; else $var = "['".$var."']"; $var = str_ireplace('id', 'children', $var); $str .= $var; } $strfinal = '$'."Array$str"; Which returns this string: "$Array[5]['children'][7]['children']" So that string is exactly the nested array I want to access, but how do I convert it to a var? I tried a variable variable $FinalArray = $$strfinal; But that doesn't work. Also for S&G, I tried eval, but no luck there either. So can I get any pointers on how to convert the string above to a var?
  20. So I'm trying to write a function that returns a nested array from a nested index in a multidimensional array & I'm having problems... The array: $Array = Array ( [1] => Array ( [id] => 1 [parent] => 0 ) [5] => Array ( [id] => 5 [parent] => 0 [children] => Array ( [7] => Array ( [id] => 7 [parent] => 5 [children] => Array ( [9] => Array ( [id] => 9 [parent] => 7 ) [12] => Array ( [id] => 12 [parent] => 7 ) ) ) ) ) [2] => Array ( [id] => 2 [parent] => 0 [children] => Array ( [3] => Array ( [id] => 3 [parent] => 2 ) ) ) ) What I want to do is create a function that takes an int and returns the children for that index. For example, I could pass 7 and get back $Array[5]['children'][7]['children'] or pass 5 and get just $Array[5]['children'] i've gotten as far as this function: function searchArray($int, $Array, $strict=false, $path=array()) { if( !is_array($Array) ) { return false; } foreach( $Array as $key => $val ) { if(is_array($val) && $subPath = searchArray($int, $val, $strict, $path) ) { $path = array_merge($path, array($key), $subPath); return $path; } elseif ((!$strict && $val == $int) || ($strict && $val === $int) ) { $path[] = $key; return $path; } } return false; } $NewArray = searchArray(7, $Array); But it just returns this, which may be helpful, I'm just not sure how to iterate it into the result I'm looking for as stated above: $NewArray = Array ( [0] => 5 [1] => children [2] => 7 [3] => id ) Any ideas? Thanks!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.