How to replace string

medaacek 20 Feb, 2013
Sorry for the easy and silly question but I cannot find any thread referring to this and Im not familiar with sql at all:

Im displaying data from a database table. One of the database columns (availability_calendar_units_id) contains values 1, 2,...5 instead of the real text that I would like to see (1=Element ICPMS, 2=Neptune ICPMS, etc). How do I replace these numbers with appropriate text in the frontend? is it sql or php code that I need? And does the code need to be in WHERE SQL or Body (Connection view settings)?

In other words the Body has this code now:
<tr><td>{startdate}</td><td>{enddate}</td><td>{title}</td><td>{availability_calendar_units_id}</td><td>{description}</td></tr>

but the {availability_calendar_units_id} gives the results as numbers 1,2,3,4,or 5.
Is there any way these individual numbers are replaced by the string (text) I define?

Many thanks for the help or for directing me to the correct thread! Im really stuck with this simple task.

Jiri
GreyHead 20 Feb, 2013
Hi medaachek,

I don't know how to handle this in ChronoConnectivity but this FAQ has some code for ChronoForms.

In ChronoConnectivity I think I'd probably use a Custom Listing and look up the values either in the Header or Body boxes.

Bob
medaacek 20 Feb, 2013
Thanks Bob (I was always amazed where you find time for this forum - you are always ready to help others!!!),

it was not that difficult after all, I found the "strtr" function of php that did the trick for me. The working code is below (note that it is for connectivity V2_RC3 - for the V4 "$MyRow" will probably not work and you have to use another quotation)



<?php
$instr = strtr ($MyRow->availability_calendar_units_id, array ('1' => 'Element II ICP-MS', '2' => 'Neptune MC ICP-MS', '3' => 'IRIS ICP-OES', '4' => 'Resonetics 193 nm excimer laser', '5' => 'New Wave UP-213 laser'));
?>
<td><?php echo $instr; ?></td>


Jiri
GreyHead 21 Feb, 2013
Hi Jiri,

That's neat - I hadn't seen strtr() used before, I'll try to remember about it for next time I have that problem.

Bob
This topic is locked and no more replies can be posted.