Jump to content

NikkiLoveGod

Members
  • Posts

    54
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

NikkiLoveGod's Achievements

Member

Member (2/5)

0

Reputation

  1. Hi all, I'm at the verge of my skills with the next dilemma, and need help from fine ppl like you. I need to build a highly flexible reporting system that has a "default" way of forming a report, and then there's a possibility for overwriting the default way. The main idea is that I have a default definition file that says something like <?php $datas = array("category" => array(array("type" => "value", "value" => "this_value"), array("type" => "value", "value" => "another_value")), "another_category" => array(...)); ?> and I include this definition file in a report file, which then includes a second file, a datafetcher which is then somehow supposed to get that value with a defined way. The trick is, that I might have 100 of these variables, and some of them, or all of them, have to be redefinable by another included file, another datafetcher. These customized datafetchers are there because I might want to create a same report to multiple targets which varies in their datas locations. Ofcourse there's other "types" also, like "filters", which gets the same data as the normal "value" types, but filters it somehow. I'm having hard time figuring out how to do this. How should I get the value for "this_value" and "another_value". Idea is to get an array looks something like this: <?php $datas = array('category' => array('this_value' => 1234, 'another_value' => 4321), ....); ?> So it should first take into account what type the value is, then start building it accordingly, and then what value it is so it know what to get. Both of these should be overwritable. Should the way to get the data be some functions like this_value(); another_value();? Then how would I take the type in account? Or overwriting as I can't redeclare functions (procedural). Or maybe some switch -conditional that has the case's included in order? Im probably sending very confusing message here, but I am confused If you could give me your 2cents and point me to the right direction, it would be awesome! Or some reference data where I can learn more would be cool too.
  2. Managed to get it working, problem lies with in the foreach statements way of handling the variable, as it is not a reference, but a copy. (http://fi.php.net/manual/en/control-structures.foreach.php) This is the solution $buffer = 5; foreach($compareArray as $needleRow => $needle) { //skip the unsetted rows if(in_array($needleRow, $unset)) { continue; } $start = $needle['start']; $end = $needle['end']; $changes = false; foreach($compareArray as $haystackRow => $haystack) { $needle = $compareArray[$needleRow]; if($haystackRow == $needleRow) { continue; } echo 'comparing ' . $needleRow . ' -> ' . $haystackRow . "\r\n"; if($haystack['start'] < $start && $haystack['end'] >= ($start - $buffer)) { $start = $haystack['start']; $changes = true; } if($haystack['end'] > $end && $haystack['start'] <= ($end + $buffer)) { $end = $haystack['end']; $changes = true; } if($changes == true) { //Update the correct values $compareArray[$needleRow]['start'] = $start; $compareArray[$needleRow]['end'] = $end; //Unset the combined row unset($compareArray[$haystackRow]); //And store the row, so we can actually skip it with in the foreach $unset[] = $haystackRow; }
  3. Do you guys have any salvation for me on this one, or is this actually a hard question, and not just my own dark moment? I've been stuck with this for ages
  4. Hi all, Im having a bit of trouble figuring out this logic, and its getting rather annoying, to be honest. This should be simple, but maybe i've been just too stuck on this. I need to combine my array, according to its values. I have this array: $compareArray = array( array('start' => 90, 'end' => 100), array('start' => 80, 'end' => 95), array('start' => 70, 'end' => 75) ); And this is what I want to get: $destArray = array( array('start' => 70, 'end' => 100) ); So basicly, i want to go through the array, check if the arrays start or date values are with in the range of 5, if so, combine them into one row. This is where I am at the moment: $buffer = 5; foreach($compareArray as $needleRow => $needle) { foreach($compareArray as $haystackRow => $haystack) { if($needle['start'] < $haystack['start'] && $needle['end'] >= ($haystack['start'] - $buffer)) { $start = $needle['start']; } else { $start = $haystack['start']; } if($needle['end'] > $haystack['end'] && $needle['start'] <= ($haystack['end'] + $buffer)) { $end = $needle['end']; } else { $end = $haystack['end']; } /* SOMETHING TO UNSET THE COMBINED ROW */ } } And im at a mental block, and can't get ahead of this for some reason. The IF -check should be valid, there shouldn't be any problem, but its the logic behind combining the arrays, that I cant figure. These values are actually a range of dates, but for the simplicity, I changed them to just numbers. So, any help here? Thanks alot! EDIT: To clarify the if -checks, it should check if the numbers are like "75 - 95" and "60 - 70", combine them to "60 - 95", or if the numbers are "50 - 90" and "60 - 80" it combines them to "50 - 90", "55 - 70" & "60 - 80" = "55 - 80" "55 - 70" & "40 - 65" = "40 - 70" and so on. BUT if the values are "50 - 70" and "80 - 90" it should leave them separated, because they are not with in the range of 5 of them selves.
  5. Thank you, yet again Mastodont. I'll go with these!
  6. Hi! I was wondering how should I design my database and how to collect info from there in a right way. So I have few products, lets say I have Tiles Y, and there is yellow tile Y, blue yellow tile Y and so on, then there is Tiles X, and there is green tile X, pink tile X. How should I design my database to hold this information? And I need to be able to list all of these products as a single product, like separate colors from each others, and then in another view, I have to combine Tile Y's colors, to show just one product. I am thinkin of putting it into a single product table, where you have the Name, ID, and Color there. And then you would somehow loop through it by doing "loop products and show each as its own product" and then you would have another loop on another view, where you would do "loop products, combine colors into one product". Any pointers? And how would I go about getting and combining the data like that? Thanks alot! Hope you guys dont start to feel like I am making you design my work, I just need one "best practice" and I can come up solutions by that on my own. hehe. -NikkiLoveGod
  7. Thanks a lot Mastodont! You have been most helpfull! Those helped me alot! Now, on to my next problem, and next post! -Nikki
  8. Hi all! More stupid questions about MVC, that I haven't had a clear answer and just have to make my self clear. Right now, I am in a mindset, that the controller asks model for some information, puts it into a variable, and sends it to a views variable. This seems fine to me, but now i am having second thoughts. Should it be more, like that I STORE the data at the model as well? Like if I get the site navigation from the DB, and define what page I am currently on, should I store that information in the MODEL and have a method to call it from there, even from the view, or should I store the the info in controller's variable, and just send it to the view? Thanks alot in advance! -NikkiLoveGod
  9. Ok, i'll try and see what the __get does for me. Anyhow, its clear that I need to put up some default values for them, either by hand or by __get thingy. Thanks alot for all of you guys!
  10. I am imagining a case, where I have made the program by mvc "pattern"(?) and have different views for different things. Like I have a news section that has a newsModel, newsController, newsView. newsController checks the current "method" or action we want to do, and tells the newsView to load it. Now the add_news and edit_news views would be identical to eachother in all other parts, than the form values. So I wouldn't want to create two different template files for adding and editing, where I would have to repeat the same code. So it is just a lot easier to echo some variables inside the template, and then when I am editing, I just provide the variables some values. The values would be inputted to the view by the controller, and the controller would get it from the model, which would then have a method there that would get the data from a database. To get rid of the warning, i might be able to define magic method __call and check if the var is defined, and if it isnt, put '' in there so it is atleast defined. Or does __call affect just another methods? So, did you get anything out of it? What do you recommend?
  11. I kinda thought so too. And I am using it, so I know when I have used one. But does it pose some security threat? And what would you recommend doing in that kind of situation? I wouldn't like to make two separate views for adding and editing, especially when there is practically no other difference, than the fact that there is the values. And I think there are a lot of similar cases. I find it a lot worse to have something like if(isset($var)) ? echo $var : echo ''; on some value field. note: yea, I know the example sucks but anyways :DD
  12. wow, you can really use ${'something' . $var} and it works!? I have never known that! Looks like you always learn something new And yea, use thorpe's, it lookes a ton faster to parse aswell.
  13. you have to make a variable variable out of it, for example. Here's how. <?php $array1 = array(); $array1[0] = "hey hey"; $array1[1] = "hey hey"; $counter = count($array1); for ($p = 0; $p < $counter; $p++) { $varname = 'arraynew' . $p; $$varname = explode(" ", $array1[$p]); } ?> This way you'll have an varible of $arraynew0 that contains array with [0] = hey and [1] = hey. Hope this helps!
  14. Hi! I was thinking, that is it considered to be bad programming design, if I use undefined variables in my code. And do they pose me to some security threats? I would use undefined variables like while echoing stuff. Say I have a "add_news_view" that I want to combine with edit news, and making it edit view, I would just have to populate the form in it. So there would be something like <input type="text" name="header" value="<?= $data['header'] ?>" /> and if I am adding news, those are empty, and if I am editing, I just provide it with the data array that has those values. Or the question might be more of "empty variables" rather than undefined. Both? So what do you recon? Thanks alot! -NikkiLoveGod
  15. Hi! Sorry to get of topic here, but what software did you use to make that diagram? I am looking for a good software to do the diagrams needed in web development, thanks! -NikkiLoveGod
×
×
  • 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.