Sir, I upload a youtube video src from my cms and need to display video on webpage. every thing is working fine.
Ehen I upload a data from cms ,every time new row is created in database.but i can not upload youtube video source with every record.
But I need to fetch last uploaded video source from database.
for ex-
In my database there are 5 rows.
Now i need to select last inserted souce from database.
for ex- I need to select row 3 source from database
id name source
1 raj //www.youtube.com/embed/zmotgOJDKXk
2 ravi
3 roy //www.youtube.com/embed/zmotgOJDKXk
4 martin
5 king
Below is my code to echo and select data
<?php
$sql="SELECT id ,source from content order by id desc";
$sub_top=mysql_query($sql);
?>
<?php while ($video= mysql_fetch_array($sub_top)) { ?>
<div class="video"> <iframe width="292" height="315" src="<?php echo $video['source']; ?>" frameborder="0" allowfullscreen></iframe></div>
<?php } ?>
</div>
This should do
SELECT *
FROM content
WHERE source IS NOT NULL
ORDER BY id DESC
LIMIT 1;
Add the clause "LIMIT 0,1" :
$sql = "SELECT id,source FROM content ORDER BY id DESC LIMIT 0,1 WHERE source <> ''";
don't know what you're asking, but this should find the newest row with a source.
$sql="SELECT id ,source from content WHERE source IS NOT NULL order by id desc LIMIT 0,1";
I think that you need to fetch only last record containing youtube URL.
select id, source from content where source ilike '%youtube%' order by id desc limit 1
this will select one record from db and it has to contain word "youtube". I don't use mysql so I didn't test it.
You can use REGEXP by MySQL in order to conduct this operation. The regular expression should be something like www.youtube.com/(.+)
SELECT id,source FROM content ORDER BY id WHERE source REGEXP 'www.youtube.com/(.+)'
This will definitely limit it to only show any record with youtube links
To Display last record with source not null:
$sql="SELECT id ,source FROM content WHERE source IS NOT NULL ORDER By id desc Limit 0,1";
In Frame add Frame unique ids on page and add allowfullscreen=""
Code is below
<div class="video">
<iframe width="292" id="vid_1" height="315" src="<?php echo $video['source']; ?>" frameborder="0" allowfullscreen=""></iframe>
</div>