tags:

views:

68

answers:

4

I've got a mysql query running and it checks to see if an iterator is equal to 1, then display this div title...

if ($this->dliterator == 1) {echo "<div class='clientsection' id='downloads'>Downloads</div><br/>";};

The problem is, is that the dl iterator may not necessarily start at 1. (it is directly related to a downloadid from the database).

How can I get this to display only for the first time through the loop ONLY?

while ($row = mysql_fetch_assoc($result)) { 

if ($row['download'] != null){ if ($this->dliterator == 1) {echo "Downloads
";};

if ($editDownload == 1) {
 echo "<div class='clientlink' style='margin-top: 15px;'>";
 echo "<input name='downloads[$this->dliterator][name]' type='text' id='download$this->dliterator' value='" . $row['download'] . "'/>";
 echo "<input name='downloads[$this->dliterator][title]' type='text' id='downloadtitle$this->dliterator' value='" . $row['downloadtitle'] . "'/>";
 echo "<img class='removelink' src='/images/deletelink.png' width='15' />";
 echo "<input id='downloadid' name='downloads[$this->dliterator][id]' type='hidden' value='".$row['downloadid']."' style='display: none'/>";
 echo "<br/><img id='uploaddownload$uploaditerator' class='uploaddownload' src='../images/upload.png' width='80'/>"; 
 echo "</div>";


};

};

$this->dliterator++;

$uploaditerator++; };

Thanks for all the answers! Here's my working solution thanks to Zuul:

if ($row['download'] != null){
if (($this->dliterator != null ) && ($check ==0)) {echo "<div class='clientsection' id='downloads'>Downloads</div><br/>";
$check++;};
+1  A: 
$row = mysql_fetch_assoc($result);

if ($row && $row['download'] != null) {

    echo "<div class='clientsection' id='downloads'>Downloads</div><br/>";
}

while ($row) {

    // ...

    $row = mysql_fetch_assoc($result);
}
erisco
+2  A: 

Put a flag out of the loop at false $firstLineFetched = false;, then if it is false you set it true and do your first line processing

Serty Oan
+6  A: 

Try this:

$check=0;

if (($this->dliterator == 1) && ($check==0)) {
  echo "<div class='clientsection' id='downloads'>Downloads</div><br/>";
  $check++;
};

It will enter the if statement if your "dliterator==1 and if $check hasn't change... After inside, it will change the $check thus preventing the if statement to run again!

Hope it helps!

Zuul
I think making `$check` a boolean would make the example more readable, but otherwise +1.
musicfreak
@musicfreak, naughty boy ;) (I'm @ work, but still trying to help, can get my head around all the details) [btw:tks!] :)
Zuul
A: 

You could just set a counter outside the loop to 0 and do something like:

if($i == 0)
  printf("<div class=........>\n");

Then be sure to increment $i ($i++) at the end of the while() and next time through the loop it will pass right over the printf() statement.

Nicholas Kreidberg