2

How can i fill my array with PDO statement which have multiple conditions?

$stmt = $conn->prepare("SELECT * 
                        FROM the_table 
                        WHERE stmt1 = '$value1' 
                          AND stmt2 = '$value2' 
                        ORDER BY sent_date");
$stmt->execute();
$row = $stmt->fetchAll();

So, this works, but I need the of the table data from my table, because I going to get only the first statement values. What I mean? If my first value (like $value1) is out the selecting change to the second statement's value (like $value2). And i will get all of my table data where exists $value1 and $value2 I need the values an array like $row

Sorry for this composition :D. Thanks in advance.

5
  • This is not how you use prepared statements.. I also don't know what your question is. Commented Dec 16, 2016 at 20:49
  • Welcome to SO. Please read What topics can I ask about and How to ask a good question And the perfect question And how to create a Minimal, Complete and Verifiable example Commented Dec 16, 2016 at 20:53
  • What don't you understand? Commented Dec 16, 2016 at 21:04
  • How can I fill my array with 2 conditions. This is the question. Commented Dec 16, 2016 at 21:06
  • What does this query give you? I don't understand 1. I need the of the table data from my table 2. If my first value (like $value1) is out the selecting change to the second statement's value (like $value2). 3. I need the values an array like $row. Commented Dec 16, 2016 at 21:10

1 Answer 1

1

Basically, you would prepare your query like that

<?php

/* insert code for database connexion here */

$value1 = 'something';
$value2 = 'whatever';

/* The query itself */
$query = $connexion->prepare('SELECT * FROM the_table WHERE stmt1 = :first AND stmt2 = :second ORDER BY sent_date');

/* Now we add the wanted values to our query */
$query->execute([
    'first' => $value1,
    'second' => $value2
]);

$result = $query->fetchAll();

Do not forget to check if the result is what your expected.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.