Jump to content

Can you let me know proper way to write this nested loop?


berde.jitendra

Recommended Posts

Hi All,

 

Can any body let me know what is proper way to write below code?

while($row = mysql_fetch_array($result))

{

  for ($colq=0; $colq<=$col_no;$colq++)

    {

  while($col = mysql_fetch_array($result_display_sequences))

          {

            for ($b=0; $b<=$seq_num;$b++)

              {

    echo $col[$b] . " ";

                  while($asso = mysql_fetch_array($result_column_associated))

                  {

                        for ($c=0; $c<=$asso_num;$c++)

                            {

  echo $asso[$c] . " ";

      if ($col[$b] == $asso[$c])

                        {  

                              echo "<td>" . $row[$colq] . "</td>";

                        }

                            }

                  }

              }

          }

      }

}

 

I want to match two values before display the result but somehow at first level its work perfect but then its didnt increase value $b as it should. So i lil but confuse now what am i doing wrong with it. Sorry i am new and trying something hard assignment while test my skill.

 

i do get result as below

2 2 3 4 5 6 7 8 9 10 11 3 4 5 6 7 8 9 10 11

 

Thanks in Advance.

Link to comment
Share on other sites

I have two columns in one table which have same values.  i am retrieving that values in two different query and while looping i am trying to match that value and if they match then it will display the which is store in first while loop.

 

I know its really wrong way but here is only one and no guidance as such. so finally come online for some help from genus guys.

 

any better way for this?

Link to comment
Share on other sites

I would but before that what ever i am fetching from database from that i want to display Name, Contact details, email address in same column while running the query. Also have comment section where user dynamically post a comment in text area. There is valid and invalid ajax code to make inquiry  valid or invalid. Will that be possible with one query.

 

Sorry i suppose to give all this requirement idea earlier.

 

Let me know if this possible.

 

Thanks for your reply.

Link to comment
Share on other sites

Please find my requirement:

 

I have multiple forms with different input field in it. Only three fields are common they are Name, Contact No, Email. Other information are different example is one form have country output and other not. So for this I am storing single forms information in different table. Other tables are similar are going to use in to fetch other information like add comment and status of enquiry.

 

However, I am confuse with database structure because there will unlimited column if I try to store information in single table. That’s why I am storing data in different table. My problem is that I want to display Name, Contact No, email are in single column. Also at the end want to add comment form which work with ajax to add user comment on the particular entry. Also next column will have validation status which also work with ajax help.

 

This whole requirement would require complicated code which I am not able to write it or doing something wrong because not getting result as want. If you want I will share my part code here.

 

Please let me know. Thanks in advance.

 

Link to comment
Share on other sites

Thanks for your reply.

 

Here i have attached my php code and sample data i am using for my work. My code is not well maintain sorry for that. Need a proper guidance for this.

 

Please let me know if you can help me out by any way.

 

please copy and paste your coding directly onto this thread, encased in code tags.

Link to comment
Share on other sites

<?PHP 
include("connect.php"); 
include("config.php"); 
include("auth.php"); 


$region=$_REQUEST['region'];
$fdate=$_REQUEST['date_from'];
$tdate=$_REQUEST['date_to'];

$datefrom = $_REQUEST['date_from'];
$dateto = $_REQUEST['date_to'];
$region = $_REQUEST['region'];

if($region==100)
{
  $region_name='Africa';
}else if($region=='All Regions')
{
   $region_name='All Regions';
}else if($region==200)
{
   $region_name='India';
}else if($region==300)
{
   $region_name='UK/ Europe';
}else if($region==400)
{
   $region_name='US/ ROW';
}

?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="style.css" type="text/css" />
<link rel="stylesheet" href="demos.css" type="text/css" />
<link rel="stylesheet" href="jquery.ui.all.css" type="text/css" />
<title>Internet leads</title>
<script src="sorttable.js" type="text/javascript"></script>
<script src="jquery-1.6.2.js" type="text/javascript"></script>
<script src="jquery.ui.widget.js" type="text/javascript"></script>
<script src="jquery.ui.datepicker.js" type="text/javascript"></script>
<script src="jquery.ui.core.js" type="text/javascript"></script> 
<script src="jquery.jtruncate.js" type="text/javascript"></script>

<!-- AJAX CODE-->

<script type="text/javascript">
function showUser(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","validinvalid.php?q="+str,true);
xmlhttp.send();
}
</script>

<!-- AJAX CODE END -->

<script type="text/javascript">
$().ready(function(){
   $(".sortable tr:even").addClass("zeb");
   $(".sortable tr:odd").addClass("zebr");
   $(".stripeMe tr td:first-child").addClass("bor_left");
});
</script>
	<script>
$(function() {
	$( "#datepickerfr" ).datepicker({dateFormat: 'yy-mm-dd'});
	$( "#datepickerto" ).datepicker({dateFormat: 'yy-mm-dd'});
});
</script>
   
<script>
//	$(function() {
//var settings = {
//    dateFormat: "yy-mm-dd",
//    changeMonth: true,
//    numberOfMonths: 1,
//    onSelect: function(selectedDate) {
//        var option = this.id == "from" ? "minDate" : "maxDate",
//            instance = $(this).data("datepicker"),
//            date = $.datepicker.parseDate(
//            instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
//        $("#from, #to").not(this).datepicker("option", option, date);
//    }
//};
//
//$("#to").datepicker(settings).val(function() {
//    var gotoCurrent = $( "#to" ).datepicker( "option", "gotoCurrent" );
//    return $.datepicker.formatDate(settings.dateFormat, new Date(), settings);
//});
//
//$("#from").datepicker(settings).val(function() {
//    var thirtyDaysAgo = new Date().getTime() - 30 * 1000 * 60 * 60 * 24;
//    return $.datepicker.formatDate(settings.dateFormat, new Date(thirtyDaysAgo), settings);
//});
//	});
//	</script>    
    
    
<script>
$(document).ready(function () {
$('.rmv-dft-val').click(
function() { 
if (this.value == this.defaultValue) 
{this.value = '';}});
$('.rmv-dft-val').blur(
function() {
if (this.value == '') {
this.value = this.defaultValue;
}
}
);
});
</script>

<script>
function compareDate()
{

valid =true;

var start = document.dashboard.date_from.value;
var end = document.dashboard.date_to.value;
var region = document.dashboard.region.value;

var fromd = Date.parse("start");
var tod = Date.parse("end");

if(start == '- Select date -')
{
  alert("Please enter from date");
  valid = false;
}
if(end == '- Select date -')
{
  alert("Please enter to date");
  valid = false;
} 
if(region == '')
{
  alert("Please select region");
  valid = false;
} 
return valid;
}
</script>
<script>
$().ready(function() {  
   $('.example1').jTruncate({  
       length: 100,  
       minTrail: 0,  
       moreText: "more",  
       lessText: "close",  
       ellipsisText: "",  
       moreAni: "",  
       lessAni: ""  
   });  
})
</script>

<SCRIPT>
function chkfield(){
with(document.frmviewcat){
for(i=0;i<elements.length;i++)
if( (elements[i].type=="checkbox") && (elements[i].name.indexOf("Cat_val[]")==0) )
elements[i].checked=true;
}
}
function unchk()
{
with(document.frmviewcat)
{
for(i=0;i<elements.length;i++)
{

if( (elements[i].type=="checkbox") && (elements[i].name.indexOf("Cat_val[]")==0) )
elements[i].checked=false;
}
}
}

function deletecategory(catno)
{
var f_len = document.frmviewcat.elements.length;
var count = 0;
for(i=0;i<=f_len-1;i++)
{
if(document.frmviewcat.elements[i].type == "checkbox" && document.frmviewcat.elements[i].checked==true)
{	
count++;
break;
}
}

if(count<=0)
{
alert("Please select record/s to Delete!!");
return false;
}
if(confirm("Are you sure with the status changes?"))
{
window.location = "http://www.value.com/campaigns/thank-you.php";
}
}
</SCRIPT>

<script type="text/javascript">
$(function() {
$(".invalidate").click(function(){

var element = $(this);
var noteid = element.attr("id");
var info = 'id=' + noteid;

$.ajax({
type: "POST",
url: "update.php",
data: info,
success: function(){

$('#Invalid'+noteid).fadeOut(200).show();
$('#Valid'+noteid).fadeOut(200).hide();
}
});

return false;
});
});

</script>

<script type="text/javascript">
$(function() {
$(".validate").click(function(){
var element = $(this);
var noteid = element.attr("id");
var info = 'id=' + noteid;

$.ajax({
type: "POST",
url: "validate.php",
data: info,
success: function(){

$('#Invalid'+noteid).fadeOut(200).hide();
$('#Valid'+noteid).fadeOut(200).show();
}
});

return false;
});
});

</script>

<script>
$(function() {

$(".formbut").click(function(){
jQuery.fn.delay = function(time,func){
    return this.each(function(){
        setTimeout(func,time);
    });
};

$('.excel').delay(10000, function(){
    $('.excel').fadeOut('fast');
    }
);
});});
</script>



<!--edit area code -->

<!--<script type="text/javascript">
$(document).ready(function()
{
$(".edit_td").click(function()
{
var ID=$(this).attr('id');
$("#first_"+ID).hide('slow');
$("#last_"+ID).hide();
$("#first_input_"+ID).show('slow');
$("#noteedit_"+ID).hide(1000);
$("#last_input_"+ID).show();
}).change(function()
{
var ID=$(this).attr('id');
var first=$("#first_input_"+ID).val();
var last=$("#last_input_"+ID).val();
var dataString = 'id='+ ID +'&firstname='+first+'&lastname='+last;
$("#first_"+ID).html('<img src="images/load.gif" />'); // Loading image

if(first.length>0)
{
$.ajax({
type: "POST",
url: "table_edit_ajax.php",
data: dataString,
cache: false,
success: function(html)
{
$("#first_"+ID).html(first);
}
});
}
else
{
alert('You have removed old contact history.');

$.ajax({
type: "POST",
url: "table_edit_ajax.php",
data: dataString,
cache: false,
success: function(html)
{
$("#first_"+ID).html(first);
}
});
$("#first_input_"+ID).show(1000);
$("#noteedit_"+ID).hide(1000);
}

});

// Edit input box click action
$(".editbox").mouseup(function() 
{
return false
});

// Outside click action
$(document).mouseup(function()
{
$(".editbox").hide();
$(".text").show();
$(".noteedit").show('slow');
});

});
</script>-->

<script type="text/javascript">

$(document).ready(function()
{
$(".edita").click(function()
{
var ID = $(this).attr('id');
$("#formbox"+ID).show();
$("#title"+ID).hide();
$("#noteedit_"+ID).hide(1000);
return false;
});

// Save Button

$(".save").click(function()
{
var A=$(this).parent().parent();
var X=A.attr('id');
var d=X.split("formbox"); // Splitting  Eg: formbox21 to 21
var id=d[1];
var Z=$("#"+X+" textarea.content").val();


var dataString = 'id='+ id +'&title='+Z ;
$.ajax({
type: "POST",
url: "table_edit_ajax.php",
data: dataString,
cache: false,
success: function(data)
{
A.hide();
$("#title"+id).html(Z);
$("#title"+id).show();
$("#noteedit_"+id).show(1000);
}
});
return false;
});

$(".cancel").click(function()
{
var A=$(this).parent().parent();
var X= A.attr("id");
var d=X.split("formbox");
var id=d[1];
$("#title"+id).show();
$("#noteedit_"+id).show(1000);
A.hide();
return false;
});

$(".editform").mouseup(function() 
{
return false
});

$(document).mouseup(function()
{
$(".editform").hide();
$(".contentshow").show();
$(".noteedit").show('slow');
});

});

</script>

</head>
<body>
<?PHP 
$lastmonth1 =mktime(0, 0, 0, date("m")-1, date("d"),   date("Y"));
$lastmonth = date('Y-m-d', $lastmonth1);
$gettodaysdate1 =mktime(0, 0, 0, date("m"), date("d"),   date("Y"));
$todaysdate = date('Y-m-d', $gettodaysdate1);
?>

<div id="header"><div class="banner"><!--<img src="images/online.jpg" alt="" title="" border="0" />--><h1>Internet leads</h1><div class="login">Welcome <span class="username"><?PHP echo $firstname. " " . $lastname; ?></span><span class="signout"><a href="index.php">Sign out</a></span></div></div></div>
<div id="bottom"><div id="content"><div class="form_search"><!--<h1>Internet enquiries</h1>-->
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" class="searchf" method="post" name="dashboard" onSubmit="return compareDate ( );"><p><label>From</label><?php /*?><input type="text" class="date" id="from" name="date_from" value="<?PHP if($fdate=="") {echo "";} else {echo $fdate;} ?>" /><?php */?><input type="text" class="date" name="date_from" value="<?PHP if($fdate=="") {echo $lastmonth;} else {echo $fdate;} ?>" id="datepickerfr" />
<span>yyyy-mm-dd</span></p><p><label>To</label><input type="text" class="date" value="<?PHP if($tdate=="") echo $todaysdate; else echo $tdate; ?>" id="datepickerto" name="date_to"/> <span>yyyy-mm-dd</span></p>
<!-- Region Display -->

<?PHP 
//$query_region = "SELECT brand_regions.region_name, brand_regions.region_id, userslogin.id FROM brand_regions, userslogin WHERE userslogin.region_id=brand_regions.region_id AND userslogin.region_id='$region_code'";
//mysql_query($query_region) or die('Error fetching result');
//$result_region = mysql_query($query_region);
//$num_region=mysql_num_rows($result_region);
//$row_region = mysql_fetch_array($result_region);

if($user_level < 300)
{

// Query to get drop down option.

$region_query = "Select region_id, region_name from brand_regions where brand_id=$brand_id";
mysql_query($region_query) or die('Error fetching result');
$region_result=mysql_query($region_query);

// Query end

echo "<p><label>Region</label>";
echo "<select name='region' id='region'>";
echo "<option value='All Regions'"; if($region=='All Regions'){ echo 'selected'; }echo ">"; echo "All Regions" ; echo "</option>";
while($row_region = mysql_fetch_array($region_result))
{
   echo "<option value='" .$row_region['region_id']. "'";  if($region==$row_region['region_id']){ echo 'selected'; } echo ">" . $row_region['region_name'] . "</option>";
   //echo "<option value='"; echo $row_region['region_id']."'"; if($region==$row_region['region_id']){ echo 'selected'; }echo ">"; $row_region['region_name'] ; echo "</option>";
}
echo "</select>";
echo "</p>";
//echo "<option value='US/ROW'"; if($region=='us_row') echo 'selected';">". US/ROW ."</option>";
//echo "<option value='All Regions'"; if($region=='All Regions') echo 'selected';">" .All . " " . Regions. "</option>";

}
else
{
echo "<p><label>Region</label><input class='region' value='$region_name' readonly='readonly'><input name='region' value='$region_code' type='hidden'><input name='userid' value='$row_region[id]' type='hidden'  disabled='disabled'></p>";
}
?>
<p class="buttons">
<input type="submit" value="View leads" name="submit" class="leadbut" />
<?PHP 
// echo "<a href='download_excel.php?export=1&from=$datefrom&to=$dateto&region=$region'><input type='button' value='Download leads' //name='download' class='formbut excel' /></a>"; ?>
</p></form></div>

<?PHP

$datefrom = $_REQUEST['date_from'];
$dateto = $_REQUEST['date_to'];
$region = $_REQUEST['region'];

if (($region == "All Regions") && ($user_level < '300'))
{

// Query to fine column names for select query 

$columns_query= "Select column_name from columns_list_to_display where brand_id=$brand_id AND column_name!='NULL' ORDER BY display_sequences";
$result=mysql_query($columns_query);
$result1=mysql_query($columns_query);

$col_no = mysql_num_rows($result);

// Query end

// To get Column names seprated by ',' 

while ($orow = mysql_fetch_array($result1))
$implode[] = $orow['column_name'];
$comma_columns_array = implode(",", $implode);
echo $comma_columns_array . "<BR><BR>";

// To get column names in array
$numberoffileds = mysql_num_rows($result);
while ($orow1 = mysql_fetch_array($result))
{
  $columns_array[] = $orow1['column_name'];
}



// Query to get data of leads to display 

$query  = "SELECT $comma_columns_array FROM $userlead_table 
          LEFT JOIN notes ON $userlead_table.id = notes.leads_id 
   	      LEFT JOIN lead_status ON $userlead_table.status = lead_status.status_code
          WHERE ((Date(submitted)>='$datefrom' AND Date(submitted)<='$dateto'))
      ORDER BY submitted DESC"; 
	  
echo $query;
	  
mysql_query($query) or die('Error fetching result');
$result=mysql_query($query);

$num=mysql_num_rows($result);

if ($num == 0)
{ 
  echo " ";
}
else
{
echo "<div class=result_strip><strong>" . $num . "</strong> "; if ($num<=1){echo "enquiry";} else {echo "enquiries"; }
echo " received from <strong>".  date('M d, Y',strtotime($datefrom)) . "</strong> to <strong>". date('M d, Y',strtotime($dateto)) ."</strong> for <strong>" . $region_name . "</strong>.</div>";
echo "<div class=result><table border=0 cellspacing=0 cellpadding=0 width=1250px class='sortable'>";
echo "<thead><tr>";

// Query to fetch and display the column tiltes

$columns_title_query= "Select field_title, display_sequences from columns_list_to_display where brand_id=$brand_id AND field_title != 'NULL' order by display_sequences";
mysql_query($columns_title_query) or die('Error fetching result');
$columns_title_result = mysql_query($columns_title_query);

// retreive display_sequences and column_associated

$query_display_sequences = "Select display_sequences from columns_list_to_display where brand_id=$brand_id AND field_title != 'NULL' order by display_sequences";
$query_column_associated = "Select column_associated from columns_list_to_display where brand_id=$brand_id AND field_title != 'NULL' order by display_sequences";

$result_display_sequences = mysql_query($query_display_sequences) or die('Error fetching result');
$result_column_associated = mysql_query($query_column_associated) or die('Error fetching result');

$seq_num= mysql_num_rows($result_display_sequences);
$asso_num= mysql_num_rows($result_column_associated);

//$seq[] = mysql_fetch_array($result_display_sequences);
//$asso[] = mysql_fetch_array($result_column_associated);



//$columns_array = mysql_fetch_array($columns_title_result);

$columns_count = mysql_num_rows($columns_title_result);




while($col = mysql_fetch_array($columns_title_result))
{
  echo "<th class='sorttable_nosort'>" . $col['field_title'] . "</th>";
}
echo "</tr></thead><tbody>";


echo "<tr>";
while($row = mysql_fetch_array($result))
{
   for ($colq=0; $colq<=$col_no;$colq++)
    { 	
   	 echo "<td>" . $colq . "</td>";
}
echo "</tr>";
}
echo "</tbody></table></div>";}
// code to diplay record of leads
//  for ($a='0';$a<=$columns_count;$a++)
//    { 

//
//       while($row = mysql_fetch_row($result))
//	   {
//	      for ($f=0; $f <=15; $f++) 
//		    {
//			   if ($f==0)
//			    {
//				  echo "<td>". $f . " " . date('M d, Y',strtotime($row[$f])). "</td>";
//				}
//				if ($f==1)
//			    {
//				  echo "<td>". $f . " " . $row[$f] . "</td>";
//				}
//				if ($f==2)
//			    {
//				  echo "<td>". $f . " " . $row[$f] . "</td>";
//				}
//				if ($f==3)
//			    {
//				  echo "<td>". $f . " " . $row[$f] . "</td>";
//				}
//				if ($f==4)
//			    {
//				  echo "<td>". $f . " " . $row[$f] . "</td>";
//				}
//				if ($f==5)
//			    {
//				  echo "<td>". $f . " " . $row[$f] . "</td>";
//				}
//				if ($f==6)
//			    { 
//				 echo "<td>";
//				  $g = $f;
//				  for ($g=$f; $f<=8; $f++) 
//				  {	   
//     			    echo $row[$f] . "<br>";
//				  }
//				  echo "</td>";
//				}
//				if ($f==9)
//			    {
//				  echo "<td style='empty-cells:show'><div class=example1>". $row[$f]."</div></td>";
//				}	
//				if ($f==10)
//			    {
//		echo "<td style='empty-cells:show' class='edita' id='";		 
//		echo $row['id'];
//		echo "'>";
//        echo "<div id='formbox"; echo $row['id'] . "' style='display:none' class='editform'>";
//		echo "<form method='post' name='form"; echo $row['id']; echo"'>";
//		echo "<textarea class='content' name='content'>";		 
//		echo $row['comments']; 
//		echo "</textarea><br>";	
//		echo "<input type='submit' value='Save' class='save' />    ";
//		echo "<input type='button' value='Cancel' class='cancel'/>";
//		echo "</form>";
//		echo "</div>";
//		echo "<h4 id='title"; echo $row['id'] . "' class='contentshow'>";
//        echo $row['comments'];
//		echo "</h4>";
//		echo "<span id='noteedit_"; echo $row['id'] . "' class='noteedit'>";
//		echo "Update";
//		echo "</span>";
//		echo "</td>";
//				}	
//				if ($f==11)
//			    {
//				$h=$f;
//				$t=3;
//				$id=$h+$t;
//	    echo "<td class='tdstatus'>"; 
//		$query_set_status_class= "Select * from lead_status where brand_id=$brand_id LIMIT 0, 1";
//     	$result_query_set_status_class = mysql_query($query_set_status_class);
//		  while($row_result = mysql_fetch_array($result_query_set_status_class))
//		  {
//		    $match_title = $row_result['status_code'];
//			
//		  }
//        if ($row[$f]==$match_title)
//		{
//		echo "<div id='Valid"; 
//		echo $row[$id]; echo "'>";
//		echo "<div class='statusvalid'>" . $row[12] . "</div>";
//		echo "<a id="; echo $row[$id]. " class='invalidate' href='#'>";
//		echo $row[13]; 
//		echo "</a>";
//		echo "</div>";
//        $query_opposite = "Select * from lead_status where status_title!='$row[12]' AND brand_id=$brand_id";	
//		$result_opposite=mysql_query($query_opposite);
//		$values_opposite = mysql_fetch_assoc($result_opposite);
//		$status_title = $values_opposite['status_title'];
//		$link_text = $values_opposite['link_text'];
//		echo "<div id='Invalid"; 
//	    echo $row[$id]; echo "' style='display:none'>"; 
//		echo "<div class='statusinvalid'>" . $status_title . "</div>"; 
//		echo "<a id="; echo $row[$id]. " class='validate' href='#'>";
//		echo $link_text;
//		echo "</a>";
//		echo "</div></td>";
//		} 
//		else 
//		{
//		echo "<div id='Invalid"; 
//		echo $row[$id]; echo "'>";
//		echo "<div class='statusinvalid'>" . $row[12] . "</div>";
//		echo "<a id="; echo $row[$id]. " class='validate' href='#'>";
//		echo $row[13]; 
//		echo "</a>";
//		echo "</div>";
//        $query_opposite = "Select * from lead_status where status_title!='$row[12]' AND brand_id=$brand_id";	
//		$result_opposite=mysql_query($query_opposite);
//		$values_opposite = mysql_fetch_assoc($result_opposite);
//		$status_title = $values_opposite['status_title'];
//		$link_text = $values_opposite['link_text'];
//		echo "<div id='Valid"; 
//	    echo $row[$id]; echo "' style='display:none'>"; 
//		echo "<div class='statusvalid'>" . $status_title . "</div>"; 
//		echo "<a id="; echo $row[$id]. " class='invalidate' href='#'>";
//		echo $link_text;
//		echo "</a>";
//		echo "</div></td>";
//		}
//				}																		
//			}echo "</tr>";
//	   }    
//}
//for ($i='1'; $i<=$num; $i++)
// {
//  echo"<tr valign=top>";
//  echo"<td class=sr_no>". $i ."</td>";

//if ($columns_array[0] == 'submitted')  
//   {
//     echo "<td>".$row[$f]."</td>";
//   }

//for ($i=0; $i < mysql_num_rows($result); $i++)
//
// while($row = mysql_fetch_row($result))     {	
////     for ($f=0; $f < $numberoffileds; $f++)
//	      {
//		     echo "<td>".$row[$f]."</td>";
//		  }
    
/*		echo"<td style='empty-cells:show'><div class='date1'>". date('M d, Y',strtotime($row['submitted']))."</div></td>";
	echo"<td style='empty-cells:show'><div class='country'>".$row[0]."</div></td>";	
	echo"<td style='empty-cells:show'><div class='city'>".$row['city']."</div></td>";
	echo"<td style='empty-cells:show'><div class='organi'>".$row['organization']."</div></td>";	
        echo"<td style='empty-cells:show'><div class='org_web'>".$row['website']."</div></td>";
	echo"<td style='empty-cells:show'><div class='desig'>".$row['designation']."</div></td>";							
	echo"<td style='empty-cells:show'><div class=info><p class=info1>". " " . $row['title'] ." ".$row['yourname']. "</p>" . "</p>" . "<p>" .$row['email']. "</p>" . "<p><lable>Ph:</lable>" .$row['phone']. "</div></td>";
	echo "<td style='empty-cells:show'><div class=example1>". $row['need']."</div></td>";
	echo "<td style='empty-cells:show' class='edita' id='";		 
	echo $row['id'];
	echo "'>";
        echo "<div id='formbox"; echo $row['id'] . "' style='display:none' class='editform'>";
	echo "<form method='post' name='form"; echo $row['id']; echo"'>";
	echo "<textarea class='content' name='content'>";		 
	echo $row['comments']; 
	echo "</textarea><br>";	
	echo "<input type='submit' value='Save' class='save' />    ";
	echo "<input type='button' value='Cancel' class='cancel'/>";
	echo "</form>";
	echo "</div>";
	echo "<h4 id='title"; echo $row['id'] . "' class='contentshow'>";
        echo $row['comments'];
	echo "</h4>";
	echo "<span id='noteedit_"; echo $row['id'] . "' class='noteedit'>";
	echo "Update";
	echo "</span>";
	echo "</td>";
    echo "<td class='tdstatus'>"; 
	$query_set_status_class= "Select * from lead_status where brand_id=$brand_id LIMIT 0, 1";
     	$result_query_set_status_class = mysql_query($query_set_status_class);
	  while($row_result = mysql_fetch_array($result_query_set_status_class))
	  {
	    $match_title = $row_result['status_code'];
	  }
        if ($row['status_code']==$match_title)
	{
	echo "<div id='Valid"; 
	echo $row['id']; echo "'>";
	echo "<div class='statusvalid'>" . $row['status_title'] . "</div>";
	echo "<a id="; echo $row['id']. " class='invalidate' href='#'>";
	echo $row['link_text']; 
	echo "</a>";
	echo "</div>";
        $query_opposite = "Select * from lead_status where status_code!=$row[status_code]";	
	$result_opposite=mysql_query($query_opposite);
	$values_opposite = mysql_fetch_assoc($result_opposite);
	$status_title = $values_opposite['status_title'];
	$link_text = $values_opposite['link_text'];
	echo "<div id='Invalid"; 
    echo $row['id']; echo "' style='display:none'>"; 
	echo "<div class='statusinvalid'>" . $status_title . "</div>"; 
	echo "<a id="; echo $row['id']. " class='validate' href='#'>";
	echo $link_text;
	echo "</a>";
	echo "</div></td>";
	} 
	else 
	{
	echo "<div id='Invalid"; 
	echo $row['id']; echo "'>";
	echo "<div class='statusinvalid'>" . $row['status_title'] . "</div>";
	echo "<a id="; echo $row['id']. " class='validate' href='#'>";
	echo $row['link_text']; 
	echo "</a>";
	echo "</div>";
        $query_opposite = "Select * from lead_status where status_code!=$row[status_code] AND brand_id=$brand_id";	
	$result_opposite=mysql_query($query_opposite);
	$values_opposite = mysql_fetch_assoc($result_opposite);
	$status_title = $values_opposite['status_title'];
	$link_text = $values_opposite['link_text'];
	echo "<div id='Valid"; 
    echo $row['id']; echo "' style='display:none'>"; 
	echo "<div class='statusvalid'>" . $status_title . "</div>"; 
	echo "<a id="; echo $row['id']. " class='invalidate' href='#'>";
	echo $link_text;
	echo "</a>";
	echo "</div></td>";
	}*/
//	    echo "</tr>";		  
//		break;
//}}
//echo "</tbody></table></div>";}
mysql_close($connection);
}
elseif (($region == "100" || $region == "200" || $region == "300" || $region == "400") && ($userid < "300"))
{
$query = "SELECT id,
             Date(submitted),
             title,
		 yourname, 
		 designation, 
		 organization, 
		 website, 
		 country, 
		 city, 
		 phone, 
		 email,
		 status, 
		 need 
       FROM secondclient_web_leads AS a LEFT JOIN notes AS b 
       ON a.id = b.leads_id 
       WHERE ((Date(a.submitted)>='$datefrom' AND Date(a.submitted)<='$dateto'))  
          AND (region_id='$region')
          ORDER BY Date(submitted) DESC";  
	  
mysql_query($query) or die('Error fetching result');
$result=mysql_query($query);
$num=mysql_num_rows($result);

if ($num == 0)
{ 
  echo " ";
}
else
{
echo "<div class=result_strip><strong>" . $num . "</strong> "; if ($num<=1){echo "enquiry";} else {echo "enquiries"; }
echo " received from <strong>".  date('M d, Y',strtotime($datefrom)) . "</strong> to <strong>". date('M d, Y',strtotime($dateto)) ."</strong> for <strong>" . $region_name . "</strong>.</div>";
echo "<div class=result><table border=0 cellspacing=0 cellpadding=0 width=1150px class='sortable'>";
echo "<thead><tr><th width=20px class='sorttable_nosort'>S.<BR />No.</th><th width=75px class='sorttable_nosort'>Date of<BR />enquiry</th><th width=80px>Country</th><th width=70px>City</th><th>Organisation</th><th>Website</th><th width=90px>Designation</th><th width=180px class='sorttable_nosort'>Contact details</th><th width=200px class='sorttable_nosort'>Query</th><th width=100px>Contact history</th><th width=20px>Status</th></tr></thead><tbody>";
for ($i='1'; $i<=$num; $i++)
  {
  echo"<tr valign=top>";
  echo"<td class=sr_no>". $i ."</td>";
/*  while($row = mysql_fetch_array($result))
     {	    
	echo"<td style='empty-cells:show'><div class='date1'>". date('M d, Y',strtotime($row['Date(submitted)']))."</div></td>";
	echo"<td style='empty-cells:show'><div class='country'>".$row['country']."</div></td>";		
	echo"<td style='empty-cells:show'><div class='city'>".$row['city']."</div></td>";
	echo"<td style='empty-cells:show'><div class='organi'>".$row['organization']."</div></td>";	
        echo"<td style='empty-cells:show'><div class='org_web'>".$row['website']."</div></td>";
	echo"<td style='empty-cells:show'><div class='desig'>".$row['designation']."</div></td>";							
	echo"<td style='empty-cells:show'><div class=info><p class=info1>". " " . $row['title'] ." ".$row['yourname']. "</p>" . "</p>" . "<p>" .$row['email']. "</p>" . "<p><lable>Ph:</lable>" .$row['phone']. "</div></td>";
	echo "<td style='empty-cells:show'><div class=example1>". $row['need']."</div></td>";
	echo "<td style='empty-cells:show' class='edita' id='";		 
	echo $row['id'];
	echo "'>";
        echo "<div id='formbox"; echo $row['id'] . "' style='display:none' class='editform'>";
	echo "<form method='post' name='form"; echo $row['id']; echo"'>";
	echo "<textarea class='content' name='content'>";		 
	echo $row['comments']; 
	echo "</textarea><br>";	
	echo "<input type='submit' value='Save' class='save' />    ";
	echo "<input type='button' value='Cancel' class='cancel'/>";
	echo "</form>";
	echo "</div>";
	echo "<h4 id='title"; echo $row['id'] . "' class='contentshow'>";
        echo $row['comments'];
	echo "</h4>";
	echo "<span id='noteedit_"; echo $row['id'] . "' class='noteedit'>";
	echo "Update";
	echo "</span>";
	echo "</td>";
	echo "<td class='tdstatus'>"; 
	if ($row['status']=='Qualified') 
	{
	   echo "<div id='Valid"; 
	   echo $row['id']; echo "'>"; 
	   echo "<div class='statusvalid'>" . $row['status'] . "</div>";
	   echo "<a id="; echo $row['id']. " class='invalidate' href='#'>";
	   echo "Mark as Disqualified</a>"; 
	   echo "</div>";
	   echo "<div id='Invalid"; 
	   echo $row['id']; echo "' style='display:none'>"; 
	   echo "<div class='statusinvalid'>" . Disqualified . "</div>"; 
	   echo "<a id="; echo $row['id']. " class='validate' href='#'>";
	   echo "Mark as Qualified</a>";
	   echo "</div></td>";
	   
	} 
	elseif ($row['status']=='Disqualified') 
	{
	   echo "<div id='Invalid"; 
	   echo $row['id']; echo "'>"; 
	   echo "<div class='statusinvalid'>" . $row['status'] . "</div>";
	   echo "<a id="; echo $row['id']. " class='validate' href='#'>";
	   echo "Mark as Qualified</a>";
	   echo "</div>";
	   echo "<div id='Valid"; 
	   echo $row['id']; echo "' style='display:none'>"; 
	   echo "<div class='statusvalid'>" . Valid . "</div>";
	   echo "<a id="; echo $row['id']. " class='invalidate' href='#'>";
	   echo "Mark as Disqualified</a>"; 
	   echo "</div></td>";		   
          }

    echo "</tr>";		  
	break;
}*/}echo "</tbody></table></div>";}
mysql_close($connection);
}


// For normal user result
else
{
$query = "SELECT a.id,
       a.submitted,
       a.yourname, 
       a.designation, 
       a.organization, 
       a.website, 
       a.country, 
       a.city, 
       a.phone, 
       a.email,
       a.status, 
       a.need,
       b.comments,
   c.status_title,
   c.status_code,
   c.link_text
       FROM $userlead_table AS a
       LEFT JOIN notes AS b ON a.id = b.leads_id 
   	   LEFT JOIN lead_status AS c ON a.status = c.status_code
       WHERE ((Date(a.submitted)>='$datefrom' AND Date(a.submitted)<='$dateto')) AND (region_id='$region') AND (status='1000')
    ORDER BY Date(submitted) DESC"; 



mysql_query($query) or die('Error fetching result');
$result=mysql_query($query);
$num=mysql_num_rows($result);

if ($num == 0)
{ 
  echo " ";
}
else
{
echo "<div class=result_strip><strong>" . $num . "</strong> "; if ($num<=1){echo "enquiry";} else {echo "enquiries"; }
echo " received from <strong>".  date('M d, Y',strtotime($datefrom)) . "</strong> to <strong>". date('M d, Y',strtotime($dateto)) ."</strong> for <strong>" . $region_name . "</strong>.</div>";
echo "<div class=result><table border=0 cellspacing=0 cellpadding=0 width=1150px class='sortable'>";
echo "<thead><tr><th width=20px class='sorttable_nosort'>S.<BR />No.</th><th width=75px class='sorttable_nosort'>Date of<BR />enquiry</th><th width=80px>Country</th><th width=70px>City</th><th>Organisation</th><th>Website</th><th width=90px>Designation</th><th width=180px class='sorttable_nosort'>Contact details</th><th width=200px class='sorttable_nosort'>Query</th><th width=100px>Contact history</th></tr></thead><tbody>";
for ($i='1'; $i<=$num; $i++)
  {
  echo"<tr valign='top'>";
  echo"<td class=sr_no>". $i . "</td>";
  while($row = mysql_fetch_array($result))
     {	
	echo"<td style='empty-cells:show'><div class='date1'>". date('M d, Y',strtotime($row['Date(submitted)'])) ."</div></td>";
	echo"<td style='empty-cells:show'>".$row['country']."</td>";	
	echo"<td style='empty-cells:show'><div class='city'>".$row['city']."</div></td>";
	echo"<td style='empty-cells:show'><div class='organi'>".$row['organization']."</div></td>";	
        echo"<td style='empty-cells:show'><div class='org_web'>".$row['website']."</div></td>";
	echo"<td style='empty-cells:show'><div class='desig'>".$row['designation']."</div></td>";							
	echo"<td style='empty-cells:show'><div class=info><p class=info1>". " " . $row['title'] ." ".$row['yourname']. "</p>" . "</p>" . "<p>" .$row['email']. "</p>" . "<p><lable>Ph:</lable>" .$row['phone']. "</div></td>";
	echo "<td style='empty-cells:show'><div class=example1>". $row['need']."</div></td>";		
	echo "<td style='empty-cells:show' class='edita' id='";		 
	echo $row['id'];
	echo "'>";
        echo "<div id='formbox"; echo $row['id'] . "' style='display:none' class='editform'>";
	echo "<form method='post' name='form"; echo $row['id']; echo"'>";
	echo "<textarea class='content' name='content'>";		 
	echo $row['comments']; 
	echo "</textarea><br>";	
	echo "<input type='submit' value='Save' class='save' />    ";
	echo "<input type='button' value='Cancel' class='cancel'/>";
	echo "</form>";
	echo "</div>";
	echo "<h4 id='title"; echo $row['id'] . "' class='contentshow'>";
        echo $row['comments'];
	echo "</h4>";
	echo "<span id='noteedit_"; echo $row['id'] . "' class='noteedit'>";
	echo "Update";
	echo "</span>";
	echo "</td></tr>";		
	break;
}}echo "</tbody></table></div>";}


mysql_close($connection);
}

?>
</div></div>
</body>
</html>

Link to comment
Share on other sites

Please find my requirement:

 

I have multiple forms with different input field in it. Only three fields are common they are Name, Contact No, Email. Other information are different example is one form have country output and other not. So for this I am storing single forms information in different table. Other tables are similar are going to use in to fetch other information like add comment and status of enquiry.

 

However, I am confuse with database structure because there will unlimited column if I try to store information in single table. That’s why I am storing data in different table. My problem is that I want to display Name, Contact No, email are in single column. Also at the end want to add comment form which work with ajax to add user comment on the particular entry. Also next column will have validation status which also work with ajax help.

 

This whole requirement would require complicated code which I am not able to write it or doing something wrong because not getting result as want. If you want I will share my part code here.

 

Please let me know. Thanks in advance.

 

You're approaching the structure of your tables wrong. Instead of an "unlimited number of columns" - which would be a maintenance nightmare - you should be utilizing rows, which is really the power behind relational tables.

 

Although I don't at all understand the relationship between the original code snippet you posted and the above description? Also we can't give you some magic code to do what you want, because it's heavily dependant on what you're trying to achieve. The description above is still too vague to suggest the best way of approaching it.

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.