Jump to content

[SOLVED] enum verification


overlordofevil

Recommended Posts

Hey all,

 

I am trying to set up a script that will look for a enum variable in my db and if it finds it sets the variable to the next one. problem I am running into is it stops at the first option.

 

function getwchar($uid)
{	
$query = "SELECT * FROM characters where id='$uid'";
$result = mysql_query($query) or die (mysql_error());
while ($row = mysql_fetch_array($result))
	{
	extract($row);
		if ($row[wchar] = 'quinary')
		{
		header("Location: charerror.php");
		}
		elseif ($row[wchar] = 'quaternary')
		{
		$wchar = 'quinary';	
		}
		elseif ($row[wchar] = 'tertiary')
		{
		$wchar = 'quaternary';	
		}
		elseif ($row[wchar] = 'secondary')
		{
		$wchar = 'tertiary';	
		}
		elseif ($row[wchar] = 'primary')
		{
		$wchar = 'secondary';	
		}
		else
		{
		$wchar = 'primary';
		}
	}
return $wchar;
}

 

I have moved the options around and it always stops at the first one. If someone could point me in the right direction I would appreciate it.

Link to comment
https://forums.phpfreaks.com/topic/100191-solved-enum-verification/
Share on other sites

I can't see what is wrong with the code though I did clean it up a little:

function getwchar($uid) {
    $query = "SELECT * FROM characters where id='$uid'";
    $result = mysql_query($query) or die (mysql_error());

    $wchar = NULL;
    while($row = mysql_fetch_assoc($result)) {
        if($row['wchar'] = 'quinary') {
            header("Location: charerror.php");
        } elseif($row['wchar'] = 'quaternary') {
            $wchar = 'quinary';
        } elseif($row['wchar'] = 'tertiary') {
            $wchar = 'quaternary';
        } elseif($row['wchar'] = 'secondary') {
            $wchar = 'tertiary';
        } elseif($row['wchar'] = 'primary') {
            $wchar = 'secondary';
        } else {
            $wchar = 'primary';
        }
    }

    return $wchar;
}

 

The only thing I can think of is that your query is only returning one row of data.

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.