While loop, need help...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
WithHisStripes
Forum Contributor
Posts: 131
Joined: Tue Sep 13, 2005 7:48 pm

While loop, need help...

Post by WithHisStripes »

Heya,
So I'm working on a site and I have a while loop that displays the users current projects, their past projects and their contact information. Each section has a title which should only occur once, but since it's in the while loop, it will repeat as many times as their are records. How can I ensure the titles only occur once? Here's a code sample: (thanks!)

Code: Select all

 
<?php
    $get_client_data = mysql_query("SELECT * FROM `top-secret`, `top-secret` WHERE `top-secret` = '$top-secret' AND `top-secret` = '$top-secret'") or die(mysql_error());
    
    echo '<h3>Your Current Projects</h3>';
    
    while ($insert_client_data = mysql_fetch_array($get_client_data, MYSQL_ASSOC)) {
                    stuff
        }
    
    echo "<h3 id='toggle-your-profile'>Edit Your Profile >></h3>";
    
    while ($insert_client_data = mysql_fetch_array($get_client_data, MYSQL_ASSOC)) {
        echo "stuff";
    }   
?>
 
Last edited by Benjamin on Fri May 29, 2009 10:15 am, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: While loop, need help...

Post by s.dot »

Why couldn't you show the title and then start the loop? Sounds like you might need some database restructuring. :)

But, to answer your question:

Code: Select all

$start = true;
while ($something)
{
    if ($start)
    {
        echo 'title';
        $start = false;
    }
 
    echo 'other stuff';
}
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply