hank__22 Posted May 27, 2007 Share Posted May 27, 2007 Hi, I'm having trouble with the syntx of this echo: Basically I have a database with a load of youtube video links (e.g. http://www.youtube.com/watch?v=293X33Goo_k) I want to have random videos be loaded when ever you go to the page (this does work). What I have so far for the echo is: echo "<object width="425" height="350">" . "<param name="movie\"" . "value=\"" . row["link"] .\""> . "</param><param name="wmode" value="transparent"></param>" . "<embed src=\"" . row{"link"] .\"" . "type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"> </embed></object>" ; link is surprisingly the link of the youtube video. The full html syntax looks like this: <object width="425" height="350"><param name="movie" value="http://www.youtube.com/watch?v=293X33Goo_k"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/watch?v=293X33Goo_k" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object> But I get parse errors and I'm finding it hard to work out where the quotes go etc, can anyone please help? Also I would like to have the title of the video at the top of the video it self, the table is called text and if possible be inside <h2> tags Quote Link to comment https://forums.phpfreaks.com/topic/53177-solved-help-with-echo-syntax/ Share on other sites More sharing options...
gabeg Posted May 27, 2007 Share Posted May 27, 2007 you need to escape the quotes when displaying things using echo/print. ie: echo "<div id=\"name\"></div>"; Quote Link to comment https://forums.phpfreaks.com/topic/53177-solved-help-with-echo-syntax/#findComment-262701 Share on other sites More sharing options...
chocopi Posted May 27, 2007 Share Posted May 27, 2007 so your code should look like: <object width=\"425\" height=\"350\"><param name=\"movie\" value=\"http://www.youtube.com/v/293X33Goo_k\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"http://www.youtube.com/v/293X33Goo_k\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"425\" height=\"350\"></embed></object> Quote Link to comment https://forums.phpfreaks.com/topic/53177-solved-help-with-echo-syntax/#findComment-262705 Share on other sites More sharing options...
hank__22 Posted May 27, 2007 Author Share Posted May 27, 2007 thats correct Quote Link to comment https://forums.phpfreaks.com/topic/53177-solved-help-with-echo-syntax/#findComment-262708 Share on other sites More sharing options...
triphis Posted May 27, 2007 Share Posted May 27, 2007 It's good that you were able to figure it all out... but I'm wondering why you wanted to echo all of that in the first place? I love PHP because you can just... exit it whenever you want, and go back to writing HTML... and then use <?=$VARIABLE?> when you need to. I find that makes things so much easier Quote Link to comment https://forums.phpfreaks.com/topic/53177-solved-help-with-echo-syntax/#findComment-262716 Share on other sites More sharing options...
hank__22 Posted May 27, 2007 Author Share Posted May 27, 2007 Ok trying it the other way: <div id="content"> <h2> <?php $host="localhost"; // Host name $username="xxxx"; // Mysql username $password="xxxx"; // Mysql password $db_name="xxxx"; // Database name $tbl_name="video"; // Table name // Connect to the database // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Edit this number to however many links you want displaying $num_displayed = 1 ; // Select random rows from the database $result = mysql_query ("SELECT * FROM $tbl_name ORDER BY RAND() LIMIT $num_displayed"); // For all the rows that you selected while ($row = mysql_fetch_array($result)) { echo $row["text"] ; } ?> </h2> <object width="425" height="350"><param name="movie" value="<?php echo $row["link"];?>"></param> <param name="wmode" value="transparent"></param><embed src="<?php echo $row["link"];?>" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object> </div> The video doesn't show, what am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/53177-solved-help-with-echo-syntax/#findComment-262747 Share on other sites More sharing options...
hank__22 Posted May 27, 2007 Author Share Posted May 27, 2007 The problem is with the php part, the link doesn't get put into the code, and so the video wont load: <object width="425" height="350"><param name="movie" value="<?php echo $row["link"];?>"></param> <param name="wmode" value="transparent"></param><embed src="<?php echo $row["link"];?>" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object> Quote Link to comment https://forums.phpfreaks.com/topic/53177-solved-help-with-echo-syntax/#findComment-262754 Share on other sites More sharing options...
gabeg Posted May 27, 2007 Share Posted May 27, 2007 you have: while($row = mysqlwhatever) { $row[stuff] } im pretty sure if you close the bracket, you can't access the $row variable anymore! so do this while ($row = mysql_fetch_array($result)) { echo $row["text"] ; ?> </h2> <object width="425" height="350"><param name="movie" value="<?php echo $row["link"];?>"></param> <param name="wmode" value="transparent"></param><embed src="<?php echo $row["link"];?>" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object> </div> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/53177-solved-help-with-echo-syntax/#findComment-262761 Share on other sites More sharing options...
hank__22 Posted May 27, 2007 Author Share Posted May 27, 2007 that works, sort of! Ive just realized that youtube has two variation of the link: The single link is: http://www.youtube.com/watch?v=o5g2yyvdjrE and the link in the embaded flash is: http://www.youtube.com/watch?v=o5g2yyvdjrE So it doesn't work And posting the whole embaded code into the database results in only half the code being shown on the webpage Quote Link to comment https://forums.phpfreaks.com/topic/53177-solved-help-with-echo-syntax/#findComment-262818 Share on other sites More sharing options...
gabeg Posted May 27, 2007 Share Posted May 27, 2007 Why are you saving the entire embed markup into the data base? Both links have the same code, o5g2yyvdjrE, therefore, just save the code into the database with any other relevant information, and then output using the link that you need. Quote Link to comment https://forums.phpfreaks.com/topic/53177-solved-help-with-echo-syntax/#findComment-262821 Share on other sites More sharing options...
hank__22 Posted May 27, 2007 Author Share Posted May 27, 2007 Ive now done it that way! thank you for spotting that Thanks everyone Quote Link to comment https://forums.phpfreaks.com/topic/53177-solved-help-with-echo-syntax/#findComment-262830 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.