Jump to content

search table column against a variable (HELP!)


teitanerim

Recommended Posts

Hi, i'm trying to see if the current userid of the user matches any userid in the table... but i cannot get the query correct. here's what I have

$userid = $my->id; //needed to get current userid

$have_listing = "SELECT `userid`=$uid FROM `agent_list`";
mysql_query($have_listing);

if($uid == $userid) {
echo "You already have a listing, would you like to edit?";
} else {
...

can anyone help?  thanks in advance!
}

Thanks,
Daniel
Your query is structured incorrectly, it should read:
[code]SELECT `userid`FROM `agent_list` WHERE `userid`='$uid'[/code]
Although, I'm not sure if your code will do what you expect anyway, try this...
[code]<?php
$userid = $my->id;
$count = mysql_result(mysql_query("SELECT COUNT(*) FROM `agent_list` WHERE `user_id`='$userid'"),0);
echo ($count > 0) ? "You have a listing" : "You do not have a listing";
?>[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.