Necesito hacer un select, que me traiga la información de usuarios respecto a la búsqueda, pero solamente si su nivel de permiso es la indicada.
Aquí el código completo
Código PHP:
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
$colname_Recordset1 = "-1";
if (isset($_POST['buscar'])) {
$colname_Recordset1 = $_POST['buscar'];
}
mysql_select_db($database_Pharma, $Pharma);
$query_Recordset1 = sprintf("SELECT * FROM usuarios, login ON usuarios.curp = login.curp WHERE Apellido_P LIKE %s AND login.Nivel = 'SUPERVISOR,USER'", GetSQLValueString("%" . $colname_Recordset1 . "%", "text"));
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $Pharma) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?>
Código PHP:
SELECT * FROM usuarios, login
ON usuarios.curp = login.curp
WHERE Apellido_P LIKE %s AND login.Nivel = 'SUPERVISOR,USER'
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ON usuarios.curp = login.curp WHERE Apellido_P LIKE '%-1%' AND login.Nivel = 'S' at line 1
Intenté reemplazarlo por el siguiente código, y aunque no me marca ningún error, tampoco me trae resultados:
Código PHP:
SELECT *
FROM usuarios, login
WHERE usuarios.curp = login.curp AND login.Nivel = 'SUPERVISOR,USER' and Apellido_P LIKE %colname%