1Putts Posted December 14, 2005 Posted December 14, 2005 I have a customers_status field in my customers table to assign reseller status. If the value is 0 (defualt), they are a retail customer and if it's 1, they are a reseller. This works fine except that 0 and 1 are not very descriptive to the Admin. I find myself having to write all kinds of 'if" statements to echo "Retail" and "Reseller" when I want to display the info. I guess I could change the field and use text instead of numbers. What I'd rather do is associate the text with the customers_status value since it's always the same...0=retail and 1=reseller but they need to be tied together somehow. So if I change the customer_status from 0 to 1, it also knows to change the text value from "retail" to "reseller". I looked at the orders_status table for some guidance but I think that's a bit overkill for what I'm trying to do. Plus I want the customers_status associated with the customers_id so I don't think creating a separate customers_status table would be the way to go. I'm thinking that using the customers_status as a primary key (like the customers_id) might be the way to go but I'm not exactly sure how that works. Alternatively, maybe I can just set up a variable like customers_status_name where needed and do it that way. Again, I'm not exactly sure how that works. Here's an example of where I'm trying to use words instead of numbers. It's a section of the admin/customers.php where if displays the info in the right box: $contents[] = array('text' => '<br>' . TEXT_INFO_CUSTOMER_STATUS . ' ' . $cInfo->customers_status); Obviously the output from this looks like this: Customer Status: 1 I'd like to to say: Customer Status: Reseller Thanks in advance for any advice you can provide.
boxtel Posted December 14, 2005 Posted December 14, 2005 I have a customers_status field in my customers table to assign reseller status. If the value is 0 (defualt), they are a retail customer and if it's 1, they are a reseller. This works fine except that 0 and 1 are not very descriptive to the Admin. I find myself having to write all kinds of 'if" statements to echo "Retail" and "Reseller" when I want to display the info. I guess I could change the field and use text instead of numbers. What I'd rather do is associate the text with the customers_status value since it's always the same...0=retail and 1=reseller but they need to be tied together somehow. So if I change the customer_status from 0 to 1, it also knows to change the text value from "retail" to "reseller". I looked at the orders_status table for some guidance but I think that's a bit overkill for what I'm trying to do. Plus I want the customers_status associated with the customers_id so I don't think creating a separate customers_status table would be the way to go. I'm thinking that using the customers_status as a primary key (like the customers_id) might be the way to go but I'm not exactly sure how that works. Alternatively, maybe I can just set up a variable like customers_status_name where needed and do it that way. Again, I'm not exactly sure how that works. Here's an example of where I'm trying to use words instead of numbers. It's a section of the admin/customers.php where if displays the info in the right box: $contents[] = array('text' => '<br>' . TEXT_INFO_CUSTOMER_STATUS . ' ' . $cInfo->customers_status); Obviously the output from this looks like this: Customer Status: 1 I'd like to to say: Customer Status: Reseller Thanks in advance for any advice you can provide. if they don't change (expand), in application_top create an array like cust_status = array(); cust_status[0] = 'Retail'; cust_status[1] = 'Reseller'; then use echo cust_status[$cInfo->customers_status]; Treasurer MFC
1Putts Posted December 14, 2005 Author Posted December 14, 2005 if they don't change (expand), in application_top create an array like cust_status = array(); cust_status[0] = 'Retail'; cust_status[1] = 'Reseller'; then use echo cust_status[$cInfo->customers_status]; Thanks. I sort of went a different route but if I can't make it work, I'll try yours. Here's what I'm trying to do... I set up another field in the customers table called customers_status_name and assigned the default to "Retail". I changed the line I included earlier to this: $contents[] = array('text' => '<br>' . TEXT_INFO_CUSTOMER_STATUS . ' ' . $cInfo->customers_status_name); Now all need to do is, when the Admin assigns Reseller status to a customer, I have to also change the field customers_status_name to 'Reseller". Currently the code only changes the customers_status (which I swiped from the newsletter code). It looks like this: <?php if ($processed == true) { if ($cInfo->customers_status == '1') { echo CUSTOMERS_STATUS_RESELLER; } else { echo CUSTOMERS_STATUS_RETAIL; } echo tep_draw_hidden_field('customers_status'); } else { echo tep_draw_pull_down_menu('customers_status', $customers_status_array, (($cInfo->customers_status == '1') ? '1' : '0')); } ?> Obviously I don't need to draw a pull down menu - I just want to simultaneously change the value of customers_status_name in the DB to 'Reseller' when customers_status gets changed to '1'. Any help is appreciated. PS. I've been trying to put together a reseller status page based on the information you gave me earlier (in another thread) but so far haven't managed to quite get it right. Still trying...
1Putts Posted December 14, 2005 Author Posted December 14, 2005 Darn, I didn't realize it at the time but now editing a customer without the necessary code to tie customers_status and customers_status_name togther wipes the customers_status_name field blank. Obviously I'm missing something important. Probably have to do something with this code as well: <?php if ($action == 'edit' || $action == 'update') { $customers_status_array = array(array('id' => '1', 'text' => CUSTOMERS_STATUS_RESELLER), array('id' => '0', 'text' => CUSTOMERS_STATUS_RETAIL)); $newsletter_array = array(array('id' => '1', 'text' => ENTRY_NEWSLETTER_YES), array('id' => '0', 'text' => ENTRY_NEWSLETTER_NO)); ?>
1Putts Posted December 14, 2005 Author Posted December 14, 2005 Aw, screw it...way too much hassle just to get the word 'Reseller' to appear instead of '1'. I dropped the customers_status_name field and changed the customers_status field to be a VARCHAR and am using the words now instead of the numbers and changed all my "if" statements to look for 'Reseller' instead of '1'. It all works fine now...sigh. I don't know what I was so bent on using numbers in the first place.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.