Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php if else statement within a select box

Tags:

html

php

mysql

I am working on a piece that allows user to create an article, but there are some restricted for an admin, which i identify as SgroupId 1. Now when I log in with my admin code, i realize i still cant post everything, except for what I identified in loadTypeUsers. I know i get the value of Sgroup1 with me, since the admin panel loads in the bar below. Also when I echo the value I get the return of 1, which should be fine.

But when I try to load the dropdown in my popup, it wont give me the full list. Instead, it loads just the list I specified in the LoadTypeUsers. Can somebody help me out here?

Thanks in advance.

~Dorv

function MakeArticleTypeDropdown(){
        echo "<select name='ArticleTypeId'>";

        if($SgroupId == 1 || $SgroupId == 1){ 
            $results = LoadType();
        }
        else
        {
            $results = LoadTypeUsers();
        }

        while($row = mysql_fetch_array($results)){
            echo "<option value='".$row['ArticleTypeId']."'>"
                            .$row['ArticleTypeName']."</option>";
        }
        echo "</select>";
    }

This is tucked in the ArticleFunction.php file

function LoadTypeUsers(){
    $query = "SELECT * FROM Articletype limit 1,3;";
    $resultaat=SendQuery($query);
    return $resultaat;
}

    function LoadType(){
    $query = "SELECT * FROM Articletype;";
    $resultaat=SendQuery($query);
    return $resultaat;
}

This is tucked in the Sentry.php file

session_start();
$UserName = $_SESSION['username'];

$result = mysql_query("select * from user where username='".$UserName."'");
while($row = mysql_fetch_array($result)){
                $UserId = $row['UserId'];
                $CharacterName = $row['CharacterName'];
                $UserName = $row['UserName'];
                $SgroupId = $row['SgroupId'];
            };
like image 939
Dorvalla Avatar asked Jul 26 '26 15:07

Dorvalla


2 Answers

$SgroupId is not defined in the function MakeArticleTypeDropdown() so it will always goes in else condition .Try something as follows

MakeArticleTypeDropdown($SgroupId)
{
//-----------your code
}
like image 136
Sumit Neema Avatar answered Jul 29 '26 07:07

Sumit Neema


first of all, I don't see you passing the value of $SgroupId to MakeArticleTypeDropdown(). Maybe you have an scope problem and you're checking a variable $SgroupId that isn't set inside the function?

second: ($SgroupId == 1 || $SgroupId == 1) What is that || for?

like image 31
NotGaeL Avatar answered Jul 29 '26 07:07

NotGaeL