Site Cloner PHP Script
Bargain Hunter PHP Script
Job Hunter PHP Script
Site Login and Access Control PHP Script

Selecting Only Numbers From Rows With MYSQL

When it comes to altering data from the database, PHP usually has an answer. In this particular situation, we are outputting weight from the database. The rows from the database output with lbs. For example, the weight for John Sims may be 175 lbs. Now, we want to remove the lbs because the plan is to use the 175 for comparison with Google Chart Tools.

How to we remove the lbs from each row that outputs? We use the preg_replace() function to select only digits.

$command = “SELECT firstname, lastname, weight FROM table_sort WHERE height<>” AND weight<>” “;
$result = mysqli_query($db, $command);
while ($row = mysqli_fetch_assoc($result)) {
$firstname = trim(addslashes($row[‘firstname’]));
$lastname = trim(addslashes($row[‘lastname’]));
$height = $row[‘height’];
$height = preg_replace(‘/\D/’, ”, $height);
}