SELECT, query

3 posts by 2 authors in: Forums > CMS Builder
Last Post: January 18, 2012   (RSS)

By rez - January 17, 2012

$Driver = new Driver_Mysql($link, "SELECT services, company, rep FROM cms_vendors",


The problem is that "services" is from another table and is showing as numbers. How do I make something like the service:label code in a query like this?

thanks for the help.

Re: [rez] SELECT, query

By Jason - January 18, 2012

Hi,

The easiest way to do this is to create an array that has the service's record num as an index and the services title as a value. You can then output a service title by using the number returned by your query as an index.

This example assumes that you are using CMS Builder version 2.08 or higher:

$allServices = mysql_select("vendor_services");
$serviceNumToTitle = array_combine(array_pluck($allServices, 'num'), array_pluck($allServices, 'title'));


You should then be able to output a service's title like this:

<?php echo $servicesNumToTitle[$Driver['service']]; ?>

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/