I currently have a MySQL database that I am accessing using PHP. You search a name and it returns the person’s contact information. However, sometimes you search a name that already exists and it returns 2 peoples contact information.
I am inserting the information into an HTML table using JavaScript. PHP is returning the contact information as a long string separated by spaces. And I am using the split function while using the space character as a delimiter.
This is all fine and dandy when the search result only returns 1 name. When it returns 2 names I am having trouble figuring out how separate the two contact’s information. Since PHP is returning them as 1 continuous string.
Here is an snippet of my php code:
$data = mysql_query($sqlString) or die("Issue here:" . mysql_error());
while($row = mysql_fetch_array($data)){
print $row['firstName'] . " " . $row['lastName'];
};
Here is a snippet of my JavaScript Code:
$.post("searchDB.php", {search:$("#searchValue").val(),
searchType:$("#searchType").val()},
function(results) {
var parsedResults = results.split(" ");
//code for inserting into HTML.
});
I’d suggest using a delimeter to separate one person’s full-name from the next:
Leading to the following jQuery (this on the assumption you don’t need to separate out the first-name and last-name to different elements):
If, on the other hand, you need to have first-name and last-name in separate cells: