Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder:
SELECT, query

 

 


rez
User

Jan 17, 2012, 1:44 PM

Post #1 of 3 (391 views)
Shortcut
SELECT, query Can't Post


Code
$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.


rez
User

Jan 17, 2012, 5:57 PM

Post #2 of 3 (384 views)
Shortcut
Re: [rez] SELECT, query [In reply to] Can't Post


Code
SELECT cms_vendor_services.title, cms_vendors.company, cms_vendors.rep FROM cms_vendors INNER JOIN cms_vendor_services ON cms_vendors.services=cms_vendor_services.num",



thats working. these are two editors / tables, so how do i use cmsb to now replace this code and give the exact output which is stored in a variable and used in a script i have acquired?

hope that makes sense. thanks for your support.


Jason
Staff / Moderator


Jan 18, 2012, 10:45 AM

Post #3 of 3 (366 views)
Shortcut
Re: [rez] SELECT, query [In reply to] Can't Post

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:


Code
  $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:


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


Hope this helps
---------------------------------------------------
Jason Sauchuk - Programmer 
interactivetools.com

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