The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/printthread.php 16 require_once



UserSpice
Validate Across Columns - Printable Version

+- UserSpice (https://userspice.com/forums)
+-- Forum: Miscellaneous (https://userspice.com/forums/forumdisplay.php?fid=28)
+--- Forum: Documentation (https://userspice.com/forums/forumdisplay.php?fid=30)
+--- Thread: Validate Across Columns (/showthread.php?tid=520)



Validate Across Columns - tradeJmark - 04-09-2017

Hi, all,
Is there any way to use the Validate class to verify if a combination of values is unique across multiple columns? I mean, in the same way that composite primary keys need to be unique. Or, will I have to do that a different way?
Thanks for the help,
Tim Meredith


Validate Across Columns - mudmin - 04-10-2017

The validate class won't do that by itself, so basically you'll have to run a query like

Code:
$checkQ = $db->query("SELECT * FROM users WHERE
.... //fill in your conditions here

Code:
$checkC = $checkQ->count();
//get a count of the results

Code:
if($checkC < 1) {
//No results found, therefore it is unique)
//do something
Code:
}