Hello, cat1 is a field in my mysql database table I want to check first if cat1 is single word. If its not a single word I want to add underscore(_) between each of the words and then retrieve it on the site and print. Please can anyone help with php code regarding this?
As I understand you actually want to replace the spaces with underscores like e.g. "cat" will remain "cat" but "black cat" will become "black_cat". If this is the case you can do it both on mysql level using REPLACE and on PHP level using str_replace.
<?php // Retrieve your DB data here into $dbField var // $dbField = ... $dbField = trim($dbField); $dbField = str_replace(' ', '_', $dbField); print $dbField; ?> PHP: You really shouldn't work through gaps in your programming knowledge. Buy a second-hand book on PHP and SQL for a few dollars on Amazon.