Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 448377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:39:49+00:00 2026-05-12T21:39:49+00:00

I need help with my loop. In each div, I want to show two

  • 0

I need help with my loop. In each div, I want to show two sets of FirstName and LastName instead of just one set, but I don’t know how can I do that because of the loop. Also, the point of setting different font sizes is to create a visual look which is a funnel-like shape. My questions are: how can I add another set of names in each div and is there a better way to code this? How can I make my code more efficient?

Edit: Well, I’m mainly trying to figure out how to add another set of names into the div or I can just use another loop. What I mean when I say add another set of name into the div, I mean I want to add another row of data to the div; I want to have the first two rows of data fetched from MySQL in one div.

$state = 1;
$fontcount = 25;
while ($row = mysql_fetch_assoc($result)) {

    if( $fontcount == 25 ) {                          $fontsize = "250%";
    } elseif( $fontcount < 25 && $fontcount >= 22 ) { $fontsize = "210%";
    } elseif( $fontcount < 22 && $fontcount >= 19 ) { $fontsize = "170%";
    } elseif( $fontcount < 19 && $fontcount >= 16 ) { $fontsize = "150%";
    } elseif( $fontcount < 16 && $fontcount >= 13 ) { $fontsize = "130%";
    } else {                                          $fontsize = "110%";
    }
    if( $state%2 == 0 ) {
            echo "<div style='background-color: #black; font-size: " . $fontsize . "; text-transform:uppercase; text-align:center;'>";
    } else {
            echo "<div style='background-color: #blue; font-size: " . $fontsize . "; text-transform:uppercase; text-align:center;'>";
    }


    echo $row['FirstName'] . " " . ' <span style="font-size: 15px;">$' . $row['LastName'] . "</span>";
    echo "</div>";
    $state++;
    $fontcount--;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T21:39:49+00:00Added an answer on May 12, 2026 at 9:39 pm

    If I’m understanding your question correctly, you want to display two full names in each div.

    To do that, you should only open the div tag when the record is odd, then close it when the row is even or is the last record in the set. There are a few ways to achieve this. I would suggest you keep an even/odd counter much like you’re doing now with $state. Open the div tag on an odd record; close it on an even record. (Add a check after the loop to close the div if the final record was odd.) You would then have to adjust your $state variable to only increment when the record was odd, so that the divs got alternating styling.

    As tster pointed out, your code here isn’t really inefficient in any serious way. You could probably nit-pick a few minor things, but the only real efficiency problems you will see in most applications lies in nested loops. Since you’re writing output here, I assume your code is not deeply nested, so I wouldn’t sweat it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 294k
  • Answers 294k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Can someone tell me why the following snippets have different… May 13, 2026 at 6:37 pm
  • Editorial Team
    Editorial Team added an answer Just remove the [] around read line - they should… May 13, 2026 at 6:37 pm
  • Editorial Team
    Editorial Team added an answer After further investigation we found that the issue is caused… May 13, 2026 at 6:37 pm

Related Questions

I'm trying to get better at using MVC/MVP style patterns with my WinForm apps
I need help programatically graphing more points than can fit in a single Excel
I have an application which needs to loop through all the lines in text
Before asking you my question directly, I'm going to describe the nature of my

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.