0

If i had a table that looked like this

# | name |
----------
1  | 1 | 
2  | 2 | 
3  | 3 | 
4  | 4 | 

how would i check if the table had the value of 4 under the name variable, and if it did to run something?

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Skribb11es
  • 41
  • 4

1 Answers1

2

With php you can use inbuilt mysqli_num_rows() function, php documentation

mysqli_result::$num_rows -- mysqli_num_rows — Gets the number of rows in a result

$q = "select name from table where name = '4'";
$r = $mysqli->query($q);
if ($r->num_rows > 0) {
    echo "exists";
} else {
    echo "not exists";
}
sf_admin
  • 577
  • 4
  • 11