Results UNDEFINED in SQL query and php -
i new when comes php, sql , still learning, trying last 4 string value of column value telephone numbers: (7258787) trying display last 4 string search query full 7 string (8787) base on have read substring(column_name, -4) result last 4 strings right. codes returns undefined, can enlighten me this?
if (isset($_get['telephone'])) { $data = "%".$_get['telephone']."%"; $sql = 'select telephone, substring(telephone,-4)from employee';
using this:
$sql = 'select * employee telephone ?';
will result correct value of 7258787 result whole string(telephone numbers) type on search box
thank in advance
this whole code:
this not answer whole script, (credits israel barragan) in database have employee table , columns 'id', 'name', 'telephone', , 'email'
<?php header('content-type: application/json'); require_once 'connectiondb.php'; $conn = dbconnect(); $ok = true; // use verify status of update. if (isset($_get['telephone'])) { // create query $data = "%".$_get['telephone']."%"; $sql = 'select * employee telephone ?'; // have tell pdo going send values query $stmt = $conn->prepare($sql); // execute query passing array toe execute(); $results = $stmt->execute(array($data)); // extract values $result $rows = $stmt->fetchall(); $error = $stmt->errorinfo(); //echo $error[2]; } // if there no records. if(empty($rows)) { echo json_encode( array('error'=>'there not records','0'=> 'there not records')); } else { echo json_encode($rows); } ?>
sorry new stackoverflow,
you can bind result in query, , last 4 digits display.
for instance, can this
(not aren't binding parameters. need this)
$stmt->bind_param("s", $data);
and execute this:
$stmt->execute();
in query instead of using select *
, name specific keys , can bind result (assuming need phone number:
$stmt->bind_result($telephone);
then result so:
$stmt->fetch();
then can substring off of $telephone
(in php substr()
)
echo substr($telephone,-4);
(oh yeah , don't forget close object with
$stmt->close();
after done)
edit:
here's query put substring
$data = "%".$_get['telephone']."%"; $stmt = $conn->prepare("select telephone employee telephone ?"); $stmt->bind_param("s", $data); $stmt->execute(); $stmt->bind_result($telephone); $stmt->fetch(); echo substr($telephone,-4); $stmt->close();
Comments
Post a Comment