View Single Post
Old 10-24-2007, 09:44 AM   #2 (permalink)
bluesaga
Super Moderator
Advanced Programmer 
 
bluesaga's Avatar
 
Join Date: Sep 2007
Posts: 165
Thanks: 0
bluesaga is on a distinguished road
Default

I would say you are doing this completely wrong...

Serializing things in a database should just be used to unserialize with php when you need to store arrays that you cannot simply store in the database. Generally (always) speaking you would never attempt to search do a query on a serialized column.

You should store:
IP
Rating

In seperate column then do:

SELECT * FROM table WHERE ip = '192.168.0.1'

Using LIKE doesnt scale well either, which is another reason this is better.

If you do not understand this, please make another post and i'll try and explain a little better, or someone else will.

If you really want your script to work you need to add a wildcard to the prefix aswell as the affix to the IP variable in the sql query:

PHP Code:
<?php
// Query to check if the user has voted
$voted mysql_query(sprintf("SELECT ip FROM %s
    WHERE ip LIKE '%s'
      AND id = '%d'"
,
        
$table,
        
'%'.$ip.'%',
        
$id
)) or die(mysql_error());
?>
Notice:
'%'.$ip.'%',
bluesaga is offline  
Reply With Quote