Loopy loops.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Loopy loops.

Post by $var »

Can anyone see where/why this error is coming up?

I stripped the following code to only include the loops, and it appears they are all closed... but i'm still getting this error, which appears to be directly related to the second last close bracket... everything before it performs, all after is this:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Code: Select all

$issueID = $_GET['ID'];
		$sql2 = "SELECT COUNT(*) FROM it_discussion WHERE Thread_IID = '$issueID' AND Thread_X ='0'";
		$numrecord = mysql_query($sql5);
		$numrecords = mysql_fetch_array($numrecord);
	
		$numThread=$numrecords[0];
		if ($numThread <='1'){
		echo "";
		}
		else {
		echo "<table width='750' cellpadding='2' cellspacing='0' class='caltable'>";
		$intRecsPerPage=100;
		if($_POST["intpage"]=="")
		{
			$intpage=1;
		}
		$sql2 = "SELECT * FROM it_discussion WHERE Thread_IID = '$issueID' AND Thread_X ='0' ORDER BY Thread_ID ASC LIMIT ".(($intpage-1)*$intRecsPerPage).", ".$intRecsPerPage;
		$resultthread = mysql_query($sql2) or die (mysql_error()); 
	
		$totalpages = intval(($numrecords[0])/$intRecsPerPage);
		if(intval($numrecords[0]/$intRecsPerPage) != ($numrecords[0]/$intRecsPerPage))
       	{
       		$totalpages = $totalpages + 1;
       	}

		for($x = (($intpage-1) * $intRecsPerPage); $x < (($intpage-1) * $intRecsPerPage) + $intRecsPerPage; $x++)
		{
			if($x/2 != intval($x/2))
					{
						$bgcolor = "#ffffff";
					}
					else
					{
					$bgcolor = "#F7F7F7";
					}
			if($x >= $numrecords[0])
			{
				break;
			}
		$threadresults = mysql_fetch_array($resultthread);	
		$threadID = $threadresults['Thread_ID'];
		$threadAuthor = $threadresults['Thread_UID'];
		$threadDate = $threadresults['Thread_Date'];
		$threadTtl = $threadresults['Thread_Ttl'];		
		$threadText = $threadresults['Thread_Text'];				

	//members	
	$sql1 = "SELECT * FROM it_mem WHERE Mem_ID=".$threadAuthor;
	$resultmem = mysql_query($sql1) or die (mysql_error()); 
	$memresults = mysql_fetch_array($resultmem);
	

	//status
	$sql2 = "SELECT * FROM it_status";
	$resultstatus = mysql_query($sql2) or die (mysql_error()); 
	$statusresults = mysql_fetch_array($resultstatus);

	//type
	$sql3 = "SELECT * FROM it_type";
	$resulttype = mysql_query($sql3) or die (mysql_error()); 
	$typeresults = mysql_fetch_array($resulttype);
	$typeRequest=$typeresults['Type_Name'];	

	//dept	
	$sql4 = "SELECT * FROM it_division WHERE Div_ID = '$issueDept'";
	$resultdiv = mysql_query($sql4) or die (mysql_error()); 
	$divresults = mysql_fetch_array($resultdiv);	
	$divName = $divresults['Div_Name'];		

	//assignment	
	$sql4 = "SELECT * FROM it_assignment WHERE Assign_TID = '$threadID' ORDER BY Assign_ID DESC";
	$resultassign = mysql_query($sql4) or die (mysql_error()); 
	$assignresults = mysql_fetch_array($resultassign);	
	$assignThread = $assignresults['Assign_TID'];
	$assignIssue = $assignresults['Assign_IID'];
	$assignAuthor = $assignresults['Assign_UID'];
	$assignNew = $assignresults['Assign_NID'];
	$assignDate = $assignresults['Assign_Date'];	
	
	//members	
	$sql5 = "SELECT * FROM it_mem WHERE Mem_ID=".$assignAuthor;
	$resultassigned = mysql_query($sql5) or die (mysql_error()); 
	$assignedresult = mysql_fetch_array($resultassigned);
	$assignedName = $assignedresults['Mem_FName'];

	//members	
	$sql6 = "SELECT * FROM it_mem WHERE Mem_ID=".$assignNew;
	$resultassignedN = mysql_query($sql6) or die (mysql_error()); 
	$assignedNresult = mysql_fetch_array($resultassignedN);
	$assignedNFName = $assignedNresult['Mem_FName'];
	$assignedNLName = $assignedNresult['Mem_LName'];		
							
	echo "<tr valign='top' bgcolor='#FFFFFF'>"; 
     echo "<td width='100%' align='left' valign='top'>"; 
	  
	  echo "By <font class='style2'>$memresults[Mem_FName] $memresults[Mem_LName] </font>on ";
	  echo convertdate($threadresults['Thread_Date']); 
	  echo "<hr size='1' noshade width='600'>";
	  echo "<ul>";
	  echo "$threadText";
	  echo "<ul><hr size='1' width='600' noshade><br>";
	  echo "<font class='style3'>";
      echo "Reassigned to ";
	  echo "$assignedNFName $assignedNLName as a $typeRequest";								 
	  echo "</font></ul>";  
	  echo "</ul>";  
	}
	}
		echo "</td></tr></table>";

Code: Select all

{
		}

               {
		     {
		     }
		
       	             {      		
       	             }

		
		{
			
					{
						
					}
					
					{
					
					}
			
			{
				
			}
		
	}
	}
User avatar
Fractal
Forum Commoner
Posts: 54
Joined: Tue Aug 16, 2005 1:28 pm

Re: Loopy loops.

Post by Fractal »

$var wrote:Can anyone see where/why this error is coming up?

I stripped the following code to only include the loops, and it appears they are all closed... but i'm still getting this error, which appears to be directly related to the second last close bracket... everything before it performs, all after is this:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Code: Select all

$issueID = $_GET['ID'];
		$sql2 = "SELECT COUNT(*) FROM it_discussion WHERE Thread_IID = '$issueID' AND Thread_X ='0'";
		$numrecord = mysql_query($sql5);
		$numrecords = mysql_fetch_array($numrecord);
	
		$numThread=$numrecords[0];
		if ($numThread <='1'){
		echo "";
		}
		else {
		echo "<table width='750' cellpadding='2' cellspacing='0' class='caltable'>";
		$intRecsPerPage=100;
		if($_POST["intpage"]=="")
		{
			$intpage=1;
		}
		$sql2 = "SELECT * FROM it_discussion WHERE Thread_IID = '$issueID' AND Thread_X ='0' ORDER BY Thread_ID ASC LIMIT ".(($intpage-1)*$intRecsPerPage).", ".$intRecsPerPage;
		$resultthread = mysql_query($sql2) or die (mysql_error()); 
	
		$totalpages = intval(($numrecords[0])/$intRecsPerPage);
		if(intval($numrecords[0]/$intRecsPerPage) != ($numrecords[0]/$intRecsPerPage))
       	{
       		$totalpages = $totalpages + 1;
       	}

		for($x = (($intpage-1) * $intRecsPerPage); $x < (($intpage-1) * $intRecsPerPage) + $intRecsPerPage; $x++)
		{
			if($x/2 != intval($x/2))
					{
						$bgcolor = "#ffffff";
					}
					else
					{
					$bgcolor = "#F7F7F7";
					}
			if($x >= $numrecords[0])
			{
				break;
			}
		$threadresults = mysql_fetch_array($resultthread);	
		$threadID = $threadresults['Thread_ID'];
		$threadAuthor = $threadresults['Thread_UID'];
		$threadDate = $threadresults['Thread_Date'];
		$threadTtl = $threadresults['Thread_Ttl'];		
		$threadText = $threadresults['Thread_Text'];				

	//members	
	$sql1 = "SELECT * FROM it_mem WHERE Mem_ID=".$threadAuthor;
	$resultmem = mysql_query($sql1) or die (mysql_error()); 
	$memresults = mysql_fetch_array($resultmem);
	

	//status
	$sql2 = "SELECT * FROM it_status";
	$resultstatus = mysql_query($sql2) or die (mysql_error()); 
	$statusresults = mysql_fetch_array($resultstatus);

	//type
	$sql3 = "SELECT * FROM it_type";
	$resulttype = mysql_query($sql3) or die (mysql_error()); 
	$typeresults = mysql_fetch_array($resulttype);
	$typeRequest=$typeresults['Type_Name'];	

	//dept	
	$sql4 = "SELECT * FROM it_division WHERE Div_ID = '$issueDept'";
	$resultdiv = mysql_query($sql4) or die (mysql_error()); 
	$divresults = mysql_fetch_array($resultdiv);	
	$divName = $divresults['Div_Name'];		

	//assignment	
	$sql4 = "SELECT * FROM it_assignment WHERE Assign_TID = '$threadID' ORDER BY Assign_ID DESC";
	$resultassign = mysql_query($sql4) or die (mysql_error()); 
	$assignresults = mysql_fetch_array($resultassign);	
	$assignThread = $assignresults['Assign_TID'];
	$assignIssue = $assignresults['Assign_IID'];
	$assignAuthor = $assignresults['Assign_UID'];
	$assignNew = $assignresults['Assign_NID'];
	$assignDate = $assignresults['Assign_Date'];	
	
	//members	
	$sql5 = "SELECT * FROM it_mem WHERE Mem_ID=".$assignAuthor;
	$resultassigned = mysql_query($sql5) or die (mysql_error()); 
	$assignedresult = mysql_fetch_array($resultassigned);
	$assignedName = $assignedresults['Mem_FName'];

	//members	
	$sql6 = "SELECT * FROM it_mem WHERE Mem_ID=".$assignNew;
	$resultassignedN = mysql_query($sql6) or die (mysql_error()); 
	$assignedNresult = mysql_fetch_array($resultassignedN);
	$assignedNFName = $assignedNresult['Mem_FName'];
	$assignedNLName = $assignedNresult['Mem_LName'];		
							
	echo "<tr valign='top' bgcolor='#FFFFFF'>"; 
     echo "<td width='100%' align='left' valign='top'>"; 
	  
	  echo "By <font class='style2'>$memresults[Mem_FName] $memresults[Mem_LName] </font>on ";
	  echo convertdate($threadresults['Thread_Date']); 
	  echo "<hr size='1' noshade width='600'>";
	  echo "<ul>";
	  echo "$threadText";
	  echo "<ul><hr size='1' width='600' noshade><br>";
	  echo "<font class='style3'>";
      echo "Reassigned to ";
	  echo "$assignedNFName $assignedNLName as a $typeRequest";								 
	  echo "</font></ul>";  
	  echo "</ul>";  
	}
	}
		echo "</td></tr></table>";

Code: Select all

$issueID = $_GET['ID'];
        $sql2 = "SELECT COUNT(*) FROM it_discussion WHERE Thread_IID = '$issueID' AND Thread_X ='0'";
        $numrecord = mysql_query($sql5);
        $numrecords = mysql_fetch_array($numrecord);
mysql_query($sql5); <-- That should be $sql2 since variables don't search past where they are asked.
Post Reply