1

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>
2
  • Are you saying you need to display last record in descending order only if source present? Commented Jan 13, 2015 at 12:57
  • yes. need to display last record in descending order only if source present Commented Jan 13, 2015 at 13:00

7 Answers 7

1

Add the clause "LIMIT 0,1" :

$sql = "SELECT id,source FROM content ORDER BY id DESC LIMIT 0,1 WHERE source <> ''";
Sign up to request clarification or add additional context in comments.

1 Comment

only need to display last record in descending order only if source present
1

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";

Comments

0

This should do

SELECT *
FROM content
WHERE source IS NOT NULL
ORDER BY id DESC
LIMIT 1;

1 Comment

need to display last record in descending order only if source present
0

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.

Comments

0

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

Comments

0

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";

Comments

0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.