0

I have a script for news output.

<?php

    $m          = new MongoClient();
    $db         = $m->news;
    $collection = 'new';
    $a          = $_GET['id'];

    echo $a;

    $ids        = array('_id' => $a);
    $cursor     = $db->$collection->find($ids);

    echo $cursor->count() . ' document(s) found. <br/>';

    foreach ($cursor as $obj) {
        echo 'Id       : ' . $obj['_id']  . '<br/>';
        echo 'Date     : ' . $obj['Date'] . '<br/>';
        echo 'News     : ' . $obj['News'] . '<br/>';
        echo '<br/>';

?>

Here is the problem. In line 6 if I write so $ids = array('_id' => 1); then I get the first news.

But if I enter here like this $ids = array('_id' => $a); and I send the request so script.php?id=1

Then 0 news is output, although the variable $a is equal to 1

Meloman
  • 3,558
  • 3
  • 41
  • 51

0 Answers0