Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Regular Coder Deacon Frost's Avatar
    Join Date
    Feb 2008
    Location
    Between the Lines
    Posts
    279
    Thanks
    31
    Thanked 4 Times in 4 Posts

    Presentation in an echo

    How would I do presentational HTML in an echo?

    For instance putting a form, or a table... it'd have to be all of it too =/.

  • #2
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    you can close the php tags
    PHP Code:
    <?php
    $var 
    'something';
    $mtime microtime();

    ?>

    <br /> <td>//etc.
    <?php echo "$var";?> <div id=<?php echo "$mtime"?>>
    get the point?

  • #3
    Regular Coder Deacon Frost's Avatar
    Join Date
    Feb 2008
    Location
    Between the Lines
    Posts
    279
    Thanks
    31
    Thanked 4 Times in 4 Posts
    I know how that works, I need to put all of the presentational data inside of an echo though, otherwise I can't do what I need to do =/.

  • #4
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    You could use the Heredoc syntax.

    Code:
    echo <<<EOF
    <h1>Using Heredoc</h1>
    <p>You don't have to worry about escaping single (') or double (") quotes while using heredoc.  You can also include $variables inside that will be parsed.</p>
    EOF;
    More information available here.
    http://www.php.net/types.string
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • Users who have thanked StupidRalph for this post:

    Deacon Frost (02-21-2008)

  • #5
    Regular Coder
    Join Date
    Aug 2002
    Location
    Oregon, United States of America
    Posts
    882
    Thanks
    1
    Thanked 9 Times in 9 Posts
    StupidRalph is correct, though it has its limitations. You cannot use constants or concat anything inside a heredoc.

    I think a better question though, is why do you have to use an echo?
    If I'm postin here, I NEED YOUR HELP!!

  • #6
    Regular Coder Deacon Frost's Avatar
    Join Date
    Feb 2008
    Location
    Between the Lines
    Posts
    279
    Thanks
    31
    Thanked 4 Times in 4 Posts
    http://www.codingforums.com/showthread.php?t=133414



    because i need to list everything, and this seems to be the only plausible way to do it.

  • #7
    Banned
    Join Date
    Feb 2008
    Location
    Winnipeg, Canada
    Posts
    396
    Thanks
    0
    Thanked 29 Times in 29 Posts
    PHP Code:
    <?php

    echo "<span style=\"font-weight:bold\">bold</span> <div style=\"color:#ff0000\">red</div>";

    ?>

  • #8
    New Coder
    Join Date
    Aug 2007
    Posts
    14
    Thanks
    3
    Thanked 1 Time in 1 Post
    You can use a dot to concatenate strings, for example...

    PHP Code:
    echo '<div id="myDiv">' $myVar '</div>'
    or

    PHP Code:
    echo '<td>' $row['name'] . '</td>'
    etc. etc.

    For reference: http://php.net/echo
    "entia non sunt multiplicanda praeter necessitatem" - "Entities should not be multiplied beyond necessity" Occam's Razor

  • #9
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    Quote Originally Posted by Scrumpy.Gums View Post
    You can use a dot to concatenate strings, for example...

    PHP Code:
    echo '<div id="myDiv">' $myVar '</div>'
    or

    PHP Code:
    echo '<td>' $row['name'] . '</td>'
    etc. etc.

    For reference: http://php.net/echo
    Or....
    PHP Code:
    echo '<div id="myDiv">' $myVar '</div>'
    You are seeing correctly; those are commas. If you're using echo, you can pass in parameters* which will be faster than concatenating.

    *echo is actually a language construct and not a function thus the reason you do not have to use the parenthesis.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #10
    Regular Coder Deacon Frost's Avatar
    Join Date
    Feb 2008
    Location
    Between the Lines
    Posts
    279
    Thanks
    31
    Thanked 4 Times in 4 Posts
    ok, and that'll work for all of a table? even if I press return at the end of each line, it'll parse it using the " and '?

  • #11
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    Which method are you referring? If you're trying to echo out a table I wouldn't use ' or " I'd use heredoc syntax. Or as also, stated, I'd break out of PHP and simply codie the table in HTML.

    I wouldn't simply use ' and " b/c of all the possible escaping of quotation marks you'd have to do.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #12
    Regular Coder Deacon Frost's Avatar
    Join Date
    Feb 2008
    Location
    Between the Lines
    Posts
    279
    Thanks
    31
    Thanked 4 Times in 4 Posts
    Alright, Ima try it with the Heredoc complex syntax.

    See, what I'm trying to do is list everything from a database in a table using a column, and order by that column. The problem I'm running into is it shows both of the same data... I couldn't figure out how to seperate them, and list them ALL. It just shows the same one multiple times using the variables.

    So when I went to W3Schools and it said use echo "<br />" I'ma see if that works.

  • #13
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    We'd be able to help you out more if you were to post some actual code up too . You can show us what is happening...and your desired outcome.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #14
    Regular Coder Deacon Frost's Avatar
    Join Date
    Feb 2008
    Location
    Between the Lines
    Posts
    279
    Thanks
    31
    Thanked 4 Times in 4 Posts
    http://www.legalmovies.tv

    The first page shows movies added today. That's sort of my goal, except I'll list them by different criterias, etc.

    what I have:
    http://downstage.tv/test.php
    PHP Code:
    <?php 
    include("/home/stage/public_html/css/inc/theaterconn.php");  

    $sql "SELECT id,filmid,name FROM theater WHERE status='2' LIMIT 2 ORDER BY id"
    $result mysql_query$sql ) or die('mysql_error()' 'Error:  ' mysql_errno() ); 
    $row mysql_fetch_assoc($result); 
    $num mysql_num_rows($result); 

    $id $row['id']; 
    $filmid $row['filmid']; 
    $name $row['name']; 

    ?> 



    <table> 
    <tr> 
    <td> 
    <form action="theater.php" method="get"> 
    <input type="hidden" name="id" value ="<? echo $id ?>"> 
    <input type="image" src="http://images.stage6.com/video_images/<? echo $filmid ?>t.jpg" value="Submit" alt="Go to Theater"> 
    <br /> 
    <center><? echo $name ?></center> 
    <tr> 
    <td> 
    <input type="hidden" name="id" value ="<? echo $id ?>"> 
    <input type="image" src="http://images.stage6.com/video_images/<? echo $filmid ?>t.jpg" value="Submit" alt="Go to Theater"> 
    <br /> 
    <center><? echo $name ?></center> 
    </form> 
    </tr> 
    </table>

    The problem being is it doesn't change (which it shouldn't)... I need to use those variables though, or if I do use the different rows, it needs to select from the selected, not from the full database.

  • #15
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    I would do something like this as looks like you just want to show all of the videos in which point you need the variables $id, $fileid, and $name to change.
    PHP Code:
    <?php 
    include("/home/stage/public_html/css/inc/theaterconn.php");  
    $sql "SELECT id,filmid,name FROM theater WHERE status='2' LIMIT 2 ORDER BY id"
    $result mysql_query$sql ) or die('The error was: ' mysql_error() . '<br>The query was: ' $sql); 
    $num mysql_num_rows($result)
    if(
    $num 0)
    {
        while(
    $row mysql_fetch_assoc($result))
        {
            
    $id $row['id']; 
            
    $filmid $row['filmid']; 
            
    $name $row['name']; 
    ?>
    <form action="theater.php" method="get"> 
    <table> 
    <tr> 
    <td> 
    <input type="hidden" name="id" value ="<?php echo $id?>"> 
    <button style="background:none;border:0;cursor:pointer;"><img src="http://images.stage6.com/video_images/<?php echo $filmid?>t.jpg" alt="Go to Theater"></button> 
    <br /> 
    <center><?php echo $name?></center> 
    <br /> 
    </td>
    </tr> 
    </table>
    </form>
    <?php
        
    }
    }
    ?>
    I would use a button element instead of input type="image" because input type="image" sends two more variables, the x and y coordinates of where the user clicked on the image.
    Last edited by _Aerospace_Eng_; 02-21-2008 at 03:25 AM.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    Deacon Frost (02-21-2008)


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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