Page 1 of 1

While loop, need help...

Posted: Wed May 27, 2009 4:29 pm
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";
    }   
?>
 

Re: While loop, need help...

Posted: Wed May 27, 2009 5:20 pm
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';
}