Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

SS mySQL query halp


Go to End


3 Posts   1813 Views

Avatar
slavelabourer

Community Member, 26 Posts

6 October 2010 at 10:13am

So i'm a bit of a newbie having trouble with this sql query. I have a form in the cms that allows a user to input a vimeo video ID and then pass that to the vimeo moogaloop api.

So i've written a query the writes some xml to the head of the current videopage

$query = (int)DB::query("SELECT VimeoID FROM `VideoPage`WHERE `ID` = '$this->ID'")->value();

for some reason it keeps returning the value as 0. Any thoughts are appreciated.
peace,
dan.

$result = mysql_query($query);
$doc = new DomDocument('1.0');

// create root node
$root = $doc->createElement('vimeoURL');
$root = $doc->appendChild($root);

// add node for each row
$occ = $doc->createElement('vimeoURL');
$occ = $root->appendChild($occ);
$child = $doc->createElement('URL');
$child = $occ->appendChild($child);
$value = $doc->createTextNode('URL' + $result);
$value = $child->appendChild($value);

$xml_string = $doc->saveXML();
//header('Content-Type: application/xml; charset=ISO-8859-1');
echo $xml_string;

Avatar
swaiba

Forum Moderator, 1899 Posts

6 October 2010 at 11:26am

hi dan, is there a reason not to use DataObject::get_by_id?
e.g.

$doVideoPage = DataObject::get_by_id('VideoPage',$this->ID);
...
 $occ = $doc->createElement($doVideoPage->vimeoURL); //assuming vimeoURL is in $db of $doVideoPage)
...

Avatar
_Vince

Community Member, 165 Posts

6 October 2010 at 3:02pm

If you really want to use SQLQuery, I think it would look more like this

$query = new SQLQuery();
$query->select = array("VimeoID");
$query->from = array("VideoPage");
$query->where = array("ID = $this->ID");

$result = $query->execute()->value();