get just one result

liunx

Guest
is there any way to get one specific name from a database

...for example, I have a table named user_message
and a row called the_user which keeps track of which user posted the message,
but what I want to do is compare the username of the CURRENT_user to the user that posted the message
(ie. a user already in the row the_user )
so that another user cant change the same message.

$check_user_query = "select * from user_message where

the_user = \"CURRENT_user\"";

$check_user = mysql_query($check_user_query) or

die(mysql_error());

if(mysql_num_rows($check_user) != 0){

return "TRUE";

} else {

return "FALSE";

}

When i use this, it always returns true...no matter what value i put in for CURRENT_user

Thanks :hotbounceMake the query read:$check_user_query = "SELECT * FROM user_message WHERE the_user = '$CURRENT_user'";same problemTry this<?php
$qry = "select count(the_user) as verified from user_message where the_user = '$CURRENT_user'";
$result = mysql_query($qry) or die(mysql_error());
$row = mysql_fetch_assoc($result);
if($row['verified'] > 0) {
return "TRUE";
} else {
return "FALSE";
}
?>Also, a general programming rule, you should not check for $var != 0 or $var == 0, it is always best to do $var > 0 or $var < 1. This is due to rounding errors which can sometimes occur (apparently).i think i have an idea for why it always returns true...

here is an explanation of what im trying to do. I have a calender system where ppl can post future events, but they have to be registered and logged in to do so, also if u posted a message, only u can edit it, no other user can touch your message..just like this forum.

I found a calender script at hotscripts where anyone can post a message, there was no user system on this...so I implemented one on it, but it is not complete. I just need to check that the current user is the same as the user who posted the message so they can edit it...

now i think the script i have and you provided me always returns true because every user that posts is stored in that row the_user, and what the script ( i think ) does is check through every entry in row the_user (every message on the calender) to see if CURRENT_user exists, and thus returns true of the CURRENT_user has posted other messages...
so what i need to do is get one specific user from the_user who posted that message and compare it with the CURRENT_user
but I do not know how to query this...

here is a url of my progress
<!-- m --><a class="postlink" href="http://members.lycos.co.uk/aacalendar/">http://members.lycos.co.uk/aacalendar/</a><!-- m -->



Thanks$check_user_query = "select * from user_message where the_user = \"CURRENT_user\"";

that will only return 1 row, it will not check and bring back all of them. yes it checks all rows for that name, but only returns true (1) if it found one.

how do you know wha tthe CURRENT_user is? dos it come from a login? a cookie? a session?

that is where I am lost.i know what the current user is through session

here is what someone else said from another forum:

it will return FALSE if you put in a value for a user that has not posted a message in effect, you are saying "get all the messages for user X, and if there are any, return TRUE"

My reply to previous quote:
so what query should i use to check if the current user is the same as the one specific user that posted the message?


his reply to my question:
select the_user
from user_messages
where message_id = N

you need to specify which message you're talking about

the query will return exactly one result

then compare this in your code to the current user


Thankswhich lead to another question: how do i specify which message_id ? i mean i do have a row for message_id, but how do i find that?

Thanksthen you have to make another query that shows all messages by the certain user and then have an edit link next to each one so all they have to do is click the link and then they can edit that certain message.

we are under the assumption that you have only 1 poster and he only posted 1 message. wha tthe other poster said is true if the CURRENT_user posted more than 1 message.
 
Top