servis 0 Junior Poster in Training

actually, the full code is just like that,

$sql = "SELECT img_id, img_thumbnail FROM images WHERE img_id = 15";
$result = mysql_query($sql) or die ('list fail' .  sql_erroe());
while($row = mysql_fetch_array($result)){
$arr[]=$row;
}

foreach($arr as $array){

$param['image1] = $array['img_thumbnail'];  //first image thumbnail  from image column in a mysql table  
$param['image2'] = $array['img_thumbnail']; //2nd image thumbnail from image column in a mysql table  
}
echo $param['image1'];
echo $param['image2'];

hope the above code will clear the requirement..

servis 0 Junior Poster in Training

hello,

i want to arrange variables in array from foreach loop like this

foreach($arr as $array){

$variable['first']      = $array['im'];  //first record from im column in a table  
$variable['second']= $array['im']; //2nd record from im column in a table  
}
echo $variable['first'];
echo $variable['second'];

the purpose is to make the variable available outside the loop without looping. any idea please....

servis 0 Junior Poster in Training

ohooooo, it is now working very much fine...yes you are right i have no experience in js and ajax....thank you Graphix for kind replies.....
please give me a hint, how can i validate multiple form inputs...

servis 0 Junior Poster in Training

thank you Graphix for your reply. i tried your suggested code, but the matter is, on pressing submit form bypass onsubmit function and execute process.php directly without validation

servis 0 Junior Poster in Training

of course you are right the complete code is as follow,

form.html

<html>
<head>
  <title>test form</title>
   <script type="text/javascript">

var xmlhttp

function valiadte()
{
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null){
	alert ("Your browser does not support AJAX!");
	return;
	  }
	var url="validate.php";
		xmlhttp.onreadystatechange=stateChanged;
		xmlhttp.open("POST",url,true);
		xmlhttp.send(null); 
}

	function stateChanged()
	{
	if (xmlhttp.readyState==4){
	  	if(xmlhttp.responseText.length == 0) { return true; } else { 
	  	document.getElementById("result").innerHTML=xmlhttp.responseText; return false;}
	  }
	 return false;
	}

	function GetXmlHttpObject()
	{
	if (window.XMLHttpRequest)
	  {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  return new XMLHttpRequest();
	  }
	if (window.ActiveXObject)
	  {
	  // code for IE6, IE5
	  return new ActiveXObject("Microsoft.XMLHTTP");
	  }
	return null;
	}
</script>
</head>

<body>
<div id="result"></div>

<form id="form" action="process.php" method="POST" onsubmit="return validate();">
  <div>Your name:</div>
  <div><input type="text" name="sender_name" size="20" /></div>

  <div><input type="submit" name="submit" value="submit" /></div>
</form>

</body>
</html>

validate.php

<?php
$name    = $_POST['user_name'];
$errors  = array(); // array of errors

// basic validation
if ($name == '') {
  $errors[] = "Please enter your name";
}

if (sizeof($errors) > 0) {
  // if errors, send the error message
  $str = implode("\n", $errors);
  die("There was an error with your submission!  Please correct the following:\n\n" . $str);
}

?>

process.php

if(isset($_POST['submit'])){

	$name = $_POST['user_name'];
            echo $name;
}
servis 0 Junior Poster in Training

i have a simple form validation onsubmit event. The requirement is very simple, if validate.php brings any error it shows errors and it stops form for further processing else form submit and action runs process.php.

But, unfortunately ajax function is not working onsubmit event..
any help please..... files are attached except html code which is here

<html>
<head>
  <title>test form</title>
   <script type="text/javascript" src="ajax.js"></script>
</head>

<body>
<div id="result"></div>

<form id="form" action="process.php" method="POST" onsubmit="return validate();">
  <div>Your name:</div>
  <div><input type="text" name="sender_name" size="20" /></div>

  <div><input type="submit" name="submit" value="submit" /></div>
</form>

</body>
</html>
servis 0 Junior Poster in Training

but i could not figure out any filter for sorting empty variables..

servis 0 Junior Poster in Training

i want to insert non empt values (as $im1, $im2.....) in mysql database, code is as follow, im_id is auto_increment key

$im1 =image1['image'];
$im2 =image2['image'];
$im3 =image3['image'];
$im4 =image4['image'];
  	
$sql = "INSERT INTO `class-ads`.`images` 
	   (im_id, image) 
   VALUES (NULL, '$im1'), 
	   (NULL, '$im2'),
	   (NULL, '$im3'),
               (NULL, '$im4') 
mysql_query($sql) or die('Error, Posting Image failed : ' . mysql_error());

any help plz...

servis 0 Junior Poster in Training

hello friends,

i am searching a ajax captcha from some time which have following properties,

- intimate user for wrong verification code without refresing ... 2ndly
- if the user enters the right code, it process the form normally.

unfortunately i could not find reqired script. please help me any body.

servis 0 Junior Poster in Training

thank you very much for your responses. when i declare arry() before the loop according to your advise, script run fine.

servis 0 Junior Poster in Training

I used following code as per your suggestion,

------sql query here------------
$result = mysql_query($sql):
while ($row = mysql_fetch_array($res))
{
$row[tableLegends];
$link = array ();
$link =$row; 
}

but the script is giving the same error.

servis 0 Junior Poster in Training

hi friends,

my code is as follow,

------sql query here------------
$result = mysql_query($sql):
while ($row = mysql_fetch_array($res))
{
$row[tableLegends];
$link[]=$row; 
}

when i use foreach loop in template, it give the inavlid argument "Invalid argument supplied for foreach() error"

foreach($link AS %links){
--------code here-------
}

i am not understanding where i comit mistake.

servis 0 Junior Poster in Training

In php file while loop is used to populate data in array in a following
way,

$result = mysql_query($sql ) or die ('Error, list failed. ' . mysql_error());

while($row = mysql_fetch_array($result))
 {
  $row[tableLegends];
  $link[]=$row;
  }

and for loop is used in printing data in theme file

for ($j=0; $j<count($link); $j++) 
{
echo $link[$j]['f_name']; 
echo $link[$j]['l_name'];

------code here-------

}

Actually, I want to use foreach loop in place of for loop.

Any idea please..

servis 0 Junior Poster in Training

hi,

i have passed following parameters in ajax function, onclick = "agU(<?php echo $u . ' , ' . $msg; ?>);" its not working. when i test the same function in following way it runs fine. onclick = "agU(<?php echo $u; ?>);" am i commiting any mistake in supplying variable???
please help..

servis 0 Junior Poster in Training

i have displayed a button on a page, by which a user may report anything to admin about contents complaint. when user click on this button, it leads to a new page where in a form he fills data & send to admin.

now i want when user click on button, it opens modal box where he puts the data & send to admin. The probelm is how can we pass variable information associated with the button to modal box then enter this information along with form data to mysql.

i have searched a lot, but could not get anything for solution. Please guide and help anybody.......

thanks in advance

servis 0 Junior Poster in Training

i am getting the list of values from databas table, some values are null, i want to show the values, which are not null. example is as follow,

//sql query 
while ($row =mysql_query($result))
{
$carBrand     =$row['brandName'];
$carMod        = $row['model'];
$carModYear =$row['modYear'];
$regCity        =$row['regCity'];
$demand      =$row['demand'];
//some of them are null, i want to print here only those are not null
}

actully i have no idea how to do it...
please help..

servis 0 Junior Poster in Training

thank you for the solution.

servis 0 Junior Poster in Training

i have four checkboxes, user have option to select all or any of them as per the nature of complaint. the html code is as follow....

<input type="checkbox" name="comp1" value="Abusive words are used">
<input type="checkbox" name="comp2" value="Attachments are vulgar">
<input type="checkbox" name="comp3" value="Provided links are not valid or open fake website">
<input type="checkbox" name="comp4" value="Provided contents are fake">

now, i want to know which option has been selected by the user, because accordingly i put the option sequence in one column of mysql. i want to store only the values which are not empty or only selected by the user....

any help please that how can it be done in php....

servis 0 Junior Poster in Training

thank you very much.............its working now, after your advised ammendments.......

servis 0 Junior Poster in Training

its runnung very much fine....your solutions are always give me something different....thinking of doing things differently....

when i test the following....it does not respond...please can you help where i am comitting mistake...

<?php
session_start();
if ( !empty( $_GET['id'] )) 
{ 
   include("securimage.php");
   $img = new Securimage();
   $valid = $img->check( $_GET['id'] );
   if ($valid == true){
   $response = "Code is Correct"; 
   }
echo $response;
} else {
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html id="html4" lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>Live Help!</title>

<script type="text/javascript">
var req;
var handleRequest = function() { 
   if (req) {
   if (req.readyState == 4 || req.status == "complete") {
		respond = req.responseText;
        if ( respond.length === "0" ) {
        task = "incorrect"; // This value will be available if the user send active request.
        }
      } 
   } else { task = "correct"; }
};

var sendRequest = function(str) {
   if(str==""){alert("please enter the code"); return;}
   req = null;
   url = "test3.php?id=" + str;
   method = "GET";
   try {
      if ( window.XMLHttpRequest ) {
      req = new XMLHttpRequest();
   } else if ( window.ActiveXObject ) {
         try {
         req = new ActiveXObject("Microsoft.XMLHTTP");
         } catch( e1 ) {
         req = new ActiveXObject("Msxml2.XMLHTTP");
         }
      }
   } catch( e2 ) {
   (( window.createRequest ) ? req = window.createRequest() : req = null );
   }
   (( req.overrideMimeType ) ? req.overrideMimeType("text/xml") : req );
   if ( req !== null ) { 
   req.onreadystatechange = handleRequest;
   req.open( method, url, true );
   (( req.setRequestHeader && …
servis 0 Junior Poster in Training

sorry essential, i used every method including all the instructions given by you, but no success....

servis 0 Junior Poster in Training

no luck sir....

servis 0 Junior Poster in Training

is it possible to use the xmlHTTP.responseText in any other java function, after execuation of stateChanged() function??? example in ajax...

function stateChanged(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
       var result = xmlHttp.responseText 		
        if (result.length=="0"){
        var task = "do";  //i want to use "task" in other js function
         return task; 
      }		
   }
}

i used many ways (a little bit i know) to do but could not get the success. how can we do???

any thoughts please......

servis 0 Junior Poster in Training

thank you essential, for giving so much ideas & solutions.

servis 0 Junior Poster in Training

actually, it is for capatcha securimage validation. when any user enters the wrong picture words in input field or does not enter any words, the script respond with message alert box, if he enter the right words, it just allows him to submit the form.

All the files are attached with the script discussed here as a test2.php. please change the extension of elephant.txt to elephan.ttf.

Thanks in advance....

servis 0 Junior Poster in Training

thank you very much essential for the solution. i was trying to get the solution for last 10days. i have a request, can you please post all the right code.

servis 0 Junior Poster in Training

thank you for detailed reply.
the script is running fine, when i enter no code in input box, it alerts "Please enter the right word" when enter right or wrong code it alerts "Thank you and this (</body> </html>)serves as a valid data.

servis 0 Junior Poster in Training

sorry, its just spellling mistake, but the result is at its place..

servis 0 Junior Poster in Training

i want to get the alert on responce text, but getting nothing, my code is as follow,

<?php  session_start(); ?>

<script type="text/javascript">
var xmlHttp
function checkCAP(str) {
	if (str=="") {
	alert("plase enter the code");
	return
}

xmlHttp=GetXmlHttpObject()
if (xmlHttp==null) {
	alert ("Browser does not support HTTP Request")
	return
}
var url="test.php"
    url=url+"?id="+str
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
	var response = xmlHttp.responseText;
      if( response == "incorrect"){
	  	alert(Please enter the right words); 
		}
 	} 
}

function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
	// Firefox, Opera 8.0+, Safari
	xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
	// Internet Explorer
	try {
	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e) {
	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	 }
  }
return xmlHttp;
}
</script>

<?php
if (!empty($_GET['id'])) { 
	include("securimage.php");
	$img = new Securimage();
	$valid = $img->check($_GET['id']);
	
	if($valid == true) {
    $responce = "correct";
  	} else {
    $responce = "incorrect";
  }
echo $responce;
} else { //form is posted
?>	
	<html>
	<head>
	  <title>Securimage Test Form</title>
	</head>
	<body>
	<form method="POST">
	<!-- pass a session id to the query string of the script to prevent ie caching -->
	<img src="securimage_show.php?sid=<?php echo md5(uniqid(time())); ?>"><br />
	<input type="text" name="code" onblur= "return checkCAP(this.value);"/><br />
	<input type="submit" value="Submit Form" />
	</form>
  <div id ="responce">Responce will be dispaly here</div>
<?php
}
?>
</body>
</html>

When i change the code as follow, i get all the source script in alert box...

function stateChanged(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
  	alert(xmlHttp.responceText); 
		}
 	} 
}

but when i change the code as follow, it runs very much fine, …

servis 0 Junior Poster in Training

thank you very much for the valueable comments.actually i want to ask something else. i am going to start new post for it.

servis 0 Junior Poster in Training

i want to display alert on the basis of responce text in AJAX, meaning to say i am getting responce text in id "responce " through php file by AJAX method, when responce is incorrect it shows alert before form submission the code is as follow,

<?php  session_start(); ?>

<script type="text/javascript">
var xmlHttp
function checkCAP(str) {
	if (str=="") {
	alert("plase enter the code");
	return
}

xmlHttp=GetXmlHttpObject()
if (xmlHttp==null) {
	alert ("Browser does not support HTTP Request")
	return
}
var url="test.php"
    url=url+"?id="+str
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
	document.getElementById("responce").innerHTML=xmlHttp.responseText
 	}
}

function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
	// Firefox, Opera 8.0+, Safari
	xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
	// Internet Explorer
	try {
	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e) {
	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	 }
  }
return xmlHttp;
}
</script>

<?php
if (!empty($_GET['id'])) { 
	include("securimage.php");
	$img = new Securimage();
	$valid = $img->check($_GET['id']);
	
	if($valid == true) {
    $responce = "correct";
  	} else {
    $responce = "incorrect";
  }
echo $responce;
} else { //form is posted
?>	
	<html>
	<head>
	  <title>Securimage Test Form</title>
	</head>
	<body>
	<form method="POST">
	<!-- pass a session id to the query string of the script to prevent ie caching -->
	<img src="securimage_show.php?sid=<?php echo md5(uniqid(time())); ?>"><br />
	<input type="text" name="code" onblur= "checkCAP(this.value);"/><br />
	<input type="submit" value="Submit Form" />
	</form>
  <div id ="responce">Responce will be dispaly here</div>
<?php
}
?>
</body>
</html>

however the script is running very much fine.
i have used may methods to but in vain..
please help somebody how to do it, …

servis 0 Junior Poster in Training

thank you very much for so helpful scripts.

servis 0 Junior Poster in Training

i want to populate drop down box values on the basis of other drop down box value dynamically(without refreshing the page) using java script. i tried to search on google, but could not find anything. please can anybody help me in this regards.

Thanks

servis 0 Junior Poster in Training

Thank you wblakenc, now the code is working very much fine on IE7, Safari and Fire Fox.

Thank you very much once again.

servis 0 Junior Poster in Training

thank you very much for your very good solutions, i tried them all but Unfortunately still no success, my complete code sample is as follow,

<html>
<head>
<title>DEMO</title>

<script type="text/javascript"><!--

function validate(form) {
with(form) {
	
if (( form.conPerP1.value == "" ) || ( form.conPerP2.value == "" ))
	 {
     alert("Please enter your telephone or cell no. to continue.");
     form.conPerP1.focus();
      return false;
      } return true; 
		
	if(!(form.agreement.checked)) {
	  alert("Please commit the agreement to continue.");
	  form.agreement.focus();
	  return false;
	    }else return true; 
	  }

 return true;
}
// --></script></head>

<?php
if(isset($_POST['put'])){
echo $_POST['conPerP1'];
echo $_POST['conPerP2'];
}
 ?>
<form method="POST" action="" onsubmit="return validate(this)">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" height="160">
<tr>
    <td width="25%" height="32" align="right"><font face="Calibri">Contact Person Phone No. 1:</font></td>
    <td width="75%" height="32">&nbsp;
	<input type="text" name="conPerP1" size="20"></td>
  </tr>

  <tr>
    <td width="25%" height="20" align="right"><font face="Calibri">Contact Person Phone No. 2:</font></td>
    <td width="75%" height="30">&nbsp;
	<input type="text" name="conPerP2" size="20"></td>
  </tr>

  <tr>
    <td height="30" colspan="2" align="left"><font face="Calibri">
    <input type="checkbox" name="agreement" value="checkbox"> I agree all the terms & conditions of this website </font></td>
  </tr>

 </table>
  <p align="center">
	<input name="put" type="submit" value="Submit" >
  </p>
</form>
</body>
</html>

secondly, agreement check validation is running fine on Safari but does not working same on IE.

Thnak you for your responses...

servis 0 Junior Poster in Training

the code did not work by removing with(form). however thank you very much for helping me...

servis 0 Junior Poster in Training

Thank you nav33 for guiding... 1st solution is very much working,
but 2nd one is nor working, the code is as follow,

function validate(form) {
with(form) {
if(form.conPerP1.value=="" || form.conPerP2.value=="") 
	{
		alert("Please enter your telephone or cell no. to continue.");
		return false;
		}
}
servis 0 Junior Poster in Training

i want to validate whether the checkbox is empty or not, if it is empty, the alert box show message, but the following code is not working...

function validate(form) {
with(form) {
   if(agreement.value.checked==false) 
  {
  alert("Please commit the agreement to continue.");
  agreement.focus();
  return false;
  }
}

Secondly, i want user must enter one any filed from two fields, for this i am using the following code, but it also not working,

function validate(form) {
with(form) {
   if(conPerP1.value=="" || conPerP2.value=="" ) 
  {
  alert("Please enter your telephone or cell no. to continue.");
  conPerP1.focus(); 
  return false;
  }
}

please help me in this regard, i tried a lot to search through GOOGLE but in vain..

Thanks in advance.....

servis 0 Junior Poster in Training

thanks for your valueable solutions...
please can you suggest me any tutorial for fruther and advance guidance in this regards...

shuja

servis 0 Junior Poster in Training

i am using POST method..
nav33n, when i use $action == 'preview' and $action=='submit', it does nothing with no error.

however, i just tried GET method, which is running fine.

But i wana use POST method....

servis 0 Junior Poster in Training

i want to provide an option to user to preview the form input before form submission, it runs well, but it does the same action on pressing submission or preview button

html

<form>
<tr>
    <td width="26%" height="30" align="right"><font face="Calibri">Category:</font></td>
 	<input type="text" name="category" size="30"></td>
 
    <td width="26%" height="30" align="right"><font face="Calibri">City:</font></td>
 	<input type="text" name="city" size="30"></td>
    
	<td width="26%" height="30" align="right"><font face="Calibri">Ad Title:</font></td>
 	<input type="text" name="adTitle" size="30"></td>
 
 </tr>
</table>

<p align="center">
<input name="put" type="submit" value="Submit" onclick="action='postAd.php?action=submit';"> 
<input name="put" type="submit" value="Preview" onclick="action='postAd.php?action=preview';">
</p>
</form>

the php script is as follow

if(isset($_POST['put'])) {

	$category = $_POST['category'];
	$city     = $_POST['city'];
	$adTitle  = $_POST['adTitle'];

$action = $_POST['action'];
if ($action = 'preview')
{

echo $category;
echo $city;
echo $adTitle;
}

if ($action = 'submit')
{
if (!get_magic_quotes_gpc()) {

    $category = addslashes($category);
	$city     = addslashes($city);
	$adTitle  = addslashes($adTitle);
   }  
$sql = "INSERT INTO `class-ads`.`post-ad` (ad_id, cat_name, city_name, ad_title, )
		            VALUES (NULL,'$category', '$city', '$adTitle')";

mysql_query($sql) or die('Error, Posting Ad failed : ' . mysql_error());                    
echo "You successfully posted the advertisment";
}
}

when i press submit it enters all data to database, but the same thing happens after pressing preview button as well.
i have tried every option, i know but in vain..i am not understanding where i am doing wrong. please some one guide me in this regard.

thanks in advance

shuja

servis 0 Junior Poster in Training

once again thank you sikka_varun for your valueable solution. actually i was using $sql return value of function instead of function its self. $result = mysql_query(PhotoListQuery'username','albumname','All'); now it is working very much fine..
once again thank you.....

servis 0 Junior Poster in Training

Thank you sikka_varun for your response, when i use the same query in regular scrips, it runs fine, but when it is used in finction it does not response without any error message.

However i tested your suggested query, but it also produce no response just as like the first one...

servis 0 Junior Poster in Training

Hellow evey body,

I have to use same sql query frequently on diferenet php scripts pages in a appliction, i want to put this query in a funtion to use it where i want but this funtion is not working at all. i am unable to figure out the problem, the code is as follow,

function PhotoListQuery ($user, $album, $imViewAuth){
{
$sql = "SELECT a.im_id, a.im_title, a.im_thumbnail, a.im_album_id, 
                         a.im_view_auth, DATE_FORMAT(a.im_date, '%d-%m-                         %Y') AS im_date, b.al_id, b.user_id 
             FROM  " . image . " a, " . album ." b  
           WHERE  b.user_id = $user AND  a.im_album_id = b.al_id AND
	        (a.im_view_auth = 'Show to every body' OR 
    		  a.im_view_auth = '$imViewAuth')";
if ($album != '') {
$sql .= "AND a.im_album_id = $album ";
}
$sql .= "ORDER BY a.im_title ";
}
return $sql;
}

please help....
thanks in advance

servis 0 Junior Poster in Training

sikka_varun thank you for your valueable solution...this is very much working.
jbennet, I think you may prevent these files path to steal by using php or some server side coding, if any body try to open the url, it send him the message "You are not allowed to view this file"...

servis 0 Junior Poster in Training

Hellow,

Can we prevent exposing java script and css in source code of web page on the user machine???

please if anybody know about it????

shuja

servis 0 Junior Poster in Training

yes, it was my mistake. this code is working fine......
Thank you very much Pritaeas and Rhyan......

servis 0 Junior Poster in Training

but this code is not working, some else solution please....

servis 0 Junior Poster in Training

hello everybody,

i want to pass directory name as a variable in include function like this,

$page = 'test';
include('$page/test.php');

i know this a wrong way, but i don't know how to do it.
please anybody help in this regard.

Thank in advance....

servis 0 Junior Poster in Training

hello,

i have following php-mysql image list script, which populate images in columns and rows of html tables, but i want to change the html columns and rows strctures into xhtml and css, i don't know how to do,

<?php
$albumId = $_GET['album'];
$query  = "SELECT im_id, im_title, im_thumbnail
                 FROM tbl_image
	 WHERE im_album_id = $albumId
	ORDER BY im_title";
$result = mysql_query($query) or die('Error, list image failed. ' . mysql_error());
if (mysql_num_rows($result) == 0) {
	echo "No image in this album yet";
} else {
	echo '<table width="700" border="0" cellspacing="1" cellpadding="2" align="center">';

	// the image is listed in a table 
	// here we specify how many columns 
	// we want to show on each row 
	$colsPerRow = 4;
	// width of each column in percent
	$colWidth   = (int)(100/$colsPerRow);
	$i = 0;
	while ($row = mysql_fetch_assoc($result)) {
		if ($i % $colsPerRow == 0) {
			// start a new row
			echo '<tr>';
		}

		echo '<td width="' . $colWidth . '%">' . 
		     '<a href="?page=image-detail&album=' . $albumId . '&image=' . $row['im_id'] . '">' . 
		     '<img src="viewImage.php?type=glthumbnail&name=' . $row['im_thumbnail'] . '" border="0">' .
        		 '<br>' . $row['im_title'] . '</a></td>';

		if ($i % $colsPerRow == $colsPerRow - 1) {
			// start a new row
			echo '</tr>';
		}		
		
		$i += 1;
	}
	
	// print blank columns
	if ($i % $colsPerRow != 0) {
		while ($i++ % $colsPerRow != 0) {
			echo '<td width="' . $colWidth . '%">&nbsp;</td>';
		}	
		echo '</tr>';
	}	
	
	echo '</table>';

}
?>

please help in this regard....