How to hide a value from the dropdown encoding table?

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
saleh
User
Posts: 470

How to hide a value from the dropdown encoding table?

Post by saleh »

I need to hide a value from the dropdown encoding table

DROP TABLE IF EXISTS `typr_receipt`;
CREATE TABLE IF NOT EXISTS `typr_receipt` (
  `receipt_id` int(11) NOT NULL,
  `receipt` varchar(255) NOT NULL,
  PRIMARY KEY (`receipt_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;




DROP TABLE IF EXISTS `abtidayiy`;
CREATE TABLE IF NOT EXISTS `abtidayiy` (
  `SchoolID` varchar(255) NOT NULL,
  `SectID` varchar(255) DEFAULT NULL,
  `School_name` varchar(255) DEFAULT NULL,
  `nawe_almadrasa` varchar(255) DEFAULT NULL,
  `Number_students` int(11) DEFAULT NULL,
  `Number_seasons` longtext,
  `SchSharingNum` int(11) DEFAULT NULL,
  `GENDER` varchar(255) DEFAULT NULL,
  `Stage` varchar(255) DEFAULT NULL,
  `tasnif_almadrasa` varchar(255) DEFAULT NULL,
  `nizam_aldirasa` varchar(255) DEFAULT NULL,
  `nawe_altaelim` varchar(255) DEFAULT NULL,
  `alsaf_1` int(11) NOT NULL,
  `alsaf_2` int(11) NOT NULL,
  `alsaf_3` int(11) NOT NULL,
  `alsaf_4` int(11) NOT NULL,
  `alsaf_5` int(11) NOT NULL,
  `alsaf_6` int(11) NOT NULL,
  `receipt` int(11) NOT NULL,
  `store` int(11) NOT NULL DEFAULT '1',
  `alsaf1` int(11) NOT NULL,
  `alsaf2` int(11) NOT NULL,
  `alsaf3` int(11) NOT NULL,
  `alsaf4` int(11) NOT NULL,
  `alsaf5` int(11) NOT NULL,
  `alsaf6` int(11) NOT NULL,
  PRIMARY KEY (`SchoolID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Here I hide the entire field,

// Write your table-specific startup script here, no need to add script tags.

// Write your table-specific startup script here
// console.log("page loaded");
$(document).ready(function(){
    $("#r_receipt").hide();
//Hide fields according to numbers 11,12,13 Other than that it shows all
$("#x_receipt").change(function() {
var str = $("option:selected", this);
if (this.value == "3") {
    $("#r_receipt").show();
} else {
    $("#r_receipt").hide();
}

});
});

but I want to hide a value only receipt_id by using a condition :
if (CurrentUserLevel() ==1){}


saleh
User
Posts: 470

Post by saleh »

I tried this code and it failed
please help

// Page Load event
function Page_Load() {
	//echo "Page Load";
    if (CurrentUserLevel() ==1){
        $sconto = ExecuteScalar("SELECT * FROM `typr_receipt` WHERE `receipt_id` IN (2,3) ORDER BY `receipt_id` ASC");
$this->receipt->CurrentValue = $sconto;

    }

}

mobhar
User
Posts: 11660

Post by mobhar »

You should use Lookup_Selecting server event instead.


saleh
User
Posts: 470

Post by saleh »

When modifying, all values appear in: typr_receipt.receipt_id 1 2 3 4 5

I just need to show him modifying : typr_receipt.receipt_id : 2 3 .....WHERE receipt_id IN (2,3)

main table : abtidayiy.receipt
coding table :typr_receipt.receipt_id

I tried Lookup_Selecting and fail

// Lookup Selecting event
function Lookup_Selecting($fld, &$filter)
{
    //var_dump($fld->Name, $fld->Lookup, $filter); // Uncomment to view the filter
    // Enter your code here

        if (CurrentUserLevel() ==1){
        $sconto = ExecuteScalar("SELECT * FROM `typr_receipt` WHERE `receipt_id` IN (2,3) ORDER BY `receipt_id` ASC");
$this->receipt->CurrentValue = $sconto;

    }

}

mobhar
User
Posts: 11660

Post by mobhar »

Try:

// Lookup Selecting event
function Lookup_Selecting($fld, &$filter)
{
    //var_dump($fld->Name, $fld->Lookup, $filter); // Uncomment to view the filter
    // Enter your code here

    if ($fld->Name == "receipt" && CurrentUserLevel() ==1 && (CurrentPageID()=="add" || CurrentPageID()=="edit")) {
        $sconto = ExecuteScalar("SELECT `receipt_id` FROM `typr_receipt` WHERE `receipt_id` IN (2,3) ORDER BY `receipt_id` ASC");
        AddFilter($filter, "receipt = " . $sconto);
    }

}

saleh
User
Posts: 470

Post by saleh »

Thanks for help

Unfortunately, the dropdown values are not shown

I also tried this query and it failed

// Lookup Selecting event
function Lookup_Selecting($fld, &$filter)
{
    //var_dump($fld->Name, $fld->Lookup, $filter); // Uncomment to view the filter
    // Enter your code here
    if ($fld->Name == "receipt" && CurrentUserLevel() ==1 && (CurrentPageID()=="add" || CurrentPageID()=="edit")) {
        $sconto = ExecuteScalar("SELECT * FROM `typr_receipt` WHERE `receipt_id` BETWEEN 2 AND 3");
        AddFilter($filter, "receipt = " . $sconto);
    }

}
// Row Rendered event
function Row_Rendered() {
if (CurrentPageID() == "edit" || CurrentUserLevel() ==1 ) {
    $this->receipt->CurrentValue = ExecuteScalar("SELECT * FROM `typr_receipt` WHERE `receipt_id` BETWEEN 2 AND 3 ");
}

}

saleh
User
Posts: 470

Post by saleh »

// Lookup Selecting event
function Lookup_Selecting($fld, &$filter)
{
    //var_dump($fld->Name, $fld->Lookup, $filter); // Uncomment to view the filter
    // Enter your code here
    if ($fld->Name == "receipt" && CurrentUserLevel() ==1 && (CurrentPageID()=="add" || CurrentPageID()=="edit")) {
        $sconto = ExecuteScalar("SELECT * FROM `typr_receipt` WHERE `receipt_id` BETWEEN 2 AND 3");
        AddFilter($filter, "receipt = " . $sconto);
    }

}

I think the reason is the filter : AddFilter($filter, "receipt = " . $sconto);

Because : receipt != $sconto
So how does the query sconto display? receipt != $sconto


arbei
User
Posts: 9286

Post by arbei »

  1. Learn how to debug. You may enable Debug and then check the SQL in the log file in which you can find the SQL (modified by your Lookup_Selecting server event) of the lookup actions, you may check the error message, if any, or copy and test the SQL in your database manager to find out the problem of your filter.
  2. You may also add, e.g. Log("My Filter: " . $filter) in the server event and then find the corresponding log in the log file to check if your filter is correct.
  3. Note that ExecuteScalar("SELECT * FROM...") return the first field of the first record from the results of your SQL. Are you sure the value is what you need?
  4. See MySQL Comparison Operators.

gregor4711
User
Posts: 66

Post by gregor4711 »

arbei wrote:

You may enable Debug

link is not working please can you provide correct link?


arbei
User
Posts: 9286

Post by arbei »


gregor4711
User
Posts: 66

Post by gregor4711 »

TXS!


Post Reply