Hi all i need to update some iframe values in my videos table, embed column. Can I achieve this with this kind code below ? I tried already but i got syntax errors. Please help me. here is the code

type of column embed is text.

UPDATE videos
SET embed RAND('<iframe src="http://example.com" height="504" width="921" 
                        frameborder="0" scrolling="no">
               </iframe>',
              '<iframe src="http://example.com" height="504" width="921" 
                       frameborder="0" scrolling="no">
               </iframe>',
               '<iframe src="http://example.com height="504" width="921" 
                        frameborder="0" scrolling="no">
               </iframe>')
WHERE id in(5727,5723,5665)

Here is the error code; #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'RAND ('

Recommended Answers

All 2 Replies

UPDATE videos
SET embed = '<iframe src="http://example.com" height="504" width="921" frameborder="0" scrolling="no"></iframe>'
WHERE id IN (5727,5723,5665)
Member Avatar for diafol

The options for the random content that you provided are all the same. If this is right, then there is not randomness and you should use pritaeas' sql. If all your iframes have the same basic structure, perhaps it's easier to just store the src in one column and build the iframe with php on the fly. This is easier than having to update loads of records if you decide that you want the width to change to 674 instead (for example).

It's possible that you'd want to create a function to display the iframe so that you can have customisable dimensions (and other attributes/properties):

function createIframe($src, $h=NULL,$w=NULL)
{
    $parts = array();
    $parts[] = "<iframe src='$src'";
    if($h) $parts[] = "height='$h'";
    if($w) $parts[] = "width='$w'";
    $parts[] = "frameborder='0' scrolling='no'></iframe>";
    return implode(" ", $parts);
}

echo createIframe($row['src'],$height,$width);   

If you're hardcoding dimensions (as in DB values or above), then you could lose responsiveness.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.