I'm not that good with code and basically copy and modified stuff to get it to work for my purposes without fully understanding it. Now I'm having issues trying to create a webpage that will allow me to update one entry in the database.
A lot of this is taken from the original program (SAM Broadcaster) Here is the code I have come up with but it has no results and I don't really see any errors to help steer me to what is wrong.
clsss.song.php
.....snip....... public static function getRequestedSong($requestID) {
$db = Database::getInstance();
try {
$select = $db->select()
->from(array('s' => 'songlist'),
array('s.*',
'songID' => 's.ID',
'requestID' => 'r.ID',))
->join(array('r' => 'requestlist'),
's.ID = r.songID',
array('dedicationName' => 'name',
'dedicationMessage' => 'msg'))
->where('r.ID = ?', $requestID);
$row = $db->fetchRow($select);
if (!is_null($row)) {
$song = new self();
$song->setValues($row);
}
} catch (Zend_Db_Adapter_Exception $ex) {
echo "Please verify database settings.<br />";
exit;
}
return $song;
}
public function setRaiseWeight() {
//Increase Song Weight
$query = "UPDATE samdb.songlist SET weight = (weight + 1) WHERE (ID = $currentSong->ID)";
Db::getInstance()->Execute($query);
}
public function setLowerWeight() {
//Lower Song Weight
$query = "UPDATE samdb.songlist SET weight = (weight - 1) WHERE (ID = $currentSong->ID)";
Db::getInstance()->Execute($query);
}
public function setValues($songinfo) {
$properties = get_class_vars(get_class($this));
$methods = get_class_methods($this);
unset($methods[array_search('setValues', $methods)]);.........snip......
display.playing.php
....snip..... <br />
<br />
Track requested by <span id="dedication-name">"<?php echo $currentSong->dedicationName; ?>"</span>
<?php if(!empty($currentSong->dedicationMessage)) : ?>
with message <span id="dedication-message">"<?php echo $currentSong->dedicationMessage; ?>"</span>
<?php endif; ?>
<!-- END:DEDICATION -->
<?php endif; ?>
<br />
<br />
Play Weight Status:
<br />
<button class="button" type="button" onclick="<?php echo setRaiseWeight ?>">+</button>
<?php echo $currentSong->weight; ?>
<button class="button" type="button" onclick="<?php echo setLowerWeight ?>">-</button>
<br />
<br />
Coming up
<br />......snip...
I been racking my brain and looking examples but this is all I can come up with. It fails with no errors but I don't even know if the onclick=
is actually calling the function or if the function is taking the $currentSong->ID
in the class.song.php
. I do know that when I added it as a test in display.playing.php
, it produces/prints the table's id number for the correct entry. I'm stumped but again I don't really know much about coding ... I'm just copying and pasting. I also added a bit of the code before what I added that seems to deal with the db in a different manor but I couldn't understand that version. I know the code I entered is what mysql-workshop says works .. and it does work in there to change the weight... though in mysql the line is more like
UPDATE samdb.songlist SET weight = (weight + 20) WHERE weight > 50 AND weight < 70;
UPDATE
samdb.
songlistSET
weight = '2' WHERE (
ID = '33');
there are single quotes and other markings (lol that screwed up putting the code in this post) but in mysql-workshop both codes work with or without the markings. I'm sure I'm just getting the syntax incorrect but I can not figure it out.
Any help for this incompetent brain dead non-coder would be greatly appreciated
$result = Db::getInstance()->Execute($query);
and then something likevar_dump($result)
to see what's inside the Result object.NULL
but I tried it with a different part of the code that uses$db = Database::getInstance();
so I usedvar_dump($db)
and it dumped a bunch of stuff .. so my code isn't working .. or not getting any results .. thanks for at least giving me a tool to at least see a bit more of what is going on :)