adam1972 Posted February 13, 2009 Report Share Posted February 13, 2009 I think I figured out how to convert an array into a string and use the string in a query... I have an array with over 40 options on a multi-select drop down list that I want to pass from a form using post to use in a query. When I do it I end up with too many commas and it fails. Here's what I've got.. <?php echo "You selected ".count($display)." for your search"; if (count($display)==1) { for($i=0;$i { $display3 = $display[$i].""; echo $display3; } } else { for($i=0;$i { $display2 = $display[$i].","; $display3 = substr($display2,0,-1); // I've even tried $display3=eregi_replace(',$', '', $display2); echo $display3; } } ?> These methods end up removing the commas across the whole string.. Not just the one at the end. What am I doing wrong? Quote Link to comment Share on other sites More sharing options...
jlhaslip Posted February 13, 2009 Report Share Posted February 13, 2009 Depends on the input that you are trying to remove commas from. What does the original data look like? Could you use implode() to create a string from the array? and echo that? Quote Link to comment Share on other sites More sharing options...
adam1972 Posted February 13, 2009 Author Report Share Posted February 13, 2009 Here's the page: > </pre> <table width="99%" border="0" align="center">Search:Column to Search: ForeclosureType RadarID APN County Address City State Zip Owner OwnerFirstName OwnerLastName OwnerSpouseFirstName Owner2 OwnerAddress OwnerCity OwnerState OwnerZip OwnerPhone PropertyType SqFt YearBuilt Beds Baths LotSize EstimatedValue EstimatedTotalLoanBalance RecordingDate Trustee TrusteeSaleNum Sort by: ForeclosureType RadarID APN County Address City State Zip Owner OwnerFirstName OwnerLastName OwnerSpouseFirstName Owner2 OwnerAddress OwnerCity OwnerState OwnerZip OwnerPhone PropertyType SqFt YearBuilt Beds Baths LotSize EstimatedValue EstimatedTotalLoanBalance RecordingDate Trustee TrusteeSaleNum </table> <br><br><br><br><br><div align="left"> ForeclosureType RadarID APN County Address City State Zip Beds Baths SqFt LotSize Owner OwnerFirstName OwnerLastName OwnerSpouseFirstName Owner2 OwnerAddress OwnerCity OwnerState OwnerZip OwnerPhone PropertyType YearBuilt EstimatedValue EstimatedTotalLoanBalance RecordingDate Trustee TrusteeSaleNum TrusteePhone SaleDate SaleTime SalePlace PublishedBid OpeningBid WinningBid EstimatedLoanPosition LoanDate LoanDocNum LoanAmount loan1RecDate loan1DocNumber loan1LoanAmount loan2RecDate loan2DocNumber loan2LoanAmount loan3RecDate loan3DocNumber loan3LoanAmount </div> <br><br><br Quote Link to comment Share on other sites More sharing options...
jlhaslip Posted February 13, 2009 Report Share Posted February 13, 2009 Try this link: http://jlhaslip.trap17.com/sm/select.php Go to that page and select the information available in the drop-downs and 'submit the form' to see the output. It outputs the POST array followed by a comma separated list of the 'display' array. The php code to create the list is as follows: $out = implode($_POST['display'], ','); echo 'Output after implosion of POST[display] array :' . $out; Of course, i don't have the Database to work with, but you should be able to use this method to create the information as you require. Post back if you need anything else. Quote Link to comment Share on other sites More sharing options...
adam1972 Posted February 15, 2009 Author Report Share Posted February 15, 2009 jlhaslip, Thank you so much!!! I have been looking for weeks with very little luck and lots of confusion! It worked like a charm!! Thank you as well for taking the time and making up that page as an example!!! Quote Link to comment Share on other sites More sharing options...
jlhaslip Posted February 16, 2009 Report Share Posted February 16, 2009 Welcome. Glad to help. Do you want the full page of code? or are you happy with the above posting? Quote Link to comment Share on other sites More sharing options...
adam1972 Posted February 16, 2009 Author Report Share Posted February 16, 2009 The posting was enough of a pointer that I got EXACTLY what I needed. Again... Thank You. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.