Jump to content

NikkiLoveGod

Members
  • Posts

    54
  • Joined

  • Last visited

Everything posted by NikkiLoveGod

  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
  16. Thanks for a quick reply there Mastodont! So, in newsController I control wether to show the presentation view, which is the listing, and then the add_edit_news view. Then at controller I assign different variables to use at the form action url, and use empty variables to populate the form when just adding a new, and when editing i just give the variables some value. Or should I have some check there whether the variables are set, then echo them? Does empty variables give a security issue, as they raise a php warning? Then how about if I have some small "info" things, like "Thank you for adding the news!", and I would like them to appear like in front of the "add_edit_news" view. Should I have a separate view for that too? I dont want to copy the add_edit_news view inside this one, so that I dont have to update two things, which is the whole point in these. Thanks again! Sorry to ask "stupid" questions, and make people explain things like to a 5 year old kid
  17. Oh, and I do not prefer variable variables over arrays in all situations, just where I have to echo alot of stuff, I would rathe write $name than $array['name']. But to store the data, then ofcourse arrays.
  18. Would you call that variable variables? Haha! sorry about that! I was thinking a bit too closely on what I did earlier on. So what I would do, is something like foreach($_POST as $key => $value) { //Do some altering to they keys, like put them all to caps, or smalls, //replace some text or something like that //$_POST['POST']; $key = strtolower($key); //Then assign them $$key = $value; } //and now you can access them like normal variables, but with lowercase echo $post; hehe, sorry to make up a bad examples But anyway, in that the idea is that you make some alters to the keys and then you can use em more easily. I hope I didnt make things more complicated
  19. Hi! I'd like to think that variable variables are a god bless! They are awesome. For example, if you have a from with field like $id . '_name' and stuff like that, you can create a loop and make those variables into $name = $value, and do something with its ID. for example: <?php foreach($_POST as $key => $value) { $key = explode('_', $key); $id = $key[0]; $field = $key[1]; //Do something with them. Put them into a DB for example according to the id or smtn. } ?> And I think these are just ANOTHER way of doing something. I like these a bit more than just arrays, but im sure you can get the same result with arrays.
  20. Hi all! I am having some trouble figuring out the MVC thingy. There is a couple of things that keep bothering me. Mainly about templates. How do I implement different "views" of the same "category". Like I have a news module in my site, and in the news module, I need to list, add and edit news. So that is 3 different views. So, I have situation where I have a frontController, that assigns a pageController, in this situation newsController. The FrontController also assigns newsView. newsController makes the newsView load the layout template. Now it is time to add the "specific template", like add_news, edit_news and so on. So should I create each "view" a separate template file in a "news" folder for example? Or should I have one template file for news, and have a check there what to show? So that way, I will have like a billion different files on a rather small site. It feels rather strange, as I have always had just one file, and in there I have had like an switch case to put up a different view. How is these things done normally? I couldn't figure out from Zend FW nor CodeIgniter. Explanation is very welcomed! Thanks! -NikkiLoveGod
  21. You need to put a .php extension to any file that you run php on. Unless you embed it with <script>... but it doesnt execute any php code with in <?php ?> tags unless the extension is .php. You could try renaming the files to a bit more logical way, and putting up the extension correctly. Try checking the page source from your browser, and you can see your php there, and that is wrong. PHP is a serverside language and is processed before sending the page back to user and thus not visible for user. good luck! Sorry if it was confusing -Nikki
  22. or you can do a loop, that will go through all the GET data ( the sent variables ) and assing a variable out of them. So $_GET['lol'] becomes $lol and so on. something like this: <?php foreach ( $_GET as $get_key => $get_val ) { $$get_key = $get_val; } ?> This way you can use the $variable names... cheers! -NikkiLoveGod
  23. I'd say its a rights issue. You dont have the sufficient rights to mvoe the file into the specified folder. You might want to consult your service provider to check that the server has the rights for that folder. ( that is, if you cant check your self ) -Nikki
  24. You can make yourself a config file, where you make a variable for every path to your files. for example, yuo make a config.php with $connpath = 'home/config/connection.php'; $someotherfile = 'someotherpath'; then you just include this config file to the files and use include $connpath; and all you have to change is the config file. I'd do it that way, if someone has a better solution, please do tell it -NikkiLoveGod.
  25. Also, take the blue / red / pink add off from the left away! And there is a small pixelmistake in the itemboxes, the left line is one pixel off from the corner. And I personally find it irritating when the menutext is downsizing when hovering. The colorchange is very sufficent for it, no need to change the fontsize too. But other than that, good job!
×
×
  • 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.