0

So this is my code:

<nav class="navbar navbar-inverse">
    <div class="container-fluid">
        <div class="navbar-header">
          <a class="navbar-brand" href="#">WebSiteName</a>
        </div>

        <ul class="nav navbar-nav">
          <li class="active"><a href="#">Home</a></li>

          <?php
               $dbconn= new PDO('sqlite:negozio.db');


          $sqlcate = "SELECT * FROM categoria";
          foreach($dbconn->query($sqlcate) as $row) { ?>
          <li class="dropdown"> 
            <a class="dropdown-toggle" data-toggle="dropdown" href="#"><?php echo $row['des_categoria']; ?> <span class="caret"></span></a>

            <ul class="dropdown-menu">
              <?php 
                $sqltipocate = "SELECT tipo.des_tipo FROM tipo, categoria, tipo_cate WHERE tipo_cate.id_cate = categoria.id_categoria AND tipo_cate.id_tipo = tipo.id_tipo AND tipo_cate.id_categoria = " . $row['id_categoria'] . " "" "; 

              foreach($dbconn->query($sqltipocate) as $row1) { ?>

              <li><a href="#"><?php echo $row1['des_tipo']; ?></a></li>
            <?php } ?>  
          </ul>
      </li>
      <?php } ?>

        </ul>
  </div>
</nav>

Everything is working fine until $sqltipocate blabla...

This error always appears:

syntax error, unexpected T_CONSTANT_ENCAPSED_STRING

Can someone help me?

Mike
  • 23,542
  • 14
  • 76
  • 87
  • @Anant why don't you add this as an answer? – benomatis Apr 24 '16 at 19:40
  • @Anant but others may see it and it could help them, so they could upvote and you would get more reputation, or I guess that's not anymore much of a motivation at 10K rep? – benomatis Apr 24 '16 at 19:43
  • @Anant well, apparently it's what I did (not realising it was already there as a comment by you) and indeed I got nothing but downvotes, so I deleted it... well, let me move on... – benomatis Apr 24 '16 at 19:47
  • @Anant no hard feelings, man, it's just a question, there are plenty more to answer... ;) enjoy! – benomatis Apr 24 '16 at 19:49
  • 1
    Possible duplicate of [Reference - What does this error mean in PHP?](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – Mike Apr 24 '16 at 20:17
  • thanks. its still not working but the error is gone. its probably because of the query or something. thanks again – little_zhimey Apr 24 '16 at 21:55

3 Answers3

1

It is concatenation problem as regarded in previous answers. I can add something may make your life easier. It is sprintf

Your sql query string will be the format parameter of sprintf as follows:

            $sqltipocate = sprintf("SELECT tipo.des_tipo FROM tipo, categoria, tipo_cate WHERE tipo_cate.id_cate = categoria.id_categoria AND tipo_cate.id_tipo = tipo.id_tipo AND tipo_cate.id_categoria = %d", $row['id_categoria']); 
SaidbakR
  • 13,303
  • 20
  • 101
  • 195
0

Use curly braces.

Example:

$id = 1;
$sql = "SELECT * FROM something WHERE id = {$id}";

echo $sql;
//SELECT * FROM something WHERE id = 1

Link to code: http://codepad.org/V9QasGHH

marmeladze
  • 6,468
  • 3
  • 24
  • 45
0

Store your $row['id_categoria'] in variable like

$id = $row['id_categoria'];

Then put $id in query like:

$sqltipocate = "SELECT tipo.des_tipo FROM tipo, categoria, tipo_cate WHERE tipo_cate.id_cate = categoria.id_categoria AND tipo_cate.id_tipo = tipo.id_tipo AND tipo_cate.id_categoria = '".$id."'";

See this tipo_cate.id_categoria = ' " $id " '

Devsi Odedra
  • 5,244
  • 1
  • 23
  • 37