...

View Full Version : explode problem



urgido
01-08-2007, 12:04 PM
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

kaisellgren
01-08-2007, 12:11 PM
$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!

urgido
01-08-2007, 12:23 PM
Is there a way to know if some user is not in the db and return error?

kaisellgren
01-08-2007, 02:51 PM
$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!

marek_mar
01-08-2007, 06:51 PM
if(mysql_fetch_array($reuslt) !== false)

Would be a better condidtion.
mysql_num_rows() always returns something, therefore it's result is never empty.

MRMAN
01-09-2007, 10:27 AM
or you could do


if (mysql_num_rows($result) <= 0)
echo "User " . $key . " does not exist in our database you bananahead !";
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum