-1

this is my first Q.

I cant show the RESULT from $row['id'] ['name'] ['level'] IT only shows ID: NAME: LEVEL:

But the results doest appear

Ive tryed adding PDO::FETCH_ASSOC to the FETCH() but it says 1 parameter given expected 0

require_once 'connection.php';
$query = "SELECT * FROM members";
$stmt = $cnx->prepare($query);
$stmt->execute();

while($row = $stmt->fetch()) {
echo "Id: " . $row['id'] . "<br>";
echo "Name: " . $row['name'] . "<br>";
echo "Level: " . $row['level'] . "<hr>";
}
Pocho22
  • 7
  • 1
  • *"I cant show the results from $row['id'] ['name'] ['level'] The echo "id:" appears but not the result from mysql"* - You're contradicting yourself. – Funk Forty Niner May 20 '16 at 15:31
  • Can we see connection.php ? – Sofiene Djebali May 20 '16 at 15:31
  • You sure you're using PDO to connect with here? and not mysqli_? – Funk Forty Niner May 20 '16 at 15:32
  • Fred -ii- It only appears the ID: but not the resutl that comes from de database that is the id number the member name and the member level Sofiene DJEBALI – Pocho22 May 20 '16 at 15:33
  • @Fred-ii- I *think* he means that `echo "Id: " . $row['id'] . "
    ";` outputs **Id:
    ** - e.g. everything's output bar the record from the database; time for your almost famous *turn on error reporting* comment I feel.
    – CD001 May 20 '16 at 15:33
  • @CD001 I don't bother with error reporting stuff anymore. Not after being bombed about it that I post useless comments about that. Just the generic "check for errors" ;--) – Funk Forty Niner May 20 '16 at 15:34
  • Yes its a school asignment i need PDO – Pocho22 May 20 '16 at 15:34
  • This is what is shown Id: Name: Level: And a i need for example Id: 01 Name: Pocho Level: Newbie – Pocho22 May 20 '16 at 15:36
  • u_mulder It gaves me: 111111 (i have 6 members) – Pocho22 May 20 '16 at 15:38
  • ^ that looks rather like the expected output from `mysqli::fetch()` (i.e. `true` x 6) as does the fact that you get the error `1 parameter given expected 0` ... are you sure you're using PDO? – CD001 May 20 '16 at 15:41
  • [See this, 10+ mins ago?](http://stackoverflow.com/questions/37350305/pdo-not-showing-results?noredirect=1#comment62216646_37350305) you never replied to that. So now I closed the question. Nor to another person who asked to see the connection codes. – Funk Forty Niner May 20 '16 at 15:43
  • I didnt saw that answer, as i told you all this was my first question and first time in this page looking for help – Pocho22 May 20 '16 at 15:54
  • – Fred -ii- The answer was in the connection.php I need a try and a new PDO statement... – Pocho22 May 20 '16 at 16:23

1 Answers1

0

As you're using mysqli api, then it's a bit complicated to use fetch:

$stmt = $cnx->prepare($query);
$stmt->execute();

// first you need to bind result to variables:
$stmt->bind_result($id, $name, $level)
// also make sure that you bind the SAME number 
// of variables as number of fields selected in a query

while($stmt->fetch()) {
    echo "Id: " . $id . "<br>";
    echo "Name: " . $name . "<br>";
    echo "Level: " . $level . "<hr>";
}
u_mulder
  • 54,101
  • 5
  • 48
  • 64
  • there was an answer that is now deleted and was probably right all along. Again... if that's the case, I'm closing this as a duplicate http://stackoverflow.com/questions/17498216/can-i-mix-mysql-apis-in-php - Edit: I closed it. – Funk Forty Niner May 20 '16 at 15:42