adding to php print

Discussion in 'Web Design and Development' started by Cabbit, Jun 22, 2007.

  1. Cabbit macrumors 68020

    Cabbit

    Joined:
    Jan 30, 2006
    Location:
    Scotland
    #1
    i would like to add another php print to this, but i dont know how to do it. i've included the bit i want to add to the string and the link it needs to effect.

    Code:
    <?php
    printf("<tr><td><a href=\"javascript:ajaxpage('/includes-functions/
    story_display.php?id=%s<<?usrname=<?php print $usrname2; ?>>>', 'contentarea');\">%s</a></td><td><span style=\"TEXT-ALIGN:center\">%s</span></td>", $row["id"], $row["title"], $row["author"], $row["id"]);
    }
    ?>
     
  2. Super Macho Man macrumors 6502a

    Super Macho Man

    Joined:
    Jul 24, 2006
    Location:
    Hollywood, CA
    #2
    You can't nest prints as far as I know. But there's no reason to anyway.

    $aaa = "cat";
    $bbb = "dog";

    print "I have a $aaa and a $bbb."; ---> "I have a cat and a dog."

    or

    print "I have a " . $aaa . " and a " . $bbb ".";

    If you're trying to do what it looks like you're trying to do, try this:

    Code:
    printf("<tr><td><a href=\"javascript:ajaxpage('/includes-functions/
    story_display.php?id=%s&usrname=$usrname2', 'contentarea');\">%s</a></td><td><span style=\"TEXT-ALIGN:center\">%s</span></td>", $row["id"], $row["title"], $row["author"], $row["id"]);
    }
     
  3. Aea macrumors 6502a

    Aea

    Joined:
    May 23, 2007
    Location:
    Denver, Colorado
    #3
    That's a lot of weird stuff you have going on there...

    Code:
    <?php
    printf("<tr><td><a href=\"javascript:ajaxpage('/includes-functions/
    story_display.php?id=%s<$usrname2>>', 'contentarea');\">%s</a></td><td><span style=\"TEXT-ALIGN:center\">%s</span></td>", $row["id"], $row["title"], $row["author"], $row["id"]);
    }
    ?>
    
     
  4. Cabbit thread starter macrumors 68020

    Cabbit

    Joined:
    Jan 30, 2006
    Location:
    Scotland
    #4
    im trying to make the entire site with ajax some things transfer easy some don't, but the site is really really fast.
     
  5. CoreWeb macrumors 6502

    Joined:
    Mar 2, 2007
    Location:
    Edge of reason
    #5
    Why are you doing so?

    Because in general, it is a bad idea to create an entire site in Ajax (if I understand your meaning). This is because not all browsers support Javascript or have Javascript enabled. It is therefore preferable to start with a normal site, and then add Ajax. Of course, you can make sure that all the back-end is generic and can be reused for both HTML and Ajax output.

    However, it is perfectly alright to make a website entirely in Ajax for the sake of an experiment.

    As for your print statement:
    PHP:
    <?php
    printf
    ("<tr><td><a href=\"javascript:ajaxpage('/includes-functions/
    story_display.php?id=%s<<?usrname=<?php print 
    $usrname2; ?>>>', 'contentarea');\">%s</a></td><td><span style=\"TEXT-ALIGN:center\">%s</span></td>"$row["id"], $row["title"], $row["author"], $row["id"]);
    }
    ?>
    Why not break it down into pieces:
    PHP:
    echo "<tr>";
    echo 
    "<td><a href=\"javascript:ajaxpage('/includes-functions/story_display?id="$row["id"];
    echo 
    "&usrname="$usrname2;
    echo 
    "','contentarea');\">"$row["title"], "</a></td>";
    echo 
    "<td style=\"text-align:center\">"$row["title"], "</td>";
    echo 
    "</tr>";
     

Share This Page