5 Replies - 1773 Views - Last Post: 18 April 2011 - 05:30 AM Rate Topic: -----

#1 Mickey1989  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 41
  • Joined: 08-February 11

Store database field into php variable

Posted 18 April 2011 - 03:40 AM

Hello guys,

I am trying to store a field i am getting from a database into a php variable. i was using this:

  $ytlink=mysql_query("SELECT youtube_Link from film WHERE film_ID = $id") 


The problem i was having with this was that when i was echoing that variable it was printing out ResourseID10, so i change it to this :

 
$ytlink=mysql_query("SELECT youtube_Link from film WHERE film_ID=$id LIMIT 1");
	
	while($l = mysql_fetch_array($ytlink)) {	
	 echo $l['youtube_Link'];
	 echo "<br>" ;
      }	



now if i was to use this $l['youtube_Link']; in the embeded youtube link, nothing would come up on the page. The code for the embeded link looks like this:

<iframe title="YouTube video player" width="480" height="390" src="<?php echo $l['youtube_Link'];?>" frameborder="0" allowfullscreen></iframe> 



Any ideas why this will not work?


Thanks
Mickey

Is This A Good Question/Topic? 0
  • +

Replies To: Store database field into php variable

#2 batesy3k  Icon User is offline

  • D.I.C Regular

Reputation: 41
  • View blog
  • Posts: 299
  • Joined: 10-September 09

Re: Store database field into php variable

Posted 18 April 2011 - 04:14 AM

You could try something along these lines (as you are only retrieving one row)
$q = mysql_query("SELECT youtube_link FROM <table> WHERE ...");
list($ytLink) = mysql_fetch_row($q);



$ytLink is now available for use in your iframe or where ever you choose to use it :)

I think the problem you were having is scope as it is within the while() loop... correct me if I am wrong though :)
Was This Post Helpful? 1
  • +
  • -

#3 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,238
  • Joined: 08-June 10

Re: Store database field into php variable

Posted 18 April 2011 - 04:24 AM

you don’t need a while() loop for one result …

check with var_dump($l); what your variable contains.
Was This Post Helpful? 0
  • +
  • -

#4 Mickey1989  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 41
  • Joined: 08-February 11

Re: Store database field into php variable

Posted 18 April 2011 - 04:48 AM

View Postbatesy3k, on 18 April 2011 - 04:14 AM, said:

You could try something along these lines (as you are only retrieving one row)
$q = mysql_query("SELECT youtube_link FROM <table> WHERE ...");
list($ytLink) = mysql_fetch_row($q);



$ytLink is now available for use in your iframe or where ever you choose to use it :)

I think the problem you were having is scope as it is within the while() loop... correct me if I am wrong though :)


i am getting the same result, the ytLink varaible is getting the correct value, but it is still not working
Was This Post Helpful? 0
  • +
  • -

#5 batesy3k  Icon User is offline

  • D.I.C Regular

Reputation: 41
  • View blog
  • Posts: 299
  • Joined: 10-September 09

Re: Store database field into php variable

Posted 18 April 2011 - 05:07 AM

You doing this:
<iframe title="YouTube video player" width="480" height="390" src="<?php echo $ytLink; ?>" frameborder="0" allowfullscreen></iframe>



Could it be your allowfullscreen thats causing it not to work? and as Dormilich said, using var_dump($ytLink) is a good way to check!
Was This Post Helpful? 0
  • +
  • -

#6 Mickey1989  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 41
  • Joined: 08-February 11

Re: Store database field into php variable

Posted 18 April 2011 - 05:30 AM

Guys apologies to every one, i was using the wrong code to embed the video, thanks for your responces
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1