select date from table where ip = php variable?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

select date from table where ip = php variable?

Post by JAB Creations »

In as MySQL as I can say it at this time...
select date from table where ip = php variable?

My PHP variable is an ip address ($ipaddress). So I'm looking to echo the string (simply a date) that is associated with the IP address on the same row. I keep getting some Resource id though it seems to have nothing to do with the auto_increment. Any way what am I doing wrong here?

Code: Select all

$q = "SELECT date FROM jab_ip_addresses WHERE ip='$ipaddress'";
$result=@mysql_query ($q) or die(mysql_error());
echo $result;
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: select date from table where ip = php variable?

Post by Benjamin »

Your looking for mysql_fetch_assoc()

http://us3.php.net/manual/en/function.m ... -assoc.php
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: select date from table where ip = php variable?

Post by JAB Creations »

Thank you very much!

Code: Select all

$ipaddress = getenv("REMOTE_ADDR");
$q = "SELECT date FROM jab_ip_addresses WHERE ip='$ipaddress'";
$result=@mysql_query ($q) or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {echo $row["date"];}
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: select date from table where ip = php variable?

Post by Benjamin »

No problem man
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: select date from table where ip = php variable?

Post by onion2k »

I would strongly recommend using mysql_fetch_object() instead of mysql_fetch_assoc. That way you don't need to change much of your code if you ever upgrade to using a database abstraction library like ADODB Lite.
Post Reply