Jump to content

Matic

Members
  • Posts

    42
  • Joined

  • Last visited

Posts posted by Matic

  1. great, I get the part where you convert to strtotime format which is the number of seconds since January 1 1970 00:00:00 UTC etc... Then you divide by 3600 to get hours...

     

    Problem is I don't know hot to convert this to my subtracted result back... As it is now, it only shows the hours since January 1 1970 00:00:00...

  2. OK I solved my problem like this:

    $current_time = date_create(date("Y-m-d H:i:s"));
    $last_time = date_create(date("Y-m-d H:i:s", strtotime(get_last_update_time($user_name))));
    $result = date_diff($current_time, $last_time);
    
    echo $result->format('%Y-%m-%d %H:%i:%s');
    

     

    but it echoes my result like so: "00-0-0 03:40:56", with all the days etc.. How do I format this so that it only show hours, lets say like so: "232156". With all the days, months years, formatted to hours?

  3. I want to subtract database timestamp from current server time. The formatted time that is returned to me from my database is "2013-09-01 22:05:39" and I use function date("Y-m-d H:i:s"); so that my server time I get in php is in the same format.

     

    How can I get a result in hours? Example: 2013-09-01 22:05:39  minus 2013-09-02 22:05:39 equals 24 hours ???

     

  4. It's cause you are reassigning the value of the output with every loop.

    $_SESSION['output'][] = $outputs; // Need the [] so that it adds a new array element rather than over-writing the previous output.
    

    Then you would need to either call a specific array key or use a foreach loop on the $_SESSION['output'] to echo out the outputs.

    yes this! Now how do I do this properly with foreach statement? This is what I am asking this whole time, though other answers in this thread helped me greatly also

  5. Thanks for all the help but my session variable still shows only the last element of my row. When it is echoes directly it is okay but when it is stored in session it only displays the last element of array...

     

    I make my session variable store array like so:

    $outputs = array();
    while($row = mysql_fetch_array($query))
    {
    
        $_SESSION['row_id'] = $row['id'];
        $outputs = $row['sport_ime'].' '.$row['sezona'].'<a href=../view/modifikacije.php> Edit</a><br>';
        $_SESSION['output'] = $outputs;
    
    }
    

    and then on another page I call that variable like so:

    $outputs = $_SESSION['output'];
    echo  ($outputs);
    

    It just echoes one row! It is the last entry in my database, why doesn't it want to echo everything? People at another site say that I am repeatedly overwriting the same variables! But I don't know how to avoid that

  6.  

    How did you echo it? Can I see the code?

    Also show us the result of:

     

    • // dump the data
    • echo '<pre>'.print_r($_SESSION, true).'</pre>'; 

     

    Well yes I echo in my html file like so:

    <?php echo($_SESSION['result']); ?>
    

    in my backend php I do the session storage like so:

    while($row = mysql_fetch_array($query))
    {
       $_SESSION['result'] = $row['sport_ime'].' '.$row['sezona'].'<br>';
    }
    
    // and then redirect back to html where it should echo the stuff
            
    header('Location:../view/vnos.php',true,303);
    exit;
    

    The results you requested were just array => 0 and 1 for the last element in my array

  7.  

    Fetch all rows and push it inside an associative array.

     

    Try,

    $query = mysql_query("SELECT * FROM sport");
    
    $_SESSION = array();
    
    while($row = mysql_fetch_array($query))
    {
       $_SESSION[] = array($row['sport_ime'],$row['sezona']); 
    }
    
    // dump the data
    
    echo '<pre>'.print_r($_SESSION, true).'</pre>';
    
    

    Or....for best performance use mysql_fetch_assoc() function.

    while($row = mysql_fetch_assoc($query))
    {
       $_SESSION[] = array($row['sport_ime'],$row['sezona']); 
    }
    

     

    That is all fine and dandy but if I call this session in another file and try to echo it, it still displays only the last element of the array...

  8. Did you even try what I posted, I have a line break after each row so they are all on new lines.  You will need to be a bit more specific as to how you want it formatted than simply saying you want it on a new row, cause that is what I gave you.  Do you want it in a new table row or simply a new line on the screen, what?

    Oh damn I didn't see that break tag there, my bad! Would you also be so kind to post a solution, if you know one, how to make every row clickable so that user can access entries and modify/delete them?

     

    Also does anyone know how to store that line

    echo $row['sport_ime'].' '.$row['sezona'].'<br>';
    

    inside $_SESSION variable correctly?

  9. $query = mysql_query("SELECT * FROM sport");
    
    while($row = mysql_fetch_array($query))
    {
       echo $row['sport_ime'].' '.$row['sezona'].'<br>';
    }
    

     

    :D no no, echo row just lists entire database in one row like so: "foo1988bar2000etc..." I want each new id in a new row ... I know there is something with for each() statement I just can't format it right

  10. Hey, I want to list all of my database entries to a nice html format. For every unique id there is one row displayed out from my database to my php/html. I just don't know how to do that. I tried using while loop and foreach I just don't know how to properly structure them... My query and php code looks like this:

    $query = mysql_query("SELECT * FROM sport");
    
    while($row = mysql_fetch_array($query))
    {
        $result = $row['sport_ime'].' '.$row['sezona'];
    }
    
  11. Lets say I have a form in form.php and when I click submit all inputted data is sent to model.php for database manipulation etc.. and then when everything is done the model.php redirects user back to form.php using function:

    header('Location:form.php');
    
    

    How in the blazing hell can form.php recognize I was redirected there from model.php ? I am so lost about this for so long now, I tried $_SERVER['HTTP_REFERER'] and everything and I just get an echo with my current page location. I want to get an echo of the model.php on my form.php

     

     

  12. If all your controllers are named: index.php, start.php, .. then you don't need a front controller as Apache already does all what your front controller would do. The reason there is a front controller in some systems is because something has to translate /foo/bar to (new Foo)->bar(); or foo_bar(); when your controllers however are files, then your front controller is obsolete.

     

    Using includes you would center the logic required to redirect the user to the correct page, like when he is not logged in.

     

    Great, I thought something was not right here :) So let me get this, using so called "front controller" in my case doesn't have to do nothing else but "center the logic required to redirect the user to the correct page" ?? Or maybe to make nicer URLs and code editing, since everything will be included from www.index.php/ forward.. It is still a nice practice and a feature to have right?

  13. You could defer more specific processing to the child controller if you wanted. In my example above, I have two entries for shop.php, both begin '/shop/(\d+)' with the URL match. If you wanted, you could have just a single entry in your main control matching that prefix, then inside shop.php test more specific conditions such as '/shop/(\d+)/buy/(\d+)' or '/shop/(\d+)/sell/(\d+)'

     

    So I guess this logic works like that, it expands outward. However I really don't want to overcomplicate things for now and just use includes and if statements. Your arrays are fine though but atm I have problems understanding nested stuff, I will however do it in the future.

     

    But would I also be with the same result if I used includes like I described above?

  14. - Depends what you bought. If it's shared hosting then you have some flexibility but really not that much. Dedicated hosting means you can do whatever you want.

    - Unless you have really locked-down shared hosting (less and less common these days) then you can make any directory "public" or "private".

    - Public directories can contain whatever you want. They probably shouldn't have views/templates because those files are no good if executed directly. In fact they might even have some code in them that shouldn't be seen at all. Generally such directories have things like CSS and Javascript and image files instead.

    - Yes, making a directory public or private is done in Apache through .htaccess (or a server-level configuration file). That's what you would use to block browsing.

     

    But the public directories must contain controllers then, or some sort of web pages to view? Because if it doesn't matter, what is stopping me from throwing everything in the private file and never worry about security?

  15. I am curious about server access. Lets say you buy a hosting service, can you manually decide which directories will be public and which will be off limits? Do public directories have to include views (templates)? Because in a lot of frameworks I see views in private directories. Can you block access via .htaccess and only allow users to browse certain pages? How do you prevent them from browsing your entire php app files?

     

    I know this is a lot of question but a simple overview about directory structure in apache servers will do, since I am building one.

  16. Hey, I was asking a lot of questions lately on this forum and it all boiled down to this one. We all know it is hype to implement front controller or master page index.php that handles all the requests to all the pages and reroutes you etc... All this for cleaner urls, easier code handling...

     

    But what if you have a browser game with a lot of locations and variables, states, conditions etc.. I can't write a million if statements or switch statements on my index page. What if I implement such page structure as described below? Basicly you don't have single point of entry or one front controller but more main controllers that connect to subcontrollers:

    
                                                                      if location forest
                         if loged in                             |---------------------------- forest.php
                      |------------------ start.php -------------|
                      |                                          |    if location home
                      |                                          |-------------------------- homebase.php
                      |                                          |   
                      |                                          |    if location else
    index.php---------|                                          |------------------------- anywhere.php
                      |
                      |  if in fight
                      |------------------- combat.php
                      |
                      |  if not loged in
                      |------------------- homepage.php
    

    Why would all pages have to go through index.php? This would be a big mess! Divide pages based on location, for example my start.php page will decide where to redirect further. So in this case I have two bigger controllers not just one front one. Is this still a good convention? I mean is this still a good front controll design or is it better to leave all the redirects to index.php?

  17.  Also your update_save function should receive it's data from the controller and not use $_POST or $_GET internally since only your controller knows about $_POST and $_GET.

     

    A model should not issue redirects since redirect's are the responsibility of the controller.

     

     

    1. How else am I supposed to tell the controller and the view to only show information if the user didn't or did click post button on my form?

     

    2. Model issued a redirect because it is wise to implement post-redirect-get pattern, without it my user could just click refresh endlesly and the database would have duplicate entries... Is there any way around this?

  18. You have to check the url to determine which page they want to go to. Unless your site consists of only two pages, one for those logged in, and one for those not.

     

    If my users have an active session I can also determine which page to redirect them to based on their choices. Just store their actions in a variable and call that variable in index.php

     

    And the index.php will display apropriate include file! The url will then always be index.php/

×
×
  • 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.