Page 1 of 1

select date from table where ip = php variable?

Posted: Fri Feb 15, 2008 2:49 am
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;

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

Posted: Fri Feb 15, 2008 2:51 am
by Benjamin
Your looking for mysql_fetch_assoc()

http://us3.php.net/manual/en/function.m ... -assoc.php

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

Posted: Fri Feb 15, 2008 3:00 am
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"];}

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

Posted: Fri Feb 15, 2008 3:10 am
by Benjamin
No problem man

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

Posted: Fri Feb 15, 2008 4:53 am
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.