Find and replace problem

I have tried to do it myself but I see that it is a bit hard. In my posts there are some short codes like:

[media id=468 width=660 height=440]

I need to get only id of the media and erase all the other words, since now I have used this code:

function do_stuff($values) {
    return '<object id="' . $values['id'] . '" />';
}

$text = 'some stuff [media id=468 width=660 height=440] more stuff';

$text = preg_replace_callback('@\\[media id=(?P<id>\\S+) width=\\S+ height=\\S+\\]@', 
                      'do_stuff', $text);

echo $text;

Will give you some stuff <object id="468" /> more stuff

That id is inside a table. After I get the id I need to put it to a function, because I need to get the link that is at the same line with that id.

For example the table has 2 colums, id and link. I need to echo the link.

Thank you

Ok let mu fully update my question.

My website, has 2 database tables. 1 of them have the posts_table and the other one have the videos.

At the moment i am getting the text images etc , normally from the post_table table. In my CMS when we add a video there is added a short code

[media id=487 width=660 height=440]

This shortcode automaticly get the link of a video from the vid_table where the id is the same as the shortcode.

So what i want is: - I need to do the same thing that the short code do, when a video is added on CMS the short code is showed in the post, i need to delete the shortcode and instead of it want to be played a video that has the link on the vid_table.

I have some problems with my english , so if you dont understand again please tell me Thank you