0

わかりました、今日はあまりにも長く働いていて、単純なことに行き詰まっています(と思います)

function commonData($uid)
{
    if ($uid)
    {
            $sql = "
                    SELECT a.user_id, a.email, a.username, a.displayname, a.level_id, a.photo_id
                    FROM engine4_users AS a
                    WHERE a.user_id = ".$uid;
    }

    $UserInfo = @mysql_fetch_assoc(mysql_query($sql));

    if ($UserInfo[user_id])
    {

            if ($UserInfo[photo_id] && $UserInfo[photo_id]!="NULL")
            {
                    $PPhoto = @mysql_fetch_assoc(mysql_query("SELECT a.* FROM engine4_storage_files AS a WHERE a.file_id = ".$UserInfo[photo_id]));
                    $photo = SITE.$PPhoto[storage_path];
            }
            else $photo = NO_PHOTO; 

    $queryMoreProfile = mysql_query("SELECT * FROM engine4_user_fields_values AS a WHERE a.item_id = ".$UserInfo[user_id]);

    while ($moreProfile = @mysql_fetch_assoc($queryMoreProfile))
    {

            //$location = '';
            if ($moreProfile['field_id']==24)
            {
                    $locationNumber = $moreProfile['value'];
                    $locationsql = @mysql_fetch_assoc(mysql_query("SELECT a.* FROM engine4_user_fields_options AS a WHERE a.option_id = ".$locationNumber));

                    if (isset($locationsql['label']) && !empty($locationsql['label']))
                    {
                            $location = $locationsql['label'];
                    }
            }

            //if(empty($location))
            //{
            //      header("Location: http://www.fetishmen.net/members/edit/profile");
            //      exit;
            //}
}

私がやろうとしているのは、IF$locationには値がない(データベースから完全に失われている)ページへのリダイレクトです。ここで何が間違っていますか?

4

2 に答える 2

2

配列のインデックスであり、変数または文字列のいずれか$moreProfile$locationsqlある必要があります。

if ($moreProfile['field_id']==24) //or $field_id
{
    $locationNumber = $moreProfile['value']; //or $value
    $locationsql = @mysql_fetch_assoc(mysql_query("SELECT a.* FROM engine4_user_fields_options AS a WHERE a.option_id = ".$locationNumber));
    $location = $locationsql['label']; //or $label 
}

if(empty($location))
{
    header("Location: http://website.com");
    exit;
}

編集: OPのコメントによると、

  if ($moreProfile['field_id'] == 24 ) 
{
    $locationNumber = $moreProfile['value']; //or $value
    $locationsql = @mysql_fetch_assoc(mysql_query("SELECT a.* FROM engine4_user_fields_options AS a WHERE a.option_id = ".$locationNumber));
    $location = $locationsql['label']; //or $label 
} else if(empty($moreProfile['field_id'])) {
     header("Location: http://website.com");
     exit;
}
于 2012-11-14T22:34:19.300 に答える
0

@の使用を停止し、mysql_resultとmysql_fetch_assocが何かを返していることを適切にチェックする必要があります。これを試して、リダイレクトされるかどうかを確認してください。

$location = '';

if ($moreProfile['field_id']==24)
{
    $locationNumber = $moreProfile['value'];
    $locationsql = @mysql_fetch_assoc(mysql_query("SELECT a.* FROM engine4_user_fields_options AS a WHERE a.option_id = ".$locationNumber));

    if (isset($locationsql['label']) && !empty($locationsql['label'])) {
            $location = $locationsql['label'];
    }
}

if(empty($location))
{
    header("Location: http://website.com");
    exit;
}
于 2012-11-14T23:16:55.520 に答える