iceblox Posted January 9, 2009 Share Posted January 9, 2009 can anyone see anything wrong with this function? As its driving me mad! Nothing is happening just getting an empty screen. function star_rating($modid,$rating) { global $db,$prefix,$nukeurl,$nosearch,$isadmin,$nosearch; $result = $db->sql_query("SELECT * FROM models WHERE modid = '$modid'"); while($row = $db->sql_fetchrow($result)) { echo 'You voted!'; } $db->sql_query("UPDATE models SET modrating=count+1 WHERE modid = '$modid'"); } Quote Link to comment https://forums.phpfreaks.com/topic/140141-php-function/ Share on other sites More sharing options...
gevans Posted January 9, 2009 Share Posted January 9, 2009 Have you tried echoing out the query to see what its actually doing? Quote Link to comment https://forums.phpfreaks.com/topic/140141-php-function/#findComment-733257 Share on other sites More sharing options...
premiso Posted January 9, 2009 Share Posted January 9, 2009 $db->sql_query("UPDATE models SET modrating=count+1 WHERE modid = '$modid'"); I do not think mysql has a default field of "count". Is there a field in that table called "count"? Or is modrating the "counting" field. If modrating is the counting field you need to change your query: $db->sql_query("UPDATE models SET modrating=`modrating`+1 WHERE modid = '$modid'"); I am not sure how the sql query function works, so I would assume that it should report an error, if not try this to get the error: $db->sql_query("UPDATE models SET modrating=`modrating`+1 WHERE modid = '$modid'") or die(mysql_error()); Also a blank screen would indicate that you are not getting any results out of the DB, are you sure that you have a valid modid in the database that you are passing through? Or are you checking it to see if the user already voted on that model, if so you would want to do it this way: $result = $db->sql_query("SELECT * FROM models WHERE modid = '$modid'"); if (mysql_num_rows($result) > 0) { echo 'You have already voted'; }else { $db->sql_query("UPDATE models SET modrating=`modrating`+1 WHERE modid = '$modid'"); echo 'Your vote has been placed, thank you.'; } But I also do not understand why you are updating and not inserting. I dunno, your logic seems goofy and flawed. Please explain exactly what this function is suppose to do/react. Since I do not know your structures I am just guessing blindly. Quote Link to comment https://forums.phpfreaks.com/topic/140141-php-function/#findComment-733342 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.