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

  • SEARCH
  • Home
  • 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 8476139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:05:50+00:00 2026-06-10T18:05:50+00:00

I think this is probably really simple to do, but I must be overlooking

  • 0

I think this is probably really simple to do, but I must be overlooking something.

Basically, I have If/Else php statements, that check if a condition is true. Within each of these if statements, is a WHILE loop that echos all the appropriate rows from my database.

The while loops need to print some table cells, and fields from the row. At the moment, each WHILE loop has the code manually typed out, meaning if I want to change the layout or something else, I need to change it within each while loop.

What I want to do, is to define a variable, that I can echo, so that I only need to change the code in one place for it to affect all WHILE loops. However, the nature of the content within the WHILE loops mean that this wont work, and here is why:

                //If the date is a monday
                if($daycheck == "Monday") {
                    //Start a row and create cell with date in
                    echo "<tr><td height='100px' valign='top'>".$datedisplay."<br />";

                    //For each event found for this day
                    while($dayrow = mysql_fetch_assoc($dayresult)) {
                        //Show the event info
                        echo $dayrow['Event Time']."<br />".$dayrow['Event Name']."<br />";
                    }

                    //End the cell for the day
                    echo "</td>";
                }

This is one IF statement, but imagine there are several more underneath. You can see in the middle is my WHILE loop, showing the fields from each row in the database.

The problem is, that if I stick:

$dayrow['Event Time']."<br />".$dayrow['Event Name']."<br />";

into a variable before the while loop, when I echo it out, it will be the same every time as the $dayrow parts don’t get updated.

Is there any way that I can put the above into a variable so that it gets update each time the WHILE loop runs?

Perhaps if the $dayrow[”] parts were stored as text rather than variables somehow?

Thanks for any assistance you can offer.

Eds

  • 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-06-10T18:05:52+00:00Added an answer on June 10, 2026 at 6:05 pm

    As DaveRandom suggested you can use sprintf() or (more fancy and more possibilities) a template system using eval().

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

Sidebar

Related Questions

Ok, this is probably really simple, but I just can't figure it out. I
another fun (and probably really simple) question for you, that I have half worked
This is probably a really stupid MSBuild question but if I have <ItemGroup> <Dll
This is probably something silly and simple in vectors or something, but I can't
I'm sooo... close but am stuck on one tiny thing that's probably really simple
Ok, I think this is probably an easy question but for the life of
I think this could be a very easy question for you. But I have
I think this is a simple and a silly question. I have included a
I think this should be a rather simple thing to do, but I'm completely
I think its quite a simple question but not sure. I have a class:

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.