jkkenzie Posted July 15, 2008 Share Posted July 15, 2008 i get this error:" Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting ']' in E:\wamp\www\AnnayBase\others\admin\index.php on line 766" when i run below code. Others work if the fields are joined. <?php $result2 = mysql_query("SELECT DISTINCT `Current Residence` FROM `members` ORDER BY `Current Residence`"); echo "<select name='Current Residence'>"; while($nt=mysql_fetch_array($result2)){ echo "<option value='$nt[Current Residence]'>$nt[Current Residence]</option>"; } echo str_replace('"', '"', trim($row["Current Residence"])); echo "</select>"; ?> Link to comment https://forums.phpfreaks.com/topic/114829-getting-data-to-list-box-when-fields-are-atleast-two-word/ Share on other sites More sharing options...
vikramjeet.singla Posted July 15, 2008 Share Posted July 15, 2008 can you post whole code here... Link to comment https://forums.phpfreaks.com/topic/114829-getting-data-to-list-box-when-fields-are-atleast-two-word/#findComment-590463 Share on other sites More sharing options...
samshel Posted July 15, 2008 Share Posted July 15, 2008 First tip, always include strings used as array keys in double quotes <?php $result2 = mysql_query("SELECT DISTINCT `Current Residence` FROM `members` ORDER BY `Current Residence`"); echo "<select name='Current Residence'>"; while($nt=mysql_fetch_array($result2)){ echo "<option value='$nt[\"Current Residence\"]'>$nt[\"Current Residence\"]</option>"; } echo str_replace('"', '"', trim($row["Current Residence"])); echo "</select>"; ?> Link to comment https://forums.phpfreaks.com/topic/114829-getting-data-to-list-box-when-fields-are-atleast-two-word/#findComment-590465 Share on other sites More sharing options...
jkkenzie Posted July 15, 2008 Author Share Posted July 15, 2008 using echo "<option value='$nt[\"Current Residence\"]'>$nt[\"Current Residence\"]</option>"; does not work. some code are here below , otherwise they are more than this text area can accommodate: <td class="hr"><?php echo htmlspecialchars("Division")." " ?></td> <td class="dr"><?php $result2 = mysql_query("SELECT DISTINCT strDivision FROM divisions ORDER BY strDivision"); echo "<select name='Division'>"; while($nt=mysql_fetch_array($result2)){ echo "<option value='$nt[strDivision]'"; if($nt[strDivision] == $strDivision) { echo " selected"; } echo ">$nt[strDivision]</option>"; } echo str_replace('"', '"', trim($row["Division"])); echo "</select>"; ?></td> </tr> <tr> <td class="hr"><?php echo htmlspecialchars("Location")." " ?></td> <td class="dr"><?php $result2 = mysql_query("SELECT DISTINCT strLocation FROM locations ORDER BY strLocation"); echo "<select name='Location'>"; while($nt=mysql_fetch_array($result2)){ echo "<option value='$nt[strLocation]'"; if($nt[strDivision] == "--- Select Location ---") { echo " selected"; } echo ">$nt[strLocation]</option>"; } echo str_replace('"', '"', trim($row["Location"])); echo "</select>"; ?></td> </tr> <tr> <td class="hr"><?php echo htmlspecialchars("SubLocation")." " ?></td> <td class="dr"><?php $result2 = mysql_query("SELECT DISTINCT strSubLocation FROM sublocations ORDER BY strSubLocation"); echo "<select name='SubLocation'>"; while($nt=mysql_fetch_array($result2)){ echo "<option value='$nt[strSubLocation]'"; if($nt[strDivision] == "--- Select Sublocation ---") { echo " selected"; } echo ">$nt[strSubLocation]</option>"; } echo str_replace('"', '"', trim($row["SubLocation"])); echo "</select>"; ?></td> </tr> <tr> <td class="hr"><?php echo htmlspecialchars("Country")." " ?></td> <td class="dr"><?php $result2 = mysql_query("SELECT DISTINCT strCountry FROM countries ORDER BY strCountry"); echo "<select name='Country'>"; while($nt=mysql_fetch_array($result2)){ echo "<option value='$nt[strCountry]'"; if($nt[strDivision] == "--- Select Country ---") { echo " selected"; } echo ">$nt[strCountry]</option>"; } echo str_replace('"', '"', trim($row["Country"])); echo "</select>"; ?></td> </tr> <tr> <td class="hr"><?php echo htmlspecialchars("Country Of Residence")." " ?></td> <td class="dr"><?php $result2 = mysql_query("SELECT DISTINCT strCountryOfResidence FROM `country of residence` ORDER BY strCountryOfResidence"); echo "<select name='Country Of Residence'>"; while($nt=mysql_fetch_array($result2)){ echo "<option value='$nt[strCountryOfResidence]'"; if($nt[strDivision] == "--- Select Country Of Residence ---") { echo " selected"; } echo ">$nt[strCountryOfResidence]</option>"; } echo str_replace('"', '"', trim($row["Country Of Residence"])); echo "</select>"; ?></td> </tr> <tr> <td class="hr"><?php echo htmlspecialchars("Form Of Payment")." " ?></td> <td class="dr"><?php $result2 = mysql_query("SELECT DISTINCT strFormOfPayments FROM `form of payment` ORDER BY strFormOfPayments"); echo "<select name='Form Of Payment'>"; while($nt=mysql_fetch_array($result2)){ echo "<option value='$nt[strFormOfPayments]'"; if($nt[strDivision] == "--- Select Form of Payment ---") { echo " selected"; } echo ">$nt[strFormOfPayments]</option>"; } echo str_replace('"', '"', trim($row["Form Of Payment"])); echo "</select>"; ?></td> </tr> <tr> <td class="hr"><?php echo htmlspecialchars("Bank")." " ?></td> <td class="dr"><?php $result2 = mysql_query("SELECT DISTINCT strBanks FROM `banks` ORDER BY strBanks"); echo "<select name='Bank'>"; while($nt=mysql_fetch_array($result2)){ echo "<option value='$nt[strBanks]'"; if($nt[strDivision] == "--- Select Bank ---") { echo " selected"; } echo ">$nt[strBanks]</option>"; } echo str_replace('"', '"', trim($row["Bank"])); echo "</select>"; ?></td> </tr> <tr> <td class="hr"><?php echo htmlspecialchars("Current Residence")." " ?></td> <td class="dr"><?php $result2 = mysql_query("SELECT DISTINCT `Current Residence` FROM `members` ORDER BY `Current Residence`"); echo "<select name='Current Residence'>"; while($nt=mysql_fetch_array($result2)){ echo "<option value='$nt[Current Residence]'>$nt[Current Residence]</option>"; } echo str_replace('"', '"', trim($row["Current Residence"])); echo "</select>"; ?></td> </tr> </table> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/114829-getting-data-to-list-box-when-fields-are-atleast-two-word/#findComment-590479 Share on other sites More sharing options...
kenrbnsn Posted July 15, 2008 Share Posted July 15, 2008 Which line is line 766? Ken Link to comment https://forums.phpfreaks.com/topic/114829-getting-data-to-list-box-when-fields-are-atleast-two-word/#findComment-590483 Share on other sites More sharing options...
jkkenzie Posted July 15, 2008 Author Share Posted July 15, 2008 the "}" after line : echo "<option value='$nt[Current Residence]'>$nt[Current Residence]</option>"; } is the 766 Link to comment https://forums.phpfreaks.com/topic/114829-getting-data-to-list-box-when-fields-are-atleast-two-word/#findComment-590490 Share on other sites More sharing options...
kenrbnsn Posted July 15, 2008 Share Posted July 15, 2008 The problem is in this line <?php echo "<option value='$nt[Current Residence]'>$nt[Current Residence]</option>"; ?> The string "Current Residence" must be quoted if it is used as an index into an array. Use either <?php echo '<option value="' . $nt['Current Residence'] . '">' . $nt['Current Residence'] . "</option>"; ?> or <?php echo "<option value='{$nt['Current Residence']}'>{$nt['Current Residence']}</option>"; ?> Ken Link to comment https://forums.phpfreaks.com/topic/114829-getting-data-to-list-box-when-fields-are-atleast-two-word/#findComment-590498 Share on other sites More sharing options...
jkkenzie Posted July 15, 2008 Author Share Posted July 15, 2008 I had to make the field one word by using mysql "AS" as follows: $result2 = mysql_query("SELECT DISTINCT `Current Residence` AS strres FROM `members` ORDER BY `Current Residence` "); echo "<select name='Current Residence'>"; while($nt=mysql_fetch_array($result2)){ echo "<option value='$nt[strres]'"; if($nt[strDivision] == "--- Select Current Residence ---") { echo " selected"; } echo ">$nt[strres]</option>"; } Quoting does not work. Link to comment https://forums.phpfreaks.com/topic/114829-getting-data-to-list-box-when-fields-are-atleast-two-word/#findComment-590503 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.