Jump to content

[SOLVED] Help with echo syntax


hank__22

Recommended Posts

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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
}
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.