Jump to content

Recommended Posts

I am using a select statement to find some information in a big table using other info form different tables as criteria. My problem is that one of the items has signal quotes in the name. So I get a syntax error. I have tried commenting the signal quotes out in the databases where that name is pulled form but that didn't seem to work.

 

Any ideas.

 

here is what my code looks like.

 


SELECT StatisticalInterfaceIdentification.nStatisticalInterfaceIdentificationID
			FROM StatisticalInterfaceIdentification
			INNER JOIN PivotStatisticalMonitorTypeToDevice
			ON StatisticalInterfaceIdentification.nPivotStatisticalMonitorTypeToDeviceID = PivotStatisticalMonitorTypeToDevice.nPivotStatisticalMonitorTypeToDeviceID
			INNER JOIN Device
			ON PivotStatisticalMonitorTypeToDevice.nDeviceID = Device.nDeviceID
			WHERE Device.sDisplayName = '$Device_Name[$key]'
				AND Device.nDeviceTypeID = '3'
				AND PivotStatisticalMonitorTypeToDevice.nStatisticalMonitorTypeID = '1'
				AND StatisticalInterfaceIdentification.sIfDescr = '$Int'
				OR
				Device.sDisplayName = '$Device_Name[$key]'
				AND Device.nDeviceTypeID = '3'
				AND PivotStatisticalMonitorTypeToDevice.nStatisticalMonitorTypeID = '1'
				AND StatisticalInterfaceIdentification.sIfDescr = '$intadd'") or
					die ("can't select StatisticalInterface");

 

At one point $Int is equal to PIX Firewall 'outside' interface I have also tried PIX Firewall \'outside\' interface

 

:-\ any ideas

 

Thanks for the help

Link to comment
https://forums.phpfreaks.com/topic/52813-select-statement-syntax-error/
Share on other sites

Looks like i missed some when i was copy pasting

 

$resultSIIID = mssql_query("
			SELECT StatisticalInterfaceIdentification.nStatisticalInterfaceIdentificationID
			FROM StatisticalInterfaceIdentification
			INNER JOIN PivotStatisticalMonitorTypeToDevice
			ON StatisticalInterfaceIdentification.nPivotStatisticalMonitorTypeToDeviceID = PivotStatisticalMonitorTypeToDevice.nPivotStatisticalMonitorTypeToDeviceID
			INNER JOIN Device
			ON PivotStatisticalMonitorTypeToDevice.nDeviceID = Device.nDeviceID
			WHERE Device.sDisplayName = '$Device_Name[$key]'
				AND Device.nDeviceTypeID = '3'
				AND PivotStatisticalMonitorTypeToDevice.nStatisticalMonitorTypeID = '1'
				AND StatisticalInterfaceIdentification.sIfDescr = '$Int'
				OR
				Device.sDisplayName = '$Device_Name[$key]'
				AND Device.nDeviceTypeID = '3'
				AND PivotStatisticalMonitorTypeToDevice.nStatisticalMonitorTypeID = '1'
				AND StatisticalInterfaceIdentification.sIfDescr = '$intadd'") or
					die ("can't select StatisticalInterface");

Ok here is the whole thing. There is some extra info which is why I didn't post it all in the first place.

 

		foreach ($Print_Order as $P_key){
		$dev = explode("|", $P_key);
		foreach ($dev as $key){

		$Interfaces = explode("|",$Interface[$key]);

		unset($tempsiiid);

		foreach ($Interfaces as $Int){
			$intadd = $Int.'-802.1Q vLAN subif';

			$resultSIIID = mssql_query("
			SELECT StatisticalInterfaceIdentification.nStatisticalInterfaceIdentificationID
			FROM StatisticalInterfaceIdentification
			INNER JOIN PivotStatisticalMonitorTypeToDevice
			ON StatisticalInterfaceIdentification.nPivotStatisticalMonitorTypeToDeviceID = PivotStatisticalMonitorTypeToDevice.nPivotStatisticalMonitorTypeToDeviceID
			INNER JOIN Device
			ON PivotStatisticalMonitorTypeToDevice.nDeviceID = Device.nDeviceID
			WHERE Device.sDisplayName = '$Device_Name[$key]'
				AND Device.nDeviceTypeID = '3'
				AND PivotStatisticalMonitorTypeToDevice.nStatisticalMonitorTypeID = '1'
				AND StatisticalInterfaceIdentification.sIfDescr = '$Int'
				OR
				Device.sDisplayName = '$Device_Name[$key]'
				AND Device.nDeviceTypeID = '3'
				AND PivotStatisticalMonitorTypeToDevice.nStatisticalMonitorTypeID = '1'
				AND StatisticalInterfaceIdentification.sIfDescr = '$intadd'") or
					die ("can't select StatisticalInterface");

			$rowSIIID = mssql_fetch_array($resultSIIID, MSSQL_ASSOC);


			if (empty($tempsiiid) && $rowSIIID['nStatisticalInterfaceIdentific'] != ""){
				$tempsiiid = array('1' => $rowSIIID['nStatisticalInterfaceIdentific']);
			} else if ($rowSIIID['nStatisticalInterfaceIdentific'] != ""){
				array_push($tempsiiid, $rowSIIID['nStatisticalInterfaceIdentific']);
			}
		}
		if (empty($SIIID) && isset($tempsiiid)){
			$SIIID = array($key => $tempsiiid);
		} else if (isset($tempsiiid)) {
			$temp = array($key => $tempsiiid);
			array_push_associative($SIIID, $temp);
		}
		}


	}

This runs through an array of devices finds the interfaces for each device and then finds that nStatisticalInterfaceIdentificationID for each interface if fails when it gets to the interface PIX Firewall 'outside' interface

Hope that helps. I am not sure what you mean by "final query strying"

Maybe I am just slow or something but I am still not understanding you fenway. Are you talking about the results of the query. If so I am not sure how that would help salve the syntax error question.

 

Illusion- are you talking about single or double quotes? I thought I had all the right quotes in the right places in my query statement.

 

I am really new to query statements and this is my first one with the join feature. From what I know you encased the entire query with double quotes and the the equal to variables in single quotes.

Illusion- are you talking about single or double quotes? I thought I had all the right quotes in the right places in my query statement.

 

I am really new to query statements and this is my first one with the join feature. From what I know you encased the entire query with double quotes and the the equal to variables in single quotes.

Do you think MySQL is smart enough to identify Exp1 AND Exp2 OR Exp3 AND Exp4 as (Exp1 AND Exp2) OR (Exp3 AND Exp4).

Here is a simpler example of what my problem is.

 

$Int = "Pix 'outside' Interface";

$resultSIIID = mssql_query("
			SELECT StatisticalInterfaceIdentification.nStatisticalInterfaceIdentificationID
			FROM StatisticalInterfaceIdentification
			WHERE StatisticalInterfaceIdentification.sIfDescr = '$Int'") or
					die ("can't select StatisticalInterface");

			$rowSIIID = mssql_fetch_array($resultSIIID, MSSQL_ASSOC);

 

I get this error

Incorrect syntax near 'outside'. (severity 15)

the problem is that "Pix 'outside' Interface" is the value of the field that I am trying to pull and I can't change that value.

 

hope that helps

Maybe I am just slow or something but I am still not understanding you fenway. Are you talking about the results of the query. If so I am not sure how that would help salve the syntax error question.

Take everything inside mysql_query() & assign it to a variable... then echo that variable to the screen -- I need to see what query the server is getting.

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.