Results 1 to 11 of 11

Thread: correct way to write this

  1. #1

    Thread Starter
    Fanatic Member stickman373's Avatar
    Join Date
    Mar 2001
    Location
    MA
    Posts
    909

    Talking correct way to write this

    Not sure exactly how to write this correctly.

    I have some text and the link for it should be as follows:

    href="$_REQUEST['cats'] & view.php? & echo $record['id']"

    now obviously I can't use & to seperate the pieces but how would I write this correctly?

    the "view.php?" is just regular text

    thanks

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    . is the concatenation character

    e.g

    $greeting = 'Hello ' . $name;

  3. #3

    Thread Starter
    Fanatic Member stickman373's Avatar
    Join Date
    Mar 2001
    Location
    MA
    Posts
    909
    i tried something like this:

    Code:
    <p align="center"><b><a href="<?php $_REQUEST['cats'] . 'view.php?' . echo $record['id']?>"><BR><?php echo $record['title']; ?></a></b></p>
    and i get an error

    it should take what i posted "cats" and then add the text view.php? and then the releated id that i am pulling from a query and it makes the url. The link should be the title.

    any ideas what is wrong?

  4. #4
    Fanatic Member Gimlin's Avatar
    Join Date
    Dec 2001
    Location
    Hell
    Posts
    734
    I like to use Print unless it is really long.

    <?php

    print("<p align=\"center\"><b><a href=\"$_REQUEST['cats'] view.php?$record['id']?\"><BR>$record['title']</a></b></p>");

    ?>

  5. #5
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    Originally posted by stickman373

    any ideas what is wrong?
    you're not printing the result. Try this:
    PHP Code:
    <p align="center"><b><a href="<?php print $_REQUEST['cats'] . 'view.php?' $record['id'];?>"><BR><?php print 'Title: ' $record['title']; ?></a></b></p>

  6. #6
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    or:

    PHP Code:
    echo "<a href=\"".$_REQUEST['cats'].'view.php?".$record['id']."\">Text</a>"; 
    Should work too..

  7. #7
    Addicted Member mralston's Avatar
    Join Date
    Aug 2002
    Location
    Altrincham Nr Manchester, England
    Posts
    141
    Or
    PHP Code:
    href="<?=$_REQUEST["cats"] . "view.php?"$record["id"?>"
    or even
    PHP Code:
    href="<?=$_REQUEST["cats"?>view.php?<?=$record["id"?>"

  8. #8
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    you don't need to "echo" it?

  9. #9
    Addicted Member mralston's Avatar
    Join Date
    Aug 2002
    Location
    Altrincham Nr Manchester, England
    Posts
    141
    Nah. You can do it like <%= %> in ASP (but obviously with question marks instead of percent signs).

    You need to have short_open_tag = On defined in php.ini. It's also possible that they have disabled that functionality in later versions of PHP - I'm using 4.0.6 because I don't have access to upgrade our live servers and I'd like to keep the development server in sync with the live one.

  10. #10
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    but u need an = sign?

  11. #11
    Addicted Member mralston's Avatar
    Join Date
    Aug 2002
    Location
    Altrincham Nr Manchester, England
    Posts
    141
    In this case

    <?=literal ?>

    can be used in place of

    <? print(literal) ?>

    like

    <%=literal %>

    can be used in place of

    <% response.write literal %>

    in ASP.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width