Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

206
Vistas
Matching array of string to numbers to get database values

In my database, I have a status column where I'm using numbers to represent a status of a product. Each of these numbers represents a string value, for example 1 is open, 2 is closed, etc. Now to display a count of these statuses in my webpage, I am converting the following numbers into a string to display them to the user:

array(1=>'Open',8=>'Hot',2=>'Closed',3=>'Transacted',4=>'Dead',9=>'Follow Up',11=>'Working')

Now I have this count as a clickable link, where the user can click the count and it takes them to a new page showing the details of that item. For which I'm using this:

<a target='_blank' href='".site_url('reports/viewall?status=' . $status)."'>".$num."</a>

This correctly passes the argument to the URL and shows http://localhost/reports/viewall?status=Closed

Now I'm storing this variable in my controller as $status, but I cannot use this string value in my model query which is this since it is giving the string value of status and not the number related to it:

SELECT * from TABLE1 where status = $status

Controller Class where I'm storing the $status:

$status = $this->input->get('status');
$content['individualleads'] = $this->leads_model->get_all_leads($status )->result();
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I think the best approach would be to pass the integer in the URL and use the array text value only when it is text meant for the user. So just:

http://localhost/reports/viewall?status=2

Another alternative is to flip the array and access the text key:

$status_num = array_flip($array)[$status];

Or search the original array:

$status_num = array_search($status, $array);

Probably more standard might be to have a status_types table with the integer status_id and text status_text for each status and join this when retrieving the status.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda