Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.