Enjoy unlimited access to all forum features for FREE! Optional upgrade available for extra perks.
NDD Camp 2024

PHP & MySQL Problem - Checking a row for existing data

Status
Not open for further replies.

sourcez

Level 4
Legacy Platinum Member
Joined
Apr 1, 2006
Messages
123
Reaction score
0
Hi all, I've got a blank on this - could be because it's late but would really appreciate any help.

Essentially I have a rating script, but there's one part I can't quite get working right. This part needs to look through a field called 'used_ips' which contains all the ip's which have voted and search through it for the current ip. If it finds the IP it should return a 1, otherwise a 0.

This is the offending code:

PHP:
$voted=mysql_num_rows(mysql_query("SELECT used_ips FROM $dbname.$tbname".ratings." WHERE used_ips LIKE '%".$ip."%' AND id='".$id."' "));

I was trying to use mysql_num_rows as the query is restricted to 1 row anyway (by $id for the primary key), so if it find it we'll get a 1 otherwise a 0.

That works in my head but my server throws up the following error every time - any ideas?

Code:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\www\xampplite\htdocs\rate.php
 

katherine

Country hopper
Legacy Exclusive Member
Joined
Jul 9, 2005
Messages
8,428
Reaction score
1,290
Code:
$result=mysql_query("SELECT used_ips FROM $dbname.$tbname".ratings." WHERE used_ips LIKE '%".$ip."%' AND id='".$id."' "));  
$voted=mysql_num_rows($result);

Or do a count if you just need the number of matching records, not the details
Code:
SELECT distinct count(used_ips) FROM $dbname.$tbname".ratings." WHERE used_ips LIKE '%".$ip."%' AND id='".$id."'
 

sourcez

Level 4
Legacy Platinum Member
Joined
Apr 1, 2006
Messages
123
Reaction score
0
Yeah, that's nice. I did this another way but this might simplify it.

Thanks!
 
Status
Not open for further replies.

The Rule #1

Do not insult any other member. Be polite and do business. Thank you!

Sedo - it.com Premiums

IT.com

Premium Members

AucDom
UKBackorder
Be a Squirrel
MariaBuy

Our Mods' Businesses

URL Shortener
UrlPick.com

*the exceptional businesses of our esteemed moderators

Top Bottom