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 6 of 6

Thread: explode problem

  1. #1
    Regular Coder
    Join Date
    Aug 2005
    Posts
    257
    Thanks
    8
    Thanked 0 Times in 0 Posts

    explode problem

    Hi..

    Look, I have the following code:
    $sql= "SELECT * FROM users WHERE nickname='$user'";

    this code is for a private messenger so users can send messages in format nick1,nick2,nick3 so I want to know how i can explode the "," and execute one sentence per "," found.

    Regards

  • #2
    Regular Coder
    Join Date
    Jan 2006
    Location
    Finland, Hollola
    Posts
    285
    Thanks
    8
    Thanked 0 Times in 0 Posts
    PHP Code:
    $users mysql_real_escape_string($_POST["users"]);
    $users_array explode(",",$users);
    foreach (
    $users_array as $key)
    {
    $sql "SELECT * FROM users WHERE nickname='$key'";

    anYthing else what can I do for Ya!
    PHP 5 & MySQL 5 (Y)

  • #3
    Regular Coder
    Join Date
    Aug 2005
    Posts
    257
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Is there a way to know if some user is not in the db and return error?

  • #4
    Regular Coder
    Join Date
    Jan 2006
    Location
    Finland, Hollola
    Posts
    285
    Thanks
    8
    Thanked 0 Times in 0 Posts
    PHP Code:
    $users mysql_real_escape_string($_POST["users"]);
    $users_array explode(",",$users);
    foreach (
    $users_array as $key)
    {
    $sql "SELECT * FROM users WHERE nickname='$key'";
    $result mysql_query($sql);
    if (empty(
    mysql_num_rows($result)))
     echo 
    "User $key does not exist in our database you bananahead !";

    anYthing else I can do for Ya!
    PHP 5 & MySQL 5 (Y)

  • #5
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    PHP Code:
    if(mysql_fetch_array($reuslt) !== false
    Would be a better condidtion.
    mysql_num_rows() always returns something, therefore it's result is never empty.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #6
    Regular Coder
    Join Date
    Jan 2006
    Location
    Preston, Lancashire, England
    Posts
    285
    Thanks
    0
    Thanked 0 Times in 0 Posts
    or you could do
    PHP Code:
    if (mysql_num_rows($result) <= 0)
     echo 
    "User " $key " does not exist in our database you bananahead !";



  •  

    Posting Permissions

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