0

誰かが私を助けてくれますか、私はこのコードを取り入れようとしています:

<?php
$blocked_users = blocked_users();
while ($block = mysql_fetch_array($blocked_users)) {
if ($block['blocked'] == '1')  {
include("includes/mod_profile/mod_blocked.php");
}
}
?>

このコードをelseステートメントに合わせるには:

$profile_info_set = get_profile_info();
while ($profile = mysql_fetch_array($profile_info_set)) 


        if (isset ($profile_id))
        if ($user['account_status'] == "Active")
        if ($user['account_type'] == "Escort") {
        include("includes/mod_profile/mod_profile.php");

        }

ユーザーのブロックステータスを0から1にするテーブルがデータベースにあり、ユーザーが誰かをブロックし、そのユーザーが自分のプロファイルにアクセスしようとすると、ユーザーがブロックされているという別のページに移動するようにしようとしています. 私はこれをやっています<?php include(.. ?>

現時点では、これをページの上部に配置しようとしました:

<?php
$blocked_users = blocked_users();
while ($block = mysql_fetch_array($blocked_users)) {
if ($block['blocked'] == '1')  {
include("includes/mod_profile/mod_blocked.php");



                }
}
?>

それが機能し、ページ mod_blocked.php を含めている間、デフォルトのプロファイル ページである mod_profile.php も表示され、重複しています。したがって、基本的に、ユーザーがブロックされていない場合は mod_profile.php に移動し、ユーザーがブロックされている場合は mod_blocked.php に移動する必要があります。

誰かが間違っている場所とこれを達成する方法を教えてもらえますか?

コードのページ全体は次のとおりです。

<?php
        $page_title = "Profile";
        include('includes/headerframe.php');


    // GET PROFILE ID FROM URL
    if (isset ($_GET['id'])) {
        $profile_id = $_GET['id'];
    }
    ?>
    <?php
    $blocked_users = blocked_users();
    while ($block = mysql_fetch_array($blocked_users)) {
    if ($block['blocked'] == '1')  {
    include("includes/mod_profile/mod_blocked.php");



                    }
    }
    ?>


    <?php
    $user_info_set = get_user_info();
    if (!$user = mysql_fetch_array($user_info_set)) {
        include ('includes/mod_profile/mod_noprofile.php');

    }

        else if (!isset($profile_id)) {
                        include("includes/mod_profile/mod_noprofile.php");
                    }

    $profile_info_set = get_profile_info();
    while ($profile = mysql_fetch_array($profile_info_set)) 


        if (isset ($profile_id))
        if ($user['account_status'] == "Active")
        if ($user['account_type'] == "Escort") {
                        include("includes/mod_profile/mod_profile.php");



                    }

                    else if ($block['blocked'] == '1')  {
                        include("includes/mod_profile/mod_noprofile.php");
                    }





                    $profile_info3_set = get_profile_info3();
    while ($profile = mysql_fetch_array($profile_info3_set)) 

        if (isset ($profile_id))
        if ($user['account_status'] == "Active")
        if ($user['account_type'] == "Client") {
                        include("includes/mod_profile/mod_account.php");
                    } 



    ?>
4

2 に答える 2

0

ここにいくつかのオプションがあります。

追加breakまたはそのdie()ようなもの

<?php
$blocked_users = blocked_users();
while ($block = mysql_fetch_array($blocked_users)) {
if ($block['blocked'] == '1')  {
include("includes/mod_profile/mod_blocked.php");
break;
}
}
?>

または、else

<?php
$page_title = "Profile";
include ('includes/headerframe.php');

// GET PROFILE ID FROM URL
if (isset($_GET['id'])) {
    $profile_id = $_GET['id'];
    die();
}

$blocked_users = blocked_users();
while ($block = mysql_fetch_array($blocked_users)) {
    if ($block['blocked'] == '1') {
        include ("includes/mod_profile/mod_blocked.php");
    } else {
        $user_info_set = get_user_info();
        if (!$user = mysql_fetch_array($user_info_set)) {
            include ('includes/mod_profile/mod_noprofile.php');
        } else if (!isset($profile_id)) {
            include ("includes/mod_profile/mod_noprofile.php");
        }

        $profile_info_set = get_profile_info();
        while ($profile = mysql_fetch_array($profile_info_set))

            if (isset($profile_id))
                if ($user['account_status'] == "Active")
                    if ($user['account_type'] == "Escort") {
                        include ("includes/mod_profile/mod_profile.php");
                    } else if ($block['blocked'] == '1') {
                        include ("includes/mod_profile/mod_noprofile.php");
                    }

        $profile_info3_set = get_profile_info3();
        while ($profile = mysql_fetch_array($profile_info3_set))

            if (isset($profile_id))
                if ($user['account_status'] == "Active")
                    if ($user['account_type'] == "Client") {
                        include ("includes/mod_profile/mod_account.php");
                    }
    }
}
?>
于 2013-01-31T18:19:34.613 に答える
0

あなたが何をしようとしているのかを完全に理解しているかどうかはわかりませんが、あなたの質問が正しい場合は、次の方法で行うことができます。

$page_title = "Profile";
include('includes/headerframe.php');

// stores the correct include file...
$toInclude = false;


// GET PROFILE ID FROM URL
if (isset ($_GET['id'])) {
    $profile_id = $_GET['id'];
}

// look up for blocked user..
$blocked_users = blocked_users();
while ($block = mysql_fetch_array($blocked_users)) {
    if ($block['blocked'] == '1')  {
        // don't do the include inside the loop
        // we simply set the $toInclude
        $toInclude = "includes/mod_profile/mod_blocked.php";
        break;
    }
}
$user_info_set = get_user_info();
// in case no include is set, and there is no profile...
if ( !$toInclude  && (!$user = mysql_fetch_array($user_info_set) || 
     !isset($profile_id)) ) {
    // we set the $toInclude now
    $toInclude = 'includes/mod_profile/mod_noprofile.php';
}


if($toInclude) {
    // either blocked or no-profile
    include($toInclude);
} else {
    // user is not blocked, and you have a profile
    // proceed with your code for normal user handling here
}
于 2013-01-31T18:35:08.040 に答える