user3757853
user3757853

Reputation: 5

Simple php syntax error, needs fixing

I have a code that can get me the category_id of an item. This is the code:

<?php echo lavada_category_id() ; ?>

I want to know how I can add this code. Inside this, I want to replace the number 2 in here;

<?php lavada_query_item("category=2");?>

with:

<?php echo lavada_category_id() ; ?>

I know you cannot do like this

<?php lavada_query_item("category=<?php echo lavada_category_id() ; ?>");?>

But how can I do it?

Upvotes: 0

Views: 36

Answers (3)

Pushpak Patel
Pushpak Patel

Reputation: 828

You just need to concatenate the string like this:

<?php lavada_query_item("category=". lavada_category_id() );?>

Upvotes: 0

Wayne Allen
Wayne Allen

Reputation: 840

I think this is what you are looking for:

<?php lavada_query_item(lavada_category_id());?>

The value returned from thelavada_category_id() function will be passed into the lavada_query_item() function.

Upvotes: 0

GGio
GGio

Reputation: 7643

Why not store it into a variable and then use that variable?

<?php 
    $catID = lavada_category_id();
    lavada_query_item("category={$catID}");
 ?>

OR if you just want category ID to be passed into lavada_query_item do this:

lavada_query_item($catID);

The syntax error that you have is that you can not use <?php within <?php

Upvotes: 1

Related Questions