Jump to content

function to generate questionaire/monkey puzzle style survey form


Greywacke
 Share

Recommended Posts

hi there,having some trouble wrapping my head around the finer details of this. can't seem to get it to work, the hospital was rescheduled for a 6th time :)the function i created sofar, is as follows:

function getquestions($surveytype,$leadid=0,$refid=0) {	$sql = "SELECT * 			FROM 				22_surveyquestions 			LEFT JOIN 				23_surveyoptions 			ON (				22_surveyquestions.bigint_QuestionID = 23_surveyoptions.bigint_QuestionID			) 			WHERE 				22_surveyquestions.bigint_TypeID = ".$surveytype." 			ORDER BY 				22_surveyquestions.smallint_SortOrder, 				23_surveyoptions.smallint_SortOrder;";	$result = mysql_query_errors($sql, $conn , __FILE__ , __LINE__ , true );	$html = "<form id=\"form_survey\" name=\"form_survey\" method=\"post\" accept-charset=\"UTF-8\" onsubmit=\"valform(this);\">".			"<input name=\"leadid\" id=\"leadid\" type=\"hidden\" value=\"".$leadid."\" />".			"<input name=\"surveyid\" id=\"surveyid\" type=\"hidden\" value=\"".$surveytype."\" />\n";	$q = array();	$q[0] = "";	$q[1] = "";	if ($result) {		$i = 1;		$shtml = "";		$arr = array();		while ($row = mysql_fetch_array($result)) {			$q[1] = $row["text_QuestionContent"];			if ($q[0] != $q[1]) {				$i++;				$n = 1;				$q[0] = $q[1];				$html .= "	<label for=\"radio_answer_1\"><strong>".$i."). ".$q[1]."</strong></label>\n";			}			$n++;			$a = "	<input type=\"radio\" name=\"radio_group_".$i."\" id=\"radio_answer_".$i."_".$n."\" value=\"".$row["bigint_OptionID"]."\" />".				"<label for=\"radio_answer_".$i."_".$n."\" >".$a."</label>\n";			if (preg_match_all("/%Supplier_([\d]+)%/",$a,$arr)) {				// get suppliers for premium & test / freemium leads and loop through				$sql0 = "SELECT 							5_suppliers.text_SupplierName 						FROM 							5_suppliers 						LEFT JOIN 							27_leadssent 						ON (							5_suppliers.bigint_SupplierID = 27_leadssent.bigint_SupplierID						) 						LEFT JOIN 							13_prospectleadsent 						ON (							5_suppliers.bigint_SupplierID = 13_prospectleadsent.bigint_SupplierID						) 						WHERE 							27_leadssent.bigint_LeadID = ".$leadid." OR 							13_prospectleadsent.bigint_ProspectID = ".$refid.";";				$result0 = mysql_query_errors($sql, $conn , __FILE__ , __LINE__ , true );				// get record by number in $arr				if (preg_match_all("/specify/",$a,$arr)) {					$html .= "	<input type=\"radio\" name=\"radio_group_".$i."\" id=\"radio_answer_".$i."_".$n."\" value=\"".$row["bigint_OptionID"]."\" />".							 "<label for=\"radio_answer_".$i."_".$n."\" >".$a."</label>\n".							 "<input type=\"text\" name=\"text_specify\" id=\"text_specify\" value=\"\" width=\"32\" />\n";				} else if (preg_match_all("/Repeat/",$a,$arr)) {					while ($row0 = mysql_fetch_array($result0)) {						$html .= preg_replace("/%Supplier_1%/",xmlentities($row0["text_SupplierName"]),$shtml);					}				} else {					$shtml .="	<input type=\"radio\" name=\"radio_group_".$i."\" id=\"radio_answer_".$i."_".$n."\" value=\"".$row["bigint_OptionID"]."\" />".							 "<label for=\"radio_answer_".$i."_".$n."\" >".$a."</label>\n";					$res = mysql_result($result0,intval($arr[0][0]-1));					$a = preg_replace("/%Supplier_".$arr[0][0]."%/",xmlentities($res),$a);					$html .= "	<input type=\"radio\" name=\"radio_group_".$i."\" id=\"radio_answer_".$i."_".$n."\" value=\"".$row["bigint_OptionID"]."\" />".							 "<label for=\"radio_answer_".$i."_".$n."\" >".$a."</label>\n";				}			} else {				$html .= $a;			}		}		mysql_free_result($result);	}	$html .= "<input type=\"submit\" value=\"Submit!\" /><input type=\"Reset\" value=\"Reset...\" />\n";	$html .= "</form>";	return array($i, $html);}

the basic database table designs that it uses here, are leads as instance records, and send records per supplier. therefor getting the list of suppliers bound to a lead from this table.if the option contains "%Supplier_1%" etc in it, it will save that series of options and repeat it on "Repeat" found. Also if "specify" is found, it will include a text field. however, this function returns no questions or options - just the opening and closing form elements... :) somebody please help me focus here - as i seem to be struggling to. the table consisting of the options, links to a question.this function is called on the public Test Page, which is supposed to return the related questionnaire for the consumer survey in question. the function above is all that does not work at the moment. it is sent the valid survey type id, lead id and reference id - but does not seem to get any results. if the variable &Supplier_1% etc was found, it is supposed to return the number found in $arr[0][0]. :) this is slightly above my head and i seem to be battling tremendously!

Link to comment
Share on other sites

What are you doing with the $a variable? The first time you define it you're concatenating it with its undefined self. Each other time through the loop do you want to keep concatenating it?It sounds like you just need to trace the execution. Verify that the first query returns records, check the various if statement conditions, etc.

Link to comment
Share on other sites

the page selects by consumer survey id, this contains the survey type, lead id and reference id's passed to the function when it is called.the function has been updated as follows, but does not replace the flags on detection.

function getquestions($surveytype,$leadid=0,$refid=0) {	$sql = "SELECT * 			FROM 				22_surveyquestions 			LEFT JOIN 				23_surveyoptions 			ON (				22_surveyquestions.bigint_QuestionID = 23_surveyoptions.bigint_QuestionID			) 			WHERE 				22_surveyquestions.bigint_TypeID = ".$surveytype." 			ORDER BY 				22_surveyquestions.smallint_SortOrder, 				23_surveyoptions.smallint_SortOrder;";	$result = mysql_query_errors($sql, $conn , __FILE__ , __LINE__ );	$html = "<form id=\"form_survey\" name=\"form_survey\" method=\"post\" accept-charset=\"UTF-8\" onsubmit=\"valform(this);\">\n".			"	<input name=\"leadid\" id=\"leadid\" type=\"hidden\" value=\"".$leadid."\" />\n".			"	<input name=\"leadid\" id=\"refid\" type=\"hidden\" value=\"".$refid."\" />\n".			"	<input name=\"surveyid\" id=\"surveyid\" type=\"hidden\" value=\"".$surveytype."\" />\n";	$q = array();	$q[0] = "";	$q[1] = "";	if ($result) {		$i = 0;		$shtml = "";		$arr = array();		while ($row = mysql_fetch_array($result)) {			$q[1] = $row["text_QuestionContent"];			if ($q[0] != $q[1]) {				$i++;				$n = 0;				$q[0] = $q[1];				$html .= "	<label for=\"radio_answer_1\"><strong>".$i."). ".$q[1]."</strong></label><br />\n";			}			$n++;			$a = $row["text_OptionContent"];			if (preg_match_all("/%Supplier_([\d]+)%/",$a,$arr)) {				// get suppliers for premium & test / freemium leads and loop through				$sql0 = "SELECT 							5_suppliers.text_SupplierName 						FROM 							5_suppliers 						LEFT JOIN 							27_leadssent 						ON (							5_suppliers.bigint_SupplierID = 27_leadssent.bigint_SupplierID						) 						LEFT JOIN 							13_prospectleadsent 						ON (							5_suppliers.bigint_SupplierID = 13_prospectleadsent.bigint_SupplierID						) 						WHERE 							27_leadssent.bigint_LeadID = ".$leadid." OR 							13_prospectleadsent.bigint_ProspectID = ".$refid.";";				$result0 = mysql_query_errors($sql, $conn , __FILE__ , __LINE__ , true );				// get record by number in $arr				if (preg_match_all("/specify/",$a,$arr)) {					$html .= "	<input type=\"radio\" name=\"radio_group_".$i."\" id=\"radio_answer_".$i."_".$n."\" value=\"".$row["bigint_OptionID"]."\" />".							 "<label for=\"radio_answer_".$i."_".$n."\" >".$a."</label><br />\n".							 "	<input type=\"text\" name=\"text_specify\" id=\"text_specify\" value=\"\" width=\"32\" /><br />\n";				} else if (preg_match_all("/Repeat/",$a,$arr)) {					while ($row0 = mysql_fetch_array($result0)) {						$html .= preg_replace("/%Supplier_[\d]+%/",xmlentities($row0["text_SupplierName"]),$shtml);					}				} else {					$shtml .="	<input type=\"radio\" name=\"radio_group_".$i."\" id=\"radio_answer_".$i."_".$n."\" value=\"".$row["bigint_OptionID"]."\" />".							 "<label for=\"radio_answer_".$i."_".$n."\" >".$a."</label><br />\n";					$res = mysql_result($result0,intval($arr[0][0]-1));					$a = preg_replace("/%Supplier_".$arr[0][0]."%/",xmlentities($res),$a);					$html .= "	<input type=\"radio\" name=\"radio_group_".$i."\" id=\"radio_answer_".$i."_".$n."\" value=\"".$row["bigint_OptionID"]."\" />".							 "<label for=\"radio_answer_".$i."_".$n."\" >".$a."</label><br />\n";				}			} else {				$html .= "	<input type=\"radio\" name=\"radio_group_".$i."\" id=\"radio_answer_".$i."_".$n."\" value=\"".$row["bigint_OptionID"]."\" />".							 "<label for=\"radio_answer_".$i."_".$n."\" >".$a."</label><br />\n";			}		}		mysql_free_result($result);	}	$html .= "<input type=\"submit\" value=\"Submit!\" /><input type=\"Reset\" value=\"Reset...\" />\n";	$html .= "</form>";	return array($i, $html);}

the url where used is still http://www.intellisource.co.za/survey.php?q=1, but it does not replace the flags and repeat options for the rest of the suppliers.

Edited by Pierre 'Greywacke' du Toit
Link to comment
Share on other sites

looking at the results of $arr, and the concatenation of $a - the function has been updated to follows:

function getquestions($surveytype,$leadid=0,$refid=0) {	$sql = "SELECT * 			FROM 				22_surveyquestions 			LEFT JOIN 				23_surveyoptions 			ON (				22_surveyquestions.bigint_QuestionID = 23_surveyoptions.bigint_QuestionID			) 			WHERE 				22_surveyquestions.bigint_TypeID = ".$surveytype." 			ORDER BY 				22_surveyquestions.smallint_SortOrder, 				23_surveyoptions.smallint_SortOrder;";	$result = mysql_query_errors($sql, $conn , __FILE__ , __LINE__ );	$shtml = "";	$html = "<form id=\"form_survey\" name=\"form_survey\" method=\"post\" accept-charset=\"UTF-8\" onsubmit=\"valform(this);\">\n".			"	<input name=\"leadid\" id=\"leadid\" type=\"hidden\" value=\"".$leadid."\" />\n".			"	<input name=\"leadid\" id=\"refid\" type=\"hidden\" value=\"".$refid."\" />\n".			"	<input name=\"surveyid\" id=\"surveyid\" type=\"hidden\" value=\"".$surveytype."\" />\n";	$q = array();	$q[0] = "";	$q[1] = "";	if ($result) {		$i = 0;		while ($row = mysql_fetch_array($result)) {			$arr0 = array();			$arr1 = array();			$arr2 = array();			$q[1] = $row["text_QuestionContent"];			if ($q[0] != $q[1]) {				$i++;				$n = 0;				$q[0] = $q[1];				$html .= "	<label for=\"radio_answer_1\"><strong>".$i."). ".$q[1]."</strong></label><br />\n";			}			$n++;			$a = $row["text_OptionContent"];			if (preg_match_all("/%Supplier_([\d]+)%/",$a,$arr0)) {				// get suppliers for premium & test / freemium leads and loop through				$sql0 = "SELECT 							5_suppliers.text_SupplierName 						FROM 							5_suppliers 						LEFT JOIN 							27_leadssent 						ON (							5_suppliers.bigint_SupplierID = 27_leadssent.bigint_SupplierID						) 						LEFT JOIN 							13_prospectleadsent 						ON (							5_suppliers.bigint_SupplierID = 13_prospectleadsent.bigint_SupplierID						) 						WHERE 							27_leadssent.bigint_LeadID = ".$leadid." OR 							13_prospectleadsent.bigint_ProspectID = ".$refid." 						GROUP BY 							5_suppliers.text_SupplierName;";				$result0 = mysql_query_errors($sql, $conn , __FILE__ , __LINE__ , true );				// get record by number in $arr				if (preg_match_all("/specify/",$a,$arr1)) {					$html .= "	<input type=\"radio\" name=\"radio_group_".$i."\" id=\"radio_answer_".$i."_".$n."\" value=\"".$row["bigint_OptionID"]."\" />".							 "<label for=\"radio_answer_".$i."_".$n."\" >".$a."</label><br />\n".							 "	<input type=\"text\" name=\"text_specify\" id=\"text_specify\" value=\"\" width=\"32\" /><br />\n";				} else if (preg_match_all("/Repeat/",$a,$arr2)) {					while ($row0 = mysql_fetch_array($result0)) {						$html .= preg_replace("/%Supplier_[\d]+%/",xmlentities($row0["text_SupplierName"]),$shtml);					}				} else {					$shtml .= "	<input type=\"radio\" name=\"radio_group_".$i."\" id=\"radio_answer_".$i."_".$n."\" value=\"".$row["bigint_OptionID"]."\" />".							  "<label for=\"radio_answer_".$i."_".$n."\" >".$a."</label><br />\n";					//print_r($arr0);					$res = mysql_result($result0,intval($arr0[1][0])-1);					$a = preg_replace("/%Supplier_".intval($arr0[1][0])."%/","/".xmlentities($res)."/",$a);					$html .= "	<input type=\"radio\" name=\"radio_group_".$i."\" id=\"radio_answer_".$i."_".$n."\" value=\"".$row["bigint_OptionID"]."\" />".							 "<label for=\"radio_answer_".$i."_".$n."\" >".$a."</label><br />\n";				}			} else {				$html .= "	<input type=\"radio\" name=\"radio_group_".$i."\" id=\"radio_answer_".$i."_".$n."\" value=\"".$row["bigint_OptionID"]."\" />".							 "<label for=\"radio_answer_".$i."_".$n."\" >".$a."</label><br />\n";			}		}		mysql_free_result($result);	}	$html .= "<input type=\"submit\" value=\"Submit!\" /><input type=\"Reset\" value=\"Reset...\" />\n";	$html .= "</form>";	return array($i, $html);}

$a is set to include $row["text_OptionContent"], and be used when writing the form to $html to return from the function.$shtml is to keep certain fields in memory, and use them again when repeating for all suppliers.the questions returned by the query here, are as follows, and need to be displayed and repeated verbatim:

bigint_QuestionID	smallint_SortOrder	bigint_TypeID	text_QuestionContent7			10			4		What is the status of your purchase at this time?7			10			4		What is the status of your purchase at this time?7			10			4		What is the status of your purchase at this time?7			10			4		What is the status of your purchase at this time?31			20			4		Did the suppliers in the CanopyXchange network contact you with a quotation?31			20			4		Did the suppliers in the CanopyXchange network contact you with a quotation?31			20			4		Did the suppliers in the CanopyXchange network contact you with a quotation?31			20			4		Did the suppliers in the CanopyXchange network contact you with a quotation?31			20			4		Did the suppliers in the CanopyXchange network contact you with a quotation?31			20			4		Did the suppliers in the CanopyXchange network contact you with a quotation?32			30			4		Which supplier or manufacturer did you choose for your purchase?32			30			4		Which supplier or manufacturer did you choose for your purchase?32			30			4		Which supplier or manufacturer did you choose for your purchase?32			30			4		Which supplier or manufacturer did you choose for your purchase?32			30			4		Which supplier or manufacturer did you choose for your purchase?32			30			4		Which supplier or manufacturer did you choose for your purchase?33			40			4		How much did you pay for your canopy? (Don't worry! This information will only be used anonymously)33			40			4		How much did you pay for your canopy? (Don't worry! This information will only be used anonymously)33			40			4		How much did you pay for your canopy? (Don't worry! This information will only be used anonymously)33			40			4		How much did you pay for your canopy? (Don't worry! This information will only be used anonymously)33			40			4		How much did you pay for your canopy? (Don't worry! This information will only be used anonymously)33			40			4		How much did you pay for your canopy? (Don't worry! This information will only be used anonymously)33			40			4		How much did you pay for your canopy? (Don't worry! This information will only be used anonymously)33			40			4		How much did you pay for your canopy? (Don't worry! This information will only be used anonymously)33			40			4		How much did you pay for your canopy? (Don't worry! This information will only be used anonymously)33			40			4		How much did you pay for your canopy? (Don't worry! This information will only be used anonymously)33			40			4		How much did you pay for your canopy? (Don't worry! This information will only be used anonymously)34			50			4		Which factor was the most important to you in choosing to purchase from the particular supplier?34			50			4		Which factor was the most important to you in choosing to purchase from the particular supplier?34			50			4		Which factor was the most important to you in choosing to purchase from the particular supplier?bigint_OptionID		smallint_SortOrder	bigint_QuestionID	text_OptionContent1			10			7			I'm still considering my purchase2			20			7			I have purchased from a supplier in CanopyXchange supplier network3			30			7			I purchased from another supplier outside the CanopyXchange supplier network6			40			7			I have decided not to make a purchase at this time32			0			31			%Supplier_1% No, this supplier didn't contact me31			0			31			%Supplier_1% Yes, within a week30			0			31			%Supplier_1% Yes, within the next day29			0			31			%Supplier_1% Yes, sameday still28			0			31			%Supplier_1% Yes, within 10 minutes!57			0			31			%Supplier_2% Repeat options for this supplier33			0			32			%Supplier_1%34			0			32			%Supplier_2%35			0			32			%Supplier_3%36			0			32			%Supplier_4%37			0			32			%Supplier_5%38			0			32			Another supplier not listed here. Please specify ...39			0			33			Less than R3,00040			0			33			Between R3,000 to R4,00041			0			33			Between R4,000 to R5,00042			0			33			Between R5,000 to R6,00043			0			33			Between R6,000 to R7,00044			0			33			Between R7,000 to R8,00045			0			33			Between R9,000 to R10,00046			0			33			Between R8,000 to R9,00047			0			33			Between R10,000 to R11,00048			0			33			Between R11,000 to R12,00049			0			33			More than R12,00050			0			34			Design and features best suited my needs51			0			34			Best value for money (good trade-off between design, quality and price)53			0			34			Customer service (professionalism, friendly, truely helpful, timely communications)

unfortunately i do not see the forest for the trees: why it does not repeat the $shtml questions per supplier name in the query when Repeat is encountered or why does it replaces the Supplier_N flags with digits 0osomebody please help! :)i have yet to test the updated function, having trouble with ftp at the moment to the server.

Edited by Pierre 'Greywacke' du Toit
Link to comment
Share on other sites

If this loop isn't running:

				} else if (preg_match_all("/Repeat/",$a,$arr2)) {					while ($row0 = mysql_fetch_array($result0)) {						$html .= preg_replace("/%Supplier_[\d]+%/",xmlentities($row0["text_SupplierName"]),$shtml);					}

Then the two possibilities are that the if statement is not matching (or the previous if statement matched, so the else gets skipped), or the result doesn't have any records.

Link to comment
Share on other sites

ok, the function has been updated as follows:

function getquestions($surveytype,$leadid=0,$refid=0) {	$sql = "SELECT * 			FROM 				22_surveyquestions 			LEFT JOIN 				23_surveyoptions 			ON (				22_surveyquestions.bigint_QuestionID = 23_surveyoptions.bigint_QuestionID			) 			WHERE 				22_surveyquestions.bigint_TypeID = ".$surveytype." 			ORDER BY 				22_surveyquestions.smallint_SortOrder, 				23_surveyoptions.smallint_SortOrder;";	$result = mysql_query_errors($sql, $conn , __FILE__ , __LINE__ );	$shtml = "";	$html = "<form id=\"form_survey\" name=\"form_survey\" method=\"post\" accept-charset=\"UTF-8\" onsubmit=\"valform(this);\">\n".			"	<input name=\"leadid\" id=\"leadid\" type=\"hidden\" value=\"".$leadid."\" />\n".			"	<input name=\"leadid\" id=\"refid\" type=\"hidden\" value=\"".$refid."\" />\n".			"	<input name=\"surveyid\" id=\"surveyid\" type=\"hidden\" value=\"".$surveytype."\" />\n";	$q = array();	$q[0] = "";	$q[1] = "";	if ($result) {		$i = 0;		while ($row = mysql_fetch_array($result)) {			$arr0 = array();			$arr1 = array();			$arr2 = array();			$q[1] = $row["text_QuestionContent"];			if ($q[0] != $q[1]) {				$i++;				$n = 0;				$q[0] = $q[1];				$html .= "	<label for=\"radio_answer_1\"><strong>".$i."). ".$q[1]."</strong></label><br />\n";			}			$n++;			$a = $row["text_OptionContent"];			if (preg_match_all("/%Supplier_([\d]+)%/",$a,$arr0)) {				// get suppliers for premium & test / freemium leads and loop through				$sql0 = "SELECT 							5_suppliers.text_SupplierName 						FROM 							5_suppliers 						LEFT JOIN 							27_leadssent 						ON (							5_suppliers.bigint_SupplierID = 27_leadssent.bigint_SupplierID						) 						LEFT JOIN 							13_prospectleadsent 						ON (							5_suppliers.bigint_SupplierID = 13_prospectleadsent.bigint_SupplierID						) 						WHERE 							27_leadssent.bigint_LeadID = ".$leadid." OR 							13_prospectleadsent.bigint_ProspectID = ".$refid." 						GROUP BY 							5_suppliers.text_SupplierName;";				$result0 = mysql_query_errors($sql0, $conn , __FILE__ , __LINE__ );				// get record by number in $arr				if (preg_match_all("/specify/",$a,$arr1)) {					$html .= "	<input type=\"radio\" name=\"radio_group_".$i."\" id=\"radio_answer_".$i."_".$n."\" value=\"".$row["bigint_OptionID"]."\" />".							 "<label for=\"radio_answer_".$i."_".$n."\" >".$a."</label><br />\n".							 "	<input type=\"text\" name=\"text_specify\" id=\"text_specify\" value=\"\" width=\"32\" /><br />\n";				} elseif (preg_match_all("/Repeat/",$a,$arr2)) {					if (mysql_data_seek($result0,1)) {						while ($row0 = mysql_fetch_array($result0)) {							$html .= preg_replace("/%Supplier_[\d]+%/",xmlentities($row0["text_SupplierName"]),$shtml);						}					}				} else {					$shtml .= "	<input type=\"radio\" name=\"radio_group_".$i."\" id=\"radio_answer_".$i."_".$n."\" value=\"".$row["bigint_OptionID"]."\" />".							  "<label for=\"radio_answer_".$i."_".$n."\" >".$a."</label><br />\n";					print_r($arr0);					if (mysql_data_seek($result0,intval($arr0[1][0])-1)) {						if ($row1 = mysql_fetch_array($result0)) {							$a = preg_replace("/%Supplier_".intval($arr0[1][0])."%/",$row1["text_SupplierName"],$a);							$html .= "	<input type=\"radio\" name=\"radio_group_".$i."\" id=\"radio_answer_".$i."_".$n."\" value=\"".$row["bigint_OptionID"]."\" />".									 "<label for=\"radio_answer_".$i."_".$n."\" >".$a."</label><br />\n";						}					}				}			} else {				$html .= "	<input type=\"radio\" name=\"radio_group_".$i."\" id=\"radio_answer_".$i."_".$n."\" value=\"".$row["bigint_OptionID"]."\" />".							 "<label for=\"radio_answer_".$i."_".$n."\" >".$a."</label><br />\n";			}		}		mysql_free_result($result);	}	$html .= "<input type=\"submit\" value=\"Submit!\" /><input type=\"Reset\" value=\"Reset...\" />\n";	$html .= "</form>";	return array($i, $html);}

ok it is now replacing with the supplier names as expected to, and repeating if "repeat" is encountered in the value. my fault was executing $sql instead of $sql0 after the query was typed out.i have also printed the values of $arr0, and when this function is run with the current database values that were specified in the previous post (the outer query), it print_r's as follows:

Array(	[0] => Array		(			[0] => %Supplier_1%		)	[1] => Array		(			[0] => 1		))Array(	[0] => Array		(			[0] => %Supplier_1%		)	[1] => Array		(			[0] => 1		))Array(	[0] => Array		(			[0] => %Supplier_1%		)	[1] => Array		(			[0] => 1		))Array(	[0] => Array		(			[0] => %Supplier_1%		)	[1] => Array		(			[0] => 1		))Array(	[0] => Array		(			[0] => %Supplier_1%		)	[1] => Array		(			[0] => 1		))Array(	[0] => Array		(			[0] => %Supplier_1%		)	[1] => Array		(			[0] => 1		))Array(	[0] => Array		(			[0] => %Supplier_2%		)	[1] => Array		(			[0] => 2		))Array(	[0] => Array		(			[0] => %Supplier_3%		)	[1] => Array		(			[0] => 3		))Array(	[0] => Array		(			[0] => %Supplier_4%		)	[1] => Array		(			[0] => 4		))<br /><b>Warning</b>:  mysql_data_seek() [<a href='function.mysql-data-seek'>function.mysql-data-seek</a>]: Offset 3 is invalid for MySQL result index 14 (or the query data is unbuffered) in <b>/home/dwtphovu/public_html/intellisource.co.za/survey.php</b> on line <b>82</b><br />Array(	[0] => Array		(			[0] => %Supplier_5%		)	[1] => Array		(			[0] => 5		))<br /><b>Warning</b>:  mysql_data_seek() [<a href='function.mysql-data-seek'>function.mysql-data-seek</a>]: Offset 4 is invalid for MySQL result index 15 (or the query data is unbuffered) in <b>/home/dwtphovu/public_html/intellisource.co.za/survey.php</b> on line <b>82</b><br />

and the inner recordset for the supplier names, returns the following:

text_SupplierName=================Canopy and Weca Centre (Centurion)Faaz Fit Canopy (Roodepoort)Midvaal Canopies (Meyerton)

yet it does not seem to be finding the text for "specify" and include the text field if found.also how would i hide the warnings that are printed if the following code runs and returns false (ie it is asking to return a supplier name beyond the length of the resultset.)

if (mysql_data_seek($result0,intval($arr0[1][0])-1)) {

Edited by Pierre 'Greywacke' du Toit
Link to comment
Share on other sites

You can check how many records are in the recordset before trying to seek. Mysql_num_rows will tell you how many records there are. Like the other one, if your if statement isn't passing when you think it should, just print everything you're checking to see why.

Link to comment
Share on other sites

thats what i did :) thanks... this function has been updated since sunday. with a slight difference in accessing it on the online survey form and the cronjob survey mailer. it generates the forms now, beautifully ^^

function getquestions($surveytype,$consumerid,$leadid=0,$refid=0) {	$sql = "SELECT * 			FROM 				22_surveyquestions 			LEFT JOIN 				23_surveyoptions 			ON (				22_surveyquestions.bigint_QuestionID = 23_surveyoptions.bigint_QuestionID			) 			WHERE 				22_surveyquestions.bigint_TypeID = ".$surveytype." 			ORDER BY 				22_surveyquestions.smallint_SortOrder, 				23_surveyoptions.smallint_SortOrder;";	$result = mysql_query_errors($sql, $conn , __FILE__ , __LINE__ );	$html = "<form id=\"form_survey\" name=\"form_survey\" method=\"post\" accept-charset=\"UTF-8\" action=\"survey_handler.php\" onsubmit=\"valform(this);\">".			"<input name=\"consumersurveyid\" id=\"consumersurveyid\" type=\"hidden\" value=\"".$GLOBALS["q"]."\" />\n";	$q = array();	$q[0] = "";	$q[1] = "";	$shtml = "";	if ($result) {		$i = 0;		while ($row = mysql_fetch_array($result)) {			$arr0 = array();			$arr1 = array();			$arr2 = array();			$q[1] = $row["text_QuestionContent"];			if ($q[0] != $q[1]) {				$i++;				$n = 0;				if ($q[0] != "") {					$html .= "	</p>\n";				}				$q[0] = $q[1];				$html .= "	<p><label for=\"radio_answer_".$i."_1\"><strong>".$i."). ".$q[1]."</strong></label></p>\n".						 "	<p>\n";				$shtml = "";			}			$n++;			$a = $row["text_OptionContent"];			$sid = 0;			if (preg_match_all("/%Supplier_([\d]+)%/",$a,$arr0)) {				// get suppliers for premium & test / freemium leads and loop through				$sql0 = "SELECT 							5_suppliers.bigint_SupplierID, 							5_suppliers.text_SupplierName 						FROM 							5_suppliers 						LEFT JOIN 							27_leadssent 						ON (							5_suppliers.bigint_SupplierID = 27_leadssent.bigint_SupplierID						) 						LEFT JOIN 							13_prospectleadsent 						ON (							5_suppliers.bigint_SupplierID = 13_prospectleadsent.bigint_SupplierID						) 						WHERE 							27_leadssent.bigint_LeadID = ".$leadid." OR 							13_prospectleadsent.bigint_ProspectID = ".$refid." 						GROUP BY 							5_suppliers.text_SupplierName;";				$result0 = mysql_query_errors($sql0, $conn , __FILE__ , __LINE__ );				// get record by number in $arr				if (preg_match_all("/Repeat/",$a,$arr2)) {					if (mysql_data_seek($result0,1)) {						while ($row0 = mysql_fetch_array($result0)) {							$html .= "	</p>\n";							$html .= "	<p>\n";							$html .= preg_replace("/%SID%/",$row0["bigint_SupplierID"],preg_replace("/%Supplier_[\d]+%/",xmlentities($row0["text_SupplierName"]),$shtml));						}					}				} else {					$shtml .= "	  <input type=\"radio\" name=\"radio_group_".$i."_%SID%\" id=\"radio_answer_".$i."_".$n."_%SID%\" value=\"".$row["bigint_OptionID"]."_%SID%\" />".							  "<label for=\"radio_answer_".$i."_".$n."_%SID%\" >  ".$a."</label><br />\n";					if (intval($arr0[1][0])-1 < mysql_num_rows($result0)) {						if (mysql_data_seek($result0,intval($arr0[1][0])-1)) {							if ($row1 = mysql_fetch_array($result0)) {								$a = preg_replace("/%Supplier_".intval($arr0[1][0])."%/",$row1["text_SupplierName"],$a);								$html .= "	  <input type=\"radio\" name=\"radio_group_".$i."\" id=\"radio_answer_".$i."_".$n."\" value=\"".$row["bigint_OptionID"]."_".$row1["bigint_SupplierID"]."\" />".										 "<label for=\"radio_answer_".$i."_".$n."\" >  ".$a."</label><br />\n";							}						}					}				}			} else {				if (preg_match_all("/specify/",$a,$arr1)) {					$html .= "	  <input type=\"radio\" name=\"radio_group_".$i."\" id=\"radio_answer_".$i."_".$n."\" value=\"".$row["bigint_OptionID"]."\" onfocus=\"document.form_survey.text_specify_".$row["bigint_OptionID"].".focus();\" />".							 "<label for=\"radio_answer_".$i."_".$n."\" >  ".$a."  ".							 "<input type=\"text\" name=\"text_specify_".$row["bigint_OptionID"]."\" id=\"text_specify_".$row["bigint_OptionID"]."\" value=\"\" width=\"32\" /></label><br />\n";				} else {					$html .= "	  <input type=\"radio\" name=\"radio_group_".$i."\" id=\"radio_answer_".$i."_".$n."\" value=\"".$row["bigint_OptionID"]."\" />".								 "<label for=\"radio_answer_".$i."_".$n."\" >  ".$a."</label><br />\n";				}			}		}		mysql_free_result($result);	}	$html .= "	</p>\n";	$html .= "	<p><input type=\"submit\" value=\"Submit!\" /><input type=\"Reset\" value=\"Reset...\" /></p>\n";	$html .= "</form>";	return array($i, $html);}

this issue has now been resolved! :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...