Home > Archive > PHP SQL > November 2004 > newbie: 2 tables as 1 result to count... how to?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
newbie: 2 tables as 1 result to count... how to?
|
|
|
| I need to check for username in 2 tables (user_basic and user_temp)
before I can alow incoming user to register new username, well, here is
what I had before I'w created temporary table:
$uname_check = mysql_query("SELECT uname FROM user_basic Where
(uname='$uname')");
if (mysql_num_rows($uname_check) > 0) { ...
but now, that mysql_num_rows isn't "working"...
now I have this lines:
$uname_check = mysql_query("SELECT uname.user_basic,uname.user_temp FROM
user_basic,user_temp Where (uname='$uname')");
if (mysql_num_rows($uname_check) > 0) { ...
and I'm geting this worning and my script fails in checking:
"mysql_num_rows(): supplied argument is not a valid MySQL result
resource in..."
can anyone help me?
--
Jan ko?
http://fotozine.org
--
| |
|
|
Jan:
You should check for errors after mysql_query(). That way you would see
that MYSQL is complaining about the syntax of your query.
Make two separate queries, one for user_basic and one for user_temp,
and add the number of rows returned from each query:
$uname_check1 =
mysql_query("SELECT uname FROM user_basic Where (uname='$uname')");
$uname_count1 = mysql_num_rows($uname_check);
$uname_check2 =
mysql_query("SELECT uname FROM user_temp Where (uname='$uname')");
$uname_count2 = mysql_num_rows($uname_check2);
if ($uname_count1 + $uname_count2 ) > 0) { ...
---
Steve
| |
| Hilarion 2004-11-19, 8:57 am |
| > SELECT uname.user_basic,uname.user_temp FROM
> user_basic,user_temp Where (uname='$uname')
should be:
SELECT uname
FROM user_basic
WHERE uname='$uname'
UNION
SELECT uname
FROM user_temp
WHERE uname='$uname'
Hilarion
|
|
|
|
|