Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts

    What php mysql functions are usefull

    Hy all

    I'm just starting MySQL, and wondering, what are the most useful php mysql functions for beginner.

    I'm using mysql_query for now, and i can see that it's very usefull, couse you can do almost anything with it.

    What other functions are useful, and can save you writing lot's of mysql code.

    Thanks for the info

  • #2
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    Well they are all useful depending on what you plan to do. A very handy tutorial(http://www.tizag.com/mysqlTutorial/).

    mysql_error() is handy for debugging error messages
    of course... mysql_connect()
    mysql_real_escape_string() good for protecting against SQL injections
    mysql_num_rows() for loops with the table rows along with mysql_affected_rows()
    and of course mysql_close()

    for a list off all php-mysql commands look at http://php.net/mysql


    -Adam
    Why not thank me?

    http://adamsworld.name

  • #3
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    I found out that mysql_fetch_array is good for showing results from tables.

    Also, is limiting number of rows shown PHP or MySQL thing?
    I mean should i use MySQL to limit shown queries, and creating Next and Previous links, or do i use PHP for that?

    Thanks for the info

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    You should use MySQL to limit the results. All you need is the total number of results, and the current results based on what page you're on.

  • #5
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Thanks :top:
    I gotta a few more questions in repertoár.

    OK, now i'm building a simple admin system, where admin can see sent messages. how do i cross reference admin's last login time with new messages time (easiest way).

    Do i create two rows for admin, like Last Time, and New Time where Last Time would be time when admin logged off, and New Time would be when admin logged on, and based on the values of last time, messages that are sent after that time, are going to be bolded like "new messages", is that a good way, or do you have any smarter suggestions?

    Also i read about databases, a lot, and i shouldn't name table rows from two databases same, or i can do that.

    Let's say for some reason i named time from admin database, and time from message database something like newTime, is that something that should be avoided?

    Thanks
    Last edited by matak; 08-18-2007 at 08:58 AM.

  • #6
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    For your first question, is the whole log in log out time just to see whether the message is 'new' or not? If so, why not just add field to the DB table where the message is stored that specifies whether the message has been viewed or not?

    The default for the field would be that the message hadn't been viewed, and when the site retrieves a message from the database for the admin to view it, the field's value would be switched to saying he had viewed it.

    HTH
    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • Users who have thanked whizard for this post:

    matak (08-20-2007)

  • #7
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Ok, now i made a field Status for message, and default i set default value to 0 (or even maybe "unread"). What mysql function can change that status to 1 (or "read").

    I've found this code which i need to call on admin message request query.

    something like this

    Code:
    $sql = SELECT * FROM messages
    //this is the code i found
    $update ="UPDATE messages SET status='1' WHERE status='0'" 
    
    if (admin requests messages) {
      mysql_fetch_array ($sql) or die..
       mysql_query($update) or die---
    }
    is that the best, and the only way to update status from 0 to 1 or are there better ways?

    Thank you all. I'm learning mySQL, and i'm fascinated how smart it is

    Edit: Ok, sorry i didn't mention before, bu also if i had more users than admin, would then be a proper way to set NewTime and LastTime, or some other way, like this update. It looks logical that update can work for one user, but when there would be more users, than it would be hard to make such a system
    Last edited by matak; 08-18-2007 at 03:16 PM.

  • #8
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Use the time. Store the time when the admin logs in or logs out. You can update it on each page or only when the admin logs out, it's up to you. Then just select the messages that were posted since the last time the "time" was updated for that user. For your other question the query would be something like this:
    PHP Code:
    $update ="UPDATE messages SET status='1' WHERE messageId = '123'"

  • #9
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Thanks for the tip. I'll post back here when i test the codes you provided.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •