PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 17th, 2012, 10:03 PM
CMYKreative CMYKreative is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 5 CMYKreative User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 12 sec
Reputation Power: 0
PHP-General - PHP Help - Consecutive Numbering

I'm trying to hide some specific <tr> rows on the registration form in Virtuemart that are not needed, but there is no way to 'target' them as it uses the same piece of coding to create all the rows.

What we have at the moment is:

echo ' <table class="adminForm user-details">' . "\n";
$_table = true;
}
echo ' <tr>' . "\n";
echo ' <td class="key" title="'.$_field['description'].'" >' . "\n";
echo ' <label class="' . $_field['name'] . '" for="' . $_field['name'] . '_field">' . "\n";
echo ' ' . $_field['title'] . ($_field['required'] ? ' *' : '') . "\n";

Where the td class is simply called "key" and all td are then called the same. We are trying to add in some consecutive lettering functionality so that each row then gets labelled with a consecutive number.

We've tried adding this into the top of the page:

<?php
// array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i');
foreach (range('a', 'z') as $letter)
?>
Which does generate consecutive letters, and then this change to the code:

echo ' <td class="key td-id-'.$letter.'" title="'.$_field['description'].'" >' . "\n";

Any thoughts on how to get this to work?

Thanks in advance!

Reply With Quote
  #2  
Old October 18th, 2012, 02:25 AM
badger_fruit's Avatar
badger_fruit badger_fruit is offline
Confused badger
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2009
Location: West Yorkshire
Posts: 760 badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 5 h 15 m 18 sec
Reputation Power: 339
The one thought that springs to mind is in the loop, have an incrementing counter and have an if statement determine if the row should be shown or not ... something like this:-

PHP Code:
// This goes inside the TR creation loop
$rcounter++;
if (
$rcounter != && $rcounter != && $rcounter != 7)  {
    
// Display the row
    
echo "<tr ..... >";



Obviously, change the numbers for the rows you don't wish to display and add/decrease the amount of 'and' conditions accordingly.
__________________
The number for UK Emergencies is changing, the new number is 0118 999 881 999 119 7253

"For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
- George Orwell, 1984

Reply With Quote
  #3  
Old October 18th, 2012, 02:54 AM
CMYKreative CMYKreative is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 5 CMYKreative User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 12 sec
Reputation Power: 0
Thanks for the reply . . . but I don't know how to implement that to make it work . . .

Reply With Quote
  #4  
Old October 18th, 2012, 03:17 AM
badger_fruit's Avatar
badger_fruit badger_fruit is offline
Confused badger
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2009
Location: West Yorkshire
Posts: 760 badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 5 h 15 m 18 sec
Reputation Power: 339
Quote:
Originally Posted by CMYKreative
Thanks for the reply . . . but I don't know how to implement that to make it work . . .


OK well you've not posted enough code to show the actual loop but consider this example and perhaps you'll have a better understanding of where and how to use it?

PHP Code:
// Lets create an array of data, from which we'll build the table ....
$tarray = array(
  
=> "Badger"
  
=> "Fruit"
  
=> "Cat"
  
=> "Dog",
   
=> "Fish"
  
=> "Sausages"
  
=> "Bacon!!!!"
  
=> "Eggs"
  
=> "Tea, white with 3 sugars"
  
=> "My Wife"
  
10 => "Ella"
  
11 => "Jake"
  
12 => "Jake dog"
);

// Now we want to make a table with each array element being the title ...
// First, we define the non-repeating elements of the table (eg the headers)
echo "<table width='100%' border=1>";
  echo 
"<tr>";
    echo 
"<td>";
      echo 
"Header";
    echo 
"</td>";
  echo 
"</tr>";

// Now we go through all the elements in the array, creating rows as we go .... 
foreach ($tarray as $value) {
  echo 
"<tr>";
    echo 
"<td>";
      echo 
$value;
    echo 
"</td>";
  echo 
"</tr>";
}

// And finally, we close the table neatly ...
echo "</table><br />"


OK, so the example above will give you an idea on the structure you have now. So now, let's use the same code above but with some modifications, we don't want to show all food items for example ... we know that they're in the array at positions 4,5,6,7, and 8 ...

PHP Code:
// Lets create an array of data, from which we'll build the table ....
$tarray = array(
  
=> "Badger"
  
=> "Fruit"
  
=> "Cat"
  
=> "Dog",
   
=> "Fish"
  
=> "Sausages"
  
=> "Bacon!!!!"
  
=> "Eggs"
  
=> "Tea, white with 3 sugars"
  
=> "My Wife"
  
10 => "Ella"
  
11 => "Jake"
  
12 => "Jake dog"
);

// Now we want to make a table with each array element being the title ...
// First, we define the non-repeating elements of the table (eg the headers)
echo "<table width='100%' border=1>";
  echo 
"<tr>";
    echo 
"<td>";
      echo 
"Header";
    echo 
"</td>";
  echo 
"</tr>";

// Now we go through all the elements in the array, creating rows as we go .... 
// Here is the first change, we need to know the $key number (0 to 12) so we can determine if we're going to show it or not ...
// Previously is was "foreach ($tarray as $value) {" but now it's "foreach ($tarray as $key => $value) {", it's a subtle change but an important one!
foreach ($tarray as $key => $value) {

// Here's the next change; the IF statement ... we need to check IF the $key is not equal to any of our "banned" item numbers
if ($key != && $key != && $key != && $key != && $key != 8) {

// If it's not, then it will do this bit
  
echo "<tr>";
    echo 
"<td>";
      echo 
$value;
    echo 
"</td>";
  echo 
"</tr>";

// Here is the end of the IF statement
}

}

// And finally, we close the table neatly ...
echo "</table><br />"


As you can see, the table is created and happily skips over the "banned" row numbers.

Reply With Quote
  #5  
Old October 18th, 2012, 03:27 AM
CMYKreative CMYKreative is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 5 CMYKreative User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 12 sec
Reputation Power: 0
Thanks again . . . I'll look into it and see if we can get it to work.

This was the original code:

echo ' <table class="adminForm user-details">' . "\n";
$_table = true;
}
echo ' <tr>' . "\n";
echo ' <td class="key" title="'.$_field['description'].'" >' . "\n";
echo ' <label class="' . $_field['name'] . '" for="' . $_field['name'] . '_field">' . "\n";
echo ' ' . $_field['title'] . ($_field['required'] ? ' *' : '') . "\n";
echo ' </label>' . "\n";
echo ' </td>' . "\n";
echo ' <td>' . "\n";
echo ' ' . $_field['formcode'] . "\n";
echo ' </td>' . "\n";
echo ' </tr>' . "\n";
}
}

if ($_table) {
echo ' </table><br>' . "\n";

Reply With Quote
  #6  
Old October 18th, 2012, 04:06 AM
badger_fruit's Avatar
badger_fruit badger_fruit is offline
Confused badger
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2009
Location: West Yorkshire
Posts: 760 badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 5 h 15 m 18 sec
Reputation Power: 339
CMYKreative, in the code you've copy/pasted, there are two "closing" curly braces but no "opening" ones so you're in a loop or a conditional statement already.
But regardless, I'm sure with a bit of digging, you'll be able to impliment something along the lines of my examples!
Good luck

Reply With Quote
  #7  
Old October 18th, 2012, 04:44 AM
CMYKreative CMYKreative is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 5 CMYKreative User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 12 sec
Reputation Power: 0
Yes, I only snipped out the relevant area of the code . . . we'll give it a go and see what we can come up with.

The full code is here:

<?php


// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');



$typefields = array('corefield', 'billto');
$corefields = VirtueMartModelUserfields::getCoreFields();
foreach ($typefields as $typefield) {
$_k = 0;
$_set = false;
$_table = false;
$_hiddenFields = '';

// for ($_i = 0, $_n = count($this->userFields['fields']); $_i < $_n; $_i++) {
for ($_i = 0, $_n = count($this->userFields['fields']); $_i < $_n; $_i++) {
// Do this at the start of the loop, since we're using 'continue' below!
if ($_i == 0) {
$_field = current($this->userFields['fields']);
} else {
$_field = next($this->userFields['fields']);
}

if ($_field['hidden'] == true) {
$_hiddenFields .= $_field['formcode'] . "\n";
continue;
}
if ($_field['type'] == 'delimiter') {
if ($_set) {
// We're in Fieldset. Close this one and start a new
if ($_table) {
echo ' </table>' . "\n";
$_table = false;
}
echo '</fieldset>' . "\n";
}
$_set = true;
echo '<fieldset>' . "\n";
echo ' <legend>' . "\n";
echo ' ' . $_field['title'];
echo ' </legend>' . "\n";
continue;
}



if (($typefield == 'corefield' && (in_array($_field['name'], $corefields) && $_field['name'] != 'email' && $_field['name'] != 'agreed') )
or ($typefield == 'billto' && !(in_array($_field['name'], $corefields) && $_field['name'] != 'email' && $_field['name'] != 'agreed') )) {
if (!$_table) {
// A table hasn't been opened as well. We need one here,
if ( $typefield == 'corefield') {
echo '<span class="userfields_info">' . $this->corefield_title . '</span>';
} else {
echo '<span class="userfields_info">' . $this->vmfield_title . '</span>';
}


echo ' <table class="adminForm user-details">' . "\n";
$_table = true;
}
echo ' <tr>' . "\n";
echo ' <td class="key" title="'.$_field['description'].'" >' . "\n";
echo ' <label class="' . $_field['name'] . '" for="' . $_field['name'] . '_field">' . "\n";
echo ' ' . $_field['title'] . ($_field['required'] ? ' *' : '') . "\n";
echo ' </label>' . "\n";
echo ' </td>' . "\n";
echo ' <td>' . "\n";
echo ' ' . $_field['formcode'] . "\n";
echo ' </td>' . "\n";
echo ' </tr>' . "\n";
}
}

if ($_table) {
echo ' </table><br>' . "\n";
}
if ($_set) {
echo '</fieldset>' . "\n";
}
$_k = 0;
$_set = false;
$_table = false;
$_hiddenFields = '';
if(is_array($this->userFields['fields'])) {
reset($this->userFields['fields']);
}

}

echo $_hiddenFields;

Reply With Quote
  #8  
Old October 18th, 2012, 05:36 AM
CMYKreative CMYKreative is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 5 CMYKreative User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 12 sec
Reputation Power: 0
OK, I found a quick and easy solution:

echo ' <tr class="key td-id-' . $_field['name'] . '">' . "\n";

I just added the existing ' . $_field['name'] . ' code to the tr and I was then able to target this in the way I wanted.

Thanks for the help!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP-General - PHP Help - Consecutive Numbering

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap