Jump to content

wepnop

Members
  • Posts

    83
  • Joined

  • Last visited

    Never

Everything posted by wepnop

  1. Thats a way but... my problem is also that i was looking to instantiate some complex object that can have lots of data only a time in the server, and be accesed permantley, so you dont waste resources recreating that object.
  2. Exist in php a way to load or execute a thing only when you start the server and anything more? Because using sessions for example, you can check if exist, but thas too bugy and also exist a sesion for each user, so if i want a permament array of errors, for example, for each conection it will be created that array and some other things, and i want to have all the errors in one...
  3. Is a test function that prints a mark or variable: $cant_pe = 1; function pe ($val='') { global $cant_pe; # Si no se pasa ningun texto, muestra 'error x'. if (!$val) { $txt = "$cant_pe"; # Augmenta contador de pe's $cant_pe++; } else { $txt = (string)$val; } echo '<font color="red" >' . "<u><br><b>ERROR:</b>$txt<br> </u></font>"; }
  4. Im iterating a array but it dont work. Its says that only exist the Memoria Ram A, ehen there are 12 elements. But the strangest thing is that: $arr = $categorias[$clave]['lista_referencias']; $max = count($arr) -1; It says that max is an array. Wtf? count is converting it to array? This is the code that iterate: $categorias = &$_SESSION['reg']->GetInvCategorias(); $arr = $categorias[$clave]['lista_referencias']; $max = count($arr) -1; pe($max); # Itera en la lista de referencias para mostrar una descripcion con todas ellas for ($i=0; $i<= $max ; $i++) { #foreach ($categorias[$clave]['lista_referencias'] as $referencia) { $referencia = $categorias[$clave]['lista_referencias'][$i]; p($categorias[$clave]['lista_referencias'][$i]); $id_ref = $referencia[1]; echo "<b><u>Selecciona $id_ref. </b></u>"; #echo "<br><select name='$id_ref'><br><br>"; $nombre_sql = $categorias[$referencia[0]]['nombre_sql']; $cons = "SELECT * FROM `$nombre_sql`"; #echo "<option value=Ninguno>Ninguno</option>"; #p($cons); $res_ref = consultar_bd($cons, true); #insp_res($res_ref); while($row = mysql_fetch_array($res_ref)) { $array_keys = array_keys($row); $id = $row['ID']; $descripcion = ''; $i=1; #insp_sql_row($row); foreach($array_keys as $key) { $campo = $row[$key]; #iv ($campo); if ($i%2 == 0) { $descripcion .= "( $key : $campo) "; } $i++; } echo $descripcion . '<br>'; #echo "<option value='$id'>$descripcion</option>"; } And this the array that contais the array thats iterated(lista referencias) $categorias['PC'] = array( # Codigo identificativo interno 'nombre' => 'PC', # Nombre que sera visto por los usuarios externos 'nombre_externo' => 'PC', # El nombre que se va a usar en la tabla sql 'nombre_sql' => 'PC', # Titulo de la pagina 'titulo' => 'Insertar ordenador', # Encabezado de la pagina 'encabezado' => 'Insertar ordenador', # Descripcion del modulo en general 'descripcion' => 'Los ordenadores contienen otros elementos.', # Imagen que se mostrar junto a la descripcion 'imagen' => 'ordenador.jpg', # Contenedora: las contenedoras tienen dentro de si mismas otras categorias, en una relacion por ejemplo, PC-Componenete. 'contenedora' => true, # Lista de referencias: aqui se ponen los nombres-codigo de cada componente que posee # cada contenedora # array(Nombre de la cateogira, Identificador unico que se vera por el usuario) 'lista_referencias' => array( array('Memoria Ram', 'Ranura Ram A'), array('Memoria Ram', 'Ranura Ram B'), array('CPU', 'CPU'), array('DVD', 'DVD'), array('Placa base', 'Placa base'), array('Disquetera', 'Disquetera'), array('Dico Duro', 'Dico Duro'), array('Raton', 'Raton'), array('Teclado', 'Teclado'), array('Caja', 'Caja'), array('Caja Disco Externo', 'Caja Disco Externo'), array('SO', 'SO') ), # Activada: si no lo esta no se vera en la aplicacion a nivel externo 'activada' => true, # Campos del formulario, tipo, nombre y descripcion para cada uno. Ordenados como saldran. 'campos' => array( 0 => array( # Tipo: 1: numero, 2: texto, 3: lista de opciones 'tipo' => 2, # Ha de coincidir con el campo sql 'nombre sql' => 'Modelo', # Ha de coincidir con el campo sql 'tipo sql' => 'Texto', # TamaƱo del campo sql 'tamanyo sql' => 25, # Nombre usado por la web 'nombre' => 'Modelo', # Descripcion del elemento 'descripcion' => 'Modelo del ordenador' ) ) );
  5. Sorry maybe its that my english is bad, but i think i asked it: What i need is to get the max of the ID value in the ordenador table using php + mysql. Thats the code i was using but it dont works, when i try to get the ID it says that index dont exist. I need some way to know and store in a php variable what is the higest ID value.
  6. I need to get the max of the field called ID, from the table ordenador. This is my actual code: $cons = "SELECT MAX(ID) FROM `ordenador`"; $maxrow = consultar_bd($cons); $id_contiene = $maxrow['ID']; consultar_bd is a function that executes a sql query and returns a fetched result as a array.
  7. Well, actually my problem is that somewhat this still failing, but its too random i think. The problem is that times it dont create the register when its not instantied. Its a wtf but its happening...
  8. How i can pass complex strings with spaces using $_POST? see for example: $string = 'I have spaces'; <input type=hidden value=$string> The value will be only I. Any suggestion for these things?
  9. I need a clean and stable way to execute code only when the program starts. I use that to create a register in the $_SESSION, and do some other things that i really need one time. I also save a error array in my register object so if its recreated each time that is losed. This is the file that is called always in all my files, in the first line. <?php # Various includes for functions include 'bd.php'; include 'sesiones.php'; include 'test.php'; include 'web_inventario.php'; include 'errores.php'; include 'usuarios.php'; include_once 'registroglobal.php'; # This start the session so i can check for it and store in it without warnings and problems. session_start(); # This code is the code that will be executed the first time. reg is the register thats persistent through sesions. The idea is that # if the register isnt isset it will be settled and this is all, just for the first time-. if (!isset($_SESSION['reg'])) { $reg = RegistroGlobal::GetInstance(); p('SETEJA SES'); # Configura para usar la libreria basica $reg->setConf('Libreria usada', 'Inventario'); include '/../ijb_categorias.php'; include '/../ijb_configuracion.php'; # Set various configurations and save in $_SESSION $reg->setInvConfig($configuracion); $reg->setInvCategorias($categorias); $_SESSION['reg'] = $reg; $_SESSION['reg']->setConf('Ruta BD', $configuracion['conexion_bd'][0]); $_SESSION['reg']->setConf('Nombre usuario', $configuracion['conexion_bd'][1]); $_SESSION['reg']->setConf('ContraseƱa', $configuracion['conexion_bd'][2] ); $_SESSION['reg']->setConf('Nombre BD', $configuracion['conexion_bd'][3]); $_SESSION['reg']->setConf('Logs', $configuracion['Logs'][3]); # Primero setea la conexion de la base de datos sin selccionar ninguna, # de esta forma no da error y permite crear una nueva o navegar sin ella $_SESSION['reg']->setDB(conectar_bd(false)); if ($configuracion['Recargar inicio'] ) { cargarConfiguracionCategorias(); #echo 'MARCA REGGGGGGGGGGGGGGGGGGGGGGGGGGGG<br><br>'; } # Actualiza el administrador $usradm = $configuracion['Administrador']; $cons = "UPDATE `usuarios` SET rango = 3 WHERE nombre = '$usradm'"; modificar_bd($cons); } # Code to execute always(conect to database) # Se asegura de conectar con la base de datos seleccionando, podria fer consulta sql de si existe o no bd $_SESSION['reg']->setDB(conectar_bd()); ?> But this isnt working. Its giving me troubles. When i think it works, in other computer or at the next day it gets broken. I dont understand why i only need that...
  10. Bueh, i solved it, but using some control exceptions. Now i call my menu function with a argument for when its categories or not. Also now i understand the auto-add of urls in html. If you write a / before the url, it adds the base path to it, it was bugging me a lot.
  11. Then how i can work with absolute paths? I need to use then only /tr/? (as it is www/tr) I get it. Absolute path is this: http://localhost/tr/categorias/listar_Ordenador.php But that only works in pure localhost. Bad idea. I think i cant use absolute paths for this, no?
  12. They can be large, anyway changue it is 1m and 0 if i know it on now.
  13. c:\wamp\www\tr\categorias\listar_Ordenador.php this the link generated
  14. Actually i have a very large object thats persistent using sessions. That object have two large arrays, and other things. I have to extract each time that arrays. Now im using: $configuracion = $_SESSION['reg']->GetInvConfig(); $categorias = $_SESSION['reg']->GetInvCategorias(); But if i get it well, this is copying all the array each time, no? i can use a reference to that array in the object easily to improve performace?
  15. Well. Now i generate a correcte path using these function: function tratar_ruta($ruta) { $path = $_SESSION['reg']->GetConf('Ruta absoluta aplicacion'); if (strtoupper(PHP_OS) == 'LINUX') { } else { $completa = $path . str_replace('/', '\\', $ruta); } return $completa; } It gets a internet path and converts to a absolute file path, for windows, for now. But it dont works. Firefox says that it dont know the protocol for that.
  16. if (strtoupper(PHP_OS)) == 'LINUX') { echo 'l'; $this->config['Ruta aplicacion'] = str_replace('/lib', '', realpath(dirname(__FILE__))); } else { echo 'w'; $this->config['Ruta aplicacion'] = str_replace('\lib', '', realpath(dirname(__FILE__))); } That have to work, no? In linux only changue the \ of the path route?
  17. Its done. I only have to get if its windows or linux using this, i think: if (strtoupper(PHP_OS)) == 'LINUX') { } else { } str_replace('\lib', '', realpath(dirname(__FILE__)))
  18. Using realpath(dirname(__FILE__)) i the complete path. But that path is the /lib one that have the library files. There is a easy way of going a up a path level?
  19. I want linux compatibility for that application. My problem now is, i can get the complete path of the application using some php function? What i will do is that the application is created and saved the first time you execute the application in the index page(tr level), and saved in my singleton class of global registry thats its in S_SESSION. So the first time its instancied, it will get the complete path. The problem here i see is that the user may execute first some file in the categorias directory. Then it will get that path as a base. I will check for that as the directory structrue of the application is fixed.
  20. I want linux compatibility for that application. My problem now is, i can get the complete path of the application using some php function? What i will do is that the application is created and saved the first time you execute the application in the index page(tr level), and saved in my singleton class of global registry thats its in S_SESSION. So the first time its instancied, it will get the complete path. The problem here i see is that the user may execute first some file in the categorias directory. Then it will get that path as a base. I will check for that as the directory structrue of the application is fixed.
  21. There isnt any other way? Because i generate dinamically a lot of php pages and having to include them dinamically sucks. Or maybe i can include all the files in the categories directory using a directory iterator, but that wont be a lot secure i think. What about a system whre i extract the complete path of the application, like: c:/wamp/www/tr And i store it in my configuration object( that is persistent throught sesions). Then i only have to add the needed each time using that string. So if now it uses: echo '<li><a href="categorias/listar_' . $nombre_tratado . '">' . 'Listar ' . $categorias[$entrada]['nombre'] . '</a></li>'; It will use: echo '<li><a href=" '. $complete_path . ' categorias/listar_' . $nombre_tratado . '">' . 'Listar ' . $categorias[$entrada]['nombre'] . '</a></li>'; There is any way of doing this also?
  22. Im having a strange path problem. The problem is that in the base directory, i have some php files. These goes well. I also have two folders: one for my function library, and other for some type of webpages. My problem is that if i changue to a webpage in that folder through the menu in the base directory the path itself it also changues, so it became that directory. Base dir: tr Library directory: lib Category dir: categorias (these two are in tr, and tr in www of wamp) If i echo a link like this in some page that is in the tr directory: <li><a href="categorias/listar_memoria_ram.php">List RAM Memory</a></li> And i go to that web, the include path changues, so it became categorias. I use functions to echo the menu each time, so, it dont work because it uses the relative path, so, if i echo this again: <li><a href="categorias/listar_memoria_ram.php">List RAM Memory</a></li> the url thas is finally called in the web explorer is: http://localhost/tr/categorias/categorias/listar_Memoria_Ram.php That dont exist. Note also that all my web functions are in a file that exists in the lib library and thats included each time using this: include_once '/../lib/lib_inventario.php'; That file have a impMenu function that is used each time, and all the others. What i was seeking if a plain way of controlling the path so it became more simplier and i could just use a single path, without exceptions. Or at least an explanation that why these happens. Ask for whatever any extra information you need.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.