Deacon Frost
02-18-2008, 11:54 AM
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 =/.
For instance putting a form, or a table... it'd have to be all of it too =/.
|
||||
Presentation in an echoDeacon Frost 02-18-2008, 11:54 AM 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 =/. rafiki 02-18-2008, 12:47 PM you can close the php tags <?php $var = 'something'; $mtime = microtime(); ?> <br /> <td>//etc. <?php echo "$var";?> <div id=<?php echo "$mtime"; ?>> get the point? Deacon Frost 02-18-2008, 09:35 PM 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 =/. StupidRalph 02-18-2008, 10:05 PM You could use the Heredoc syntax. 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 Ultragames 02-19-2008, 01:40 AM 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? Deacon Frost 02-19-2008, 03:09 PM 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. Andrew Johnson 02-19-2008, 03:13 PM <?php echo "<span style=\"font-weight:bold\">bold</span> <div style=\"color:#ff0000\">red</div>"; ?> Scrumpy.Gums 02-19-2008, 04:44 PM You can use a dot to concatenate strings, for example... echo '<div id="myDiv">' . $myVar . '</div>'; or echo '<td>' . $row['name'] . '</td>'; etc. etc. :rolleyes: For reference: http://php.net/echo StupidRalph 02-19-2008, 08:11 PM You can use a dot to concatenate strings, for example... echo '<div id="myDiv">' . $myVar . '</div>'; or echo '<td>' . $row['name'] . '</td>'; etc. etc. :rolleyes: For reference: http://php.net/echo Or.... 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. Deacon Frost 02-20-2008, 04:42 AM 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 '? StupidRalph 02-20-2008, 01:50 PM 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. Deacon Frost 02-20-2008, 10:35 PM 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. StupidRalph 02-20-2008, 10:45 PM 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. Deacon Frost 02-20-2008, 11:04 PM 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 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. _Aerospace_Eng_ 02-21-2008, 02:19 AM 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 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. Deacon Frost 02-21-2008, 02:29 AM Parse error: syntax error, unexpected T_IF in /home/stage/public_html/test.php on line 16. Which would be if($num > 0) I'm trying to figure it out right now. (I get multiple errors heretoafter deletion of the if) _Aerospace_Eng_ 02-21-2008, 02:34 AM Sorry forgot a semi-colon after $num = mysql_num_rows($result) $num = mysql_num_rows($result); Deacon Frost 02-21-2008, 02:43 AM Alright, thanks for taking the time and writing that out... it worked fantastically and that is the only really major hump of problem I had to overcome! XD. It's amazing how simplistic it was. Now I am moving onto other features, thank you all so much again! Now I can resume my week long block XD! (EDIT: One last question. I was re-reading your post Aero, and I saw that you recommended not using the image because of X Y coordinates. The reason it does that is because of the hidden id field that I had to put into it so the movie would actually work. Is there a better way to do this without compromising the use of images?) _Aerospace_Eng_ 02-21-2008, 02:57 AM I posted the example in my last post prior to the one above. I changed it to a button which works the same way as a submit button and it doesn't pass the x and y coordinates. Forgot to test in IE, the button doesn't work in IE. Are all of the images going to be the same height and width? If so you can style the submit button to look like an image which would solve your problem or can live with the extra coordinates being submitted. |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum