Jump to content

Remove comma from last result


lbaxterl

Recommended Posts

I have the following script which outputs different results based on weather a result is odd or even, pretty simple. The prblem lies with the very last result ouputted, as you can see from the code it will have a comma trailing it, which causes IE to not display the gallery.

 

Can Anyone advise me on how to remove this last comma/echo the last result differently.

 

Thank you

 

<?php
include "config.inc.php";
$num = 1;
function checkNum($num){
  return ($num%2) ? TRUE : FALSE;
}


	$result = mysql_query( "SELECT photo_id, photo_filename FROM gallery_photos WHERE photo_category= 6 AND promo= 1 ");
	$nr = mysql_num_rows( $result );

		$NumOfRecords = mysql_num_rows($result);

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


  
  $id = $row['photo_id'];
  $img = $row['photo_filename'];
  
  
  if(checkNum($num) === TRUE){
   echo "
   
  { src: 'admin/photos/".$img."', dir: 'left'   },";
  
  $num++;

  }
  
elseif ($num == $NumOfRecords) {
      echo "  { src: 'admin/photos/".$img."', dir: 'left'   }";
   }


  
  else{
  echo  "
   
  { src: 'admin/photos/".$img."', dir: 'right'   },";
  $num++;
}

}

      ?>

Link to comment
Share on other sites

Sorry i posted code i was messing around with there here is the working code (in firefox at least), it still outputs the last record having a comma after it.

 


<?php
include "config.inc.php";
$num = 1;
function checkNum($num){
  return ($num%2) ? TRUE : FALSE;
}


	$result = mysql_query( "SELECT photo_id, photo_filename FROM gallery_photos WHERE photo_category= 6 AND promo= 1 ");
	$nr = mysql_num_rows( $result );

		$NumOfRecords = mysql_num_rows($result);

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


  
  $id = $row['photo_id'];
  $img = $row['photo_filename'];
  
  
  if(checkNum($num) === TRUE){
   echo "
   
  { src: 'admin/photos/".$img."', dir: 'left'   },";
  
  $num++;

  }
  
  else{
  echo  "
   
  { src: 'admin/photos/".$img."', dir: 'right'   },";
  $num++;
}

}

      ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.