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?

6
  • @Anant why don't you add this as an answer? Commented Apr 24, 2016 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? Commented Apr 24, 2016 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... Commented Apr 24, 2016 at 19:47
  • @Anant no hard feelings, man, it's just a question, there are plenty more to answer... ;) enjoy! Commented Apr 24, 2016 at 19:49
  • 1
    Possible duplicate of Reference - What does this error mean in PHP? Commented Apr 24, 2016 at 20:17

3 Answers 3

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']); 
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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 " '

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.