0

how to put where clause variable $didno in following code:

$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM misscall WHERE did_no = ?";
$q = $pdo->query($sql);
$mobile1 = array();
while ($mobi1 = $q->fetchColumn()) {
$mobile1[] = $mobi1;
}
$mobile1list = join(",", $mobile1);
Database::disconnect();

thanks in advance

4
Contributors
3
Replies
26
Views
2 Years
Discussion Span
Last Post by diafol
0

is this what you want:

$sql = "SELECT * FROM misscall WHERE did_no = ". $didno;

or did I not understand your question?

0

This would also work by including the var within the double quotes (this example is if the data type of did_no is a numeric - no single quotes around the php var):

$sql = "SELECT * FROM misscall WHERE did_no = $didno";

However, if did_no is a string (varchar etc) then you must put single quotes around the php var as in:

$sql = "SELECT * FROM misscall WHERE did_no = '$didno'";

The above examples work only if you are using double quotes around the query statement.

0

If you are using a 'placeholder' use a prepared statement not a query.

$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT `mobile` FROM misscall WHERE did_no = ?"; //or whichever field you're after
$stmt = $pdo->prepare($sql);
$stmt->execute(array($didno));
$mobil = $stmt->fetchAll(PDO::FETCH_COLUMN,0);
$mobile1list = implode(",", $mobil);
Database::disconnect();

In order to get unique mobile numbers, I think you can do: $mobil = $stmt->fetchAll(PDO::FETCH_COLUMN | PDO::FETCH_UNIQUE,0) or you can do a SELECT DISTINCT.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.