WordPress.org

Ready to get started?Download WordPress

Forums

Simple Fields
[resolved] Displays only last data (7 posts)

  1. upadeshs
    Member
    Posted 1 year ago #

    I am using the following code below but was able to display only the last data group. What is wrong with the code. How to display repeated data.

    <?php $repeatable_field_values = simple_fields_values("rec_name,rec_desc,rec_homeurl,rec_logo");
    	foreach ($repeatable_field_values as $values)
    		$file_id = $values["rec_logo"];
            $image_info = wp_get_attachment_image_src($file_id, "thumbnail");
            $image = $image_info[0];
    {
    	echo "<table border='1' cellspacing='1' cellpadding='1' style='width: 100%'>
          <tbody>
            <tr>
              <td rowspan='3' colspan='1' style='text-align:center;'><img src='$image' alt='".$values["rec_name"]." logo'/></td>
              <td rowspan='1' colspan='3' style='text-align:center;'><a href='".$values["rec_homeurl"]."' target='_blank'><strong>".$values["rec_name"]."</strong></a></td>
            </tr>
            <tr>
              <td rowspan='1' colspan='3'>".$values["rec_desc"]."</td>
            </tr>
            <tr>
              <td><a href='".$values["rec_homeurl"]."' target='_blank'>Home</a></td>
              <td></td>
              <td></td>
            </tr>
          </tbody>
        </table>";
    }
    ?>

    Please help!

    http://wordpress.org/extend/plugins/simple-fields/

  2. Pär Thernström
    Member
    Plugin Author

    Posted 1 year ago #

    It looks ok I think. If you just write

    print_r($repeatable_field_values);

    do you get/see all values in that array?

  3. upadeshs
    Member
    Posted 1 year ago #

    Yes sir I can see all the values in array. So what can I do next?

  4. Pär Thernström
    Member
    Plugin Author

    Posted 1 year ago #

    Ah, I think you made a small error in your code. The way you loop/use the foreach seems a bit odd. Try this version instead:

    <?php
    $repeatable_field_values = simple_fields_values("rec_name,rec_desc,rec_homeurl,rec_logo");
    foreach ($repeatable_field_values as $values) {
    	$file_id = $values["rec_logo"];
    	$image_info = wp_get_attachment_image_src($file_id, "thumbnail");
    	$image = $image_info[0];
    	echo "<table border='1' cellspacing='1' cellpadding='1' style='width: 100%'>
          <tbody>
            <tr>
              <td rowspan='3' colspan='1' style='text-align:center;'><img src='$image' alt='".$values["rec_name"]." logo'/></td>
              <td rowspan='1' colspan='3' style='text-align:center;'><a href='".$values["rec_homeurl"]."' target='_blank'><strong>".$values["rec_name"]."</strong></a></td>
            </tr>
            <tr>
              <td rowspan='1' colspan='3'>".$values["rec_desc"]."</td>
            </tr>
            <tr>
              <td><a href='".$values["rec_homeurl"]."' target='_blank'>Home</a></td>
              <td></td>
              <td></td>
            </tr>
          </tbody>
        </table>";
    }
    ?>
  5. upadeshs
    Member
    Posted 1 year ago #

    Woohhhhaa! It's working like a charm. Thanks!!! You are awesome! But I can't figure it out what was mistake in my script? Anyways thanks for help.

  6. upadeshs
    Member
    Posted 1 year ago #

    Yeah! I

  7. upadeshs
    Member
    Posted 1 year ago #

    Yeah! I figured out what mistake was. Thanks a billion to solve my problem.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic