message blog

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nathj
    Recognized Expert Contributor
    • May 2007
    • 937

    #16
    Originally posted by insane
    hi,
    thanks.its fine thing for me to do my job..but i want to get my output in desending order and want limit it.but my nestd loop which retrieving data from two table.plz help me....

    [PHP]$query="select p.name_poster,p .email,p.contac t_no,m.date_pos t, m.details from post_details p, message_blog m where p.contact_no=m. contact_no ";
    [/PHP]
    and in bangladesh where current time is GMT+6 hrs
    how can i do it plz
    Hi

    You need an ORDER BY clause and a LIMIT clause:
    [php]
    $query="select p.name_poster,p .email,p.contac t_no,m.date_pos t, m.details from post_details p, message_blog m where p.contact_no=m. contact_no ORDER BY p.name_poster DESC LIMIT 0, 10";

    [/php]
    this will get the results order by the posters name starting with Z and working backwards through the alphabet. It will also only return a maximum 10 records.

    I hope that helps
    nathj

    Comment

    • insane
      New Member
      • Feb 2008
      • 18

      #17
      Originally posted by nathj
      Hi

      You need an ORDER BY clause and a LIMIT clause:
      [php]
      $query="select p.name_poster,p .email,p.contac t_no,m.date_pos t, m.details from post_details p, message_blog m where p.contact_no=m. contact_no ORDER BY p.name_poster DESC LIMIT 0, 10";

      [/php]
      this will get the results order by the posters name starting with Z and working backwards through the alphabet. It will also only return a maximum 10 records.

      I hope that helps
      nathj
      thanks NATHJ
      its working ....
      but i cant get the local time and date its showing 0000-00-00. and ip is blank in my local server.
      please help me..
      hey! dont get angry..i know u r busy

      Comment

      • nathj
        Recognized Expert Contributor
        • May 2007
        • 937

        #18
        Originally posted by insane
        thanks NATHJ
        its working ....
        but i cant get the local time and date its showing 0000-00-00. and ip is blank in my local server.
        please help me..
        hey! dont get angry..i know u r busy
        Hi Insane,

        Glad to hear we a re making good progress with this.

        I'm not sure I fully understand the issue so here's a couple of questions.
        1. Are you trying to get the date ut of the table for display on the screen?
        2. How are you storing the date? When you look at the field what is in it and what data type are you using?
        3. How do you input the date into the table?
        As a quick pointer you should check out the php date() function and the MySQL date_fromat() function.

        Using the latter of these you could do something like:
        [php]
        $query="select p.name_poster,p .email,p.contac t_no,
        date_format(m.d ate_post, '%Y-%m-%d') as postdate, m.details from post_details p, message_blog m where p.contact_no=m. contact_no ORDER BY p.name_poster DESC LIMIT 0, 10";
        [/php]

        Assuming the field is a date type this will give you the output of YYYY-mm-dd as the postdate field.

        Cheers
        nathj

        Comment

        • insane
          New Member
          • Feb 2008
          • 18

          #19
          hi.
          now im trying to insert the cueernt local time and date into database automatically when the user will submit their post.

          please help me sir

          Comment

          • nathj
            Recognized Expert Contributor
            • May 2007
            • 937

            #20
            Originally posted by insane
            hi.
            now im trying to insert the cueernt local time and date into database automatically when the user will submit their post.

            please help me sir
            Hi,

            when I do this I get a variable in php and define it as the current date and time and then use the variable in the insert statement.
            [php]
            $lcCurrent = date('Y-m-d H:l:s');
            [/php]
            this variable would then say '2008-02-07 10:57:10' (my local time as I post).

            Hope this helps
            nathj

            Comment

            • insane
              New Member
              • Feb 2008
              • 18

              #21
              hi,
              i did it as u say.
              the field is timestamp,and i want to show it to the screen.

              the problem is that i am not getting the current local time as
              in my country the current time is 8:00pm but its showing 13:00:00 and i want to get it 12 hr format

              thanks sir 4 ur help

              Comment

              • nathj
                Recognized Expert Contributor
                • May 2007
                • 937

                #22
                Originally posted by insane
                hi,
                i did it as u say.
                the field is timestamp,and i want to show it to the screen.

                the problem is that i am not getting the current local time as
                in my country the current time is 8:00pm but its showing 13:00:00 and i want to get it 12 hr format

                thanks sir 4 ur help
                Hi,

                PHP is a server side language so the local time is the time the server thinks it is. Most likely this is based on its physical location. It is possible to correct the time with a simple adjustment of adding or subtracting the relevant number of hours.

                To use 12 hour time rather than 24 hour tme simply replace the H from the code snippet in my last post with either h (leading 0's) or g (no leading 0's).

                Cheers
                nathj

                Comment

                • insane
                  New Member
                  • Feb 2008
                  • 18

                  #23
                  actually i dont know how to substract time here

                  and one i want to get the o/p through html and css
                  how can i do it

                  Comment

                  • nathj
                    Recognized Expert Contributor
                    • May 2007
                    • 937

                    #24
                    Originally posted by insane
                    actually i dont know how to substract time here

                    and one i want to get the o/p through html and css
                    how can i do it
                    Hi,

                    I'm still not sure at which point you want to adjust the time - when the values are loaded to the server or when they are retreived? Personally I would do it when they are loaded to the server and then have a note on the site indicating the timezone of the server this would make things clear for the user.

                    As for the output in HTML and CSS, this is easy. Have you read the Data Abstraction article I referenced earlier?

                    With the returned array you can simply issue code as follows:
                    [php]
                    <?php
                    // assume there is a return called $laResults
                    foreach($laResu lts as $laRow)
                    {
                    echo $laRow['fieldname'] ; // this is the name of the field on the select statement
                    }

                    [/php]
                    That echo will simply print the contents of the field for each row in the result set. To add formatting aroun it simply include the HTML is the echo. This HTML can use enay of you selectors, classes or psuedo classes from you CSS - simply how you would write HTML.

                    Cheers
                    nathj

                    Comment

                    • insane
                      New Member
                      • Feb 2008
                      • 18

                      #25
                      hi thanks,
                      i want to load the local time and date in database and also want to retrieve it

                      Comment

                      • nathj
                        Recognized Expert Contributor
                        • May 2007
                        • 937

                        #26
                        Originally posted by insane
                        hi thanks,
                        i want to load the local time and date in database and also want to retrieve it
                        If it's loaded as local then it will be retreived as local, simple. The question is local to where/who? I think local to the server or local to the gepgraphic area your site is aimed at. So I have a site aimed at UK residents about events happening in the UK so I would ensure that the imtes on the site are UK times.

                        If I remember correctly your sever was 5 hours ahead of where you are. So try the following to get the variable to input into the database:
                        [php]
                        $lcLocalTime= date('Y-m-d H:i:s', time()+ (60*60*5));
                        [/php]

                        Try it out and you will see that the results is five hours ahead of local time. This is valid for a datetime field. You wouldneed to play around with mktime() to get this into a timestamp field format.

                        If you use the Datetime field you can simply retreive using date_format to arrange it as you want and away to go.

                        Cheers
                        nathj

                        Comment

                        • insane
                          New Member
                          • Feb 2008
                          • 18

                          #27
                          hey thanks a lot .its working
                          but
                          yet in problem as taking (foreach) not showing error but result is not matching
                          my code is
                          [PHP]while($row=mysq l_fetch_array($ result))[/PHP]
                          [PHP]echo $r[name_poster];[/PHP]
                          [PHP]foreach ($row as $r)[/PHP]
                          like another field
                          but not getting the required o/p

                          Comment

                          • insane
                            New Member
                            • Feb 2008
                            • 18

                            #28
                            hi,
                            here im in trouble with another problem with my login system.its simply working.i've created a registration form and a login form with database table user of fields name,email,user id,password.but now i want to make an admin panel to control the members page and want to retrieve the forgotten password.

                            plz help me bro...

                            insane

                            Comment

                            • nathj
                              Recognized Expert Contributor
                              • May 2007
                              • 937

                              #29
                              Originally posted by insane
                              hi,
                              here im in trouble with another problem with my login system.its simply working.i've created a registration form and a login form with database table user of fields name,email,user id,password.but now i want to make an admin panel to control the members page and want to retrieve the forgotten password.

                              plz help me bro...

                              insane
                              Hi,

                              I wouldn't retreive a password from a database. The password should be hashed in the database so there is no way for you to know what it is anyway.

                              The system I usually go for is one where the password is reset. This new password is emailed to the users specified email address and then it is hashed and stored in the database. The admin panel then needs to allow the user to change the password.

                              This is the process I use. the next step is to read up on the sha256 option in php and also figure out the process to generate a random password generator.

                              I hope this helps
                              nathj

                              Comment

                              Working...