Jump to content

php function


iceblox

Recommended Posts

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'");


}

Link to comment
https://forums.phpfreaks.com/topic/140141-php-function/
Share on other sites

$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.

Link to comment
https://forums.phpfreaks.com/topic/140141-php-function/#findComment-733342
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.