user3190238
user3190238

Reputation: 43

Display second value from mysql by foreach loop

Sorry, If my question is not good.

I am using this code to display values from mysql database.

<?php foreach ($values as $value) { ?>

 <span><?php echo cimy_uef_sanitize_content($value['VALUE']); ?></span>

 <?php } ?>

It is displaying result like this

-> http://pkbazaar.com/realoffers/wp-content/Cimy_User_Extra_Fields/riaz/avatar/aget-3.png

-> Johar Town

-> 1234567

-> 54000

-> Australia

-> WA

-> Lahore 

But I don't want to display first value like "http://localhost/realoffers/wp-content/Cimy_User_Extra_Fields/riaz/avatar/aget-3.png"

What I should do to start displaying value from second value like "Johar Town".

Upvotes: 0

Views: 589

Answers (7)

Akshay Paghdar
Akshay Paghdar

Reputation: 3629

If you want to exclude url pattern than you should use regex match like this:-

<?php 
foreach ($values as $value)
{
    if(!preg_match('#^(http|https)?://#', $value))
    {
    ?>
    <span><?php echo cimy_uef_sanitize_content($value['VALUE']); ?></span>
<?php 
    }
}
?>

Hope this will help you to exclude urls.

Upvotes: 0

Noman Ghani
Noman Ghani

Reputation: 468

<?php 

 unset($values[0]);
 foreach ($values as $value) { ?>

<span><?php echo cimy_uef_sanitize_content($value['VALUE']); ?></span>

<?php } ?>

Upvotes: 0

Jim
Jim

Reputation: 22656

It's probably better to change your query to not return a row you don't need but you can just remove the first item from the array:

<?php 
array_shift($values);
foreach ($values as $value) { ?>

 <span><?php echo cimy_uef_sanitize_content($value['VALUE']); ?></span>

 <?php } ?>

See https://www.php.net/array_shift

Upvotes: 0

cdog
cdog

Reputation: 2084

If you don't need the first value you can shift the element off the beggining of array.

<?php $old_value = array_shift($values); ?>
<?php foreach ($values as $value) : ?>
    <span>
        <?php echo cimy_uef_sanitize_content($value['VALUE']); ?>
    </span>
<?php endforeach; ?>

Upvotes: 1

Fluffeh
Fluffeh

Reputation: 33522

If the number of records is the same in each array and a fixed value, it would be fairly simple to use the following:

<?php 
foreach ($values as $value) 
    {
    ?>
        <span><?php echo cimy_uef_sanitize_content($value['FIELD2']); ?></span>
        <span><?php echo cimy_uef_sanitize_content($value['FIELD3']); ?></span>
        <span><?php echo cimy_uef_sanitize_content($value['FIELD4']); ?></span>
        <span><?php echo cimy_uef_sanitize_content($value['FIELD5']); ?></span>
        <span><?php echo cimy_uef_sanitize_content($value['FIELD6']); ?></span>
    <?php 
    } 
?>

Upvotes: 0

779IDEAS
779IDEAS

Reputation: 301

Try this:

<?php 
foreach ($values as $k=>$value) { 
 if ($k==1){
   ?><span><?php echo cimy_uef_sanitize_content($value['VALUE']); ?></span><?php 
  } 
}
?>

Upvotes: 0

Daan
Daan

Reputation: 12246

<?php $count = 0; 
    foreach ($values as $value) { 
         if($count == 0 ) { 
             $count++;
         } else { ?>
             <span><?php echo cimy_uef_sanitize_content($value['VALUE']); ?></span>   
         <?php } 
     } ?>

Upvotes: 0

Related Questions