tags:

views:

40

answers:

2

i have thi function :

<?php
function getmypost($number)
    {
        query_posts('p=1828');
        while (have_posts()) : the_post();
        the_title('<h1>', '</h1>');
        the_content();
        endwhile;
    }
?>

i need to make the 1828 as a variable i have try :

    query_posts('\'p='. $number .'\'');

it does not work.... what can be the RIGHT way to do that ?

+3  A: 

If I understand you correctly

query_posts('p='.$number);

should work.

If you need a single quote ' in the string you'd escape the '

query_posts('p=\''.$number.'\'');

or using double quotes (more elegant, and you can put the variable straight in. Dominik already suggested this in his answer)

query_posts("p='$number'");
Pekka
ok, it work.. byt i need more explaination.... inside the () there must be the '' the same as the delimiter... how can it work ?
marc-andre menard
you could also use query_posts("p=$number");
Dominik
or `("p={$number}")` which would also work if you have a more complex variable name, such as `("p={$numbers[$index]['foo']->value}")`
Wim
This works because it is essentially getting changed to p=valueofnumberhere. What you had was before: query_posts('\'p='. $number .'\''); was getting changed to 'p=valueofnumberhere' (notice how your value has extra quotes in it). If you modified what you had query_posts('p='. $number .''); it would work as well, although the extra .'' at the end is unnecessary.
Brian
@marc-andre: You have no delimiters in your example. The ' that you see are the marks of a string in PHP: http://de2.php.net/manual/en/language.types.string.php
Boldewyn
A: 

You could use

query_posts("'p=$number'");
Dominik
dont work for me !
marc-andre menard