Vote once with Status: ON / OFF feature

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

v3inTe
Forum Newbie
Posts: 21
Joined: Thu Oct 06, 2011 2:39 am

Re: Vote once with Status: ON / OFF feature

Post by v3inTe »

No,.
i want to add the text "NOW PLAYING" at the first data..
and "UP NEXT" at the second data..
v3inTe
Forum Newbie
Posts: 21
Joined: Thu Oct 06, 2011 2:39 am

Re: Vote once with Status: ON / OFF feature

Post by v3inTe »

anyone. :)
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Vote once with Status: ON / OFF feature

Post by social_experiment »

Code: Select all

<?php
switch($counter) {
		case 1:
		$title = 'Now Playing';
		break;
		case 2:
		$title = 'Up Next';
		break;
		default:
		$title = '';
		break;
	}
?>
Add this inside the while loop and somewhere in the script echo $title. Hth
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
v3inTe
Forum Newbie
Posts: 21
Joined: Thu Oct 06, 2011 2:39 am

Re: Vote once with Status: ON / OFF feature

Post by v3inTe »

Code: Select all

<?php
 // check the value from the voting status table
 $qry = "SELECT status FROM songreqstat";
 $sql = mysql_query($qry);
 $ary = mysql_fetch_array($sql);
 $value = $ary['status'];
if (strtolower($value) == 'yes' or strtolower($value) == 'pause') {

 // select the data from the database
 $qry = "SELECT * FROM songreqlist WHERE songstatus='approved' ORDER BY srlid ASC";
 $sql = mysql_query($qry);
 $counter = 1;
  echo '<table broder="0" width="305">';
  // echo table headers, etc
  while ($ary = mysql_fetch_array($sql)) {

switch($counter) {
                case 1:
                $ary['stitle'] = 'Now Playing';
                break;
                case 2:
                $ary['stitle'] = 'Up Next';
                break;
                default:
                $title = '';
                break;
        }

    echo '<tr>';
    echo '<td><div class="number-bg"><div class="number">';
    echo $counter;
    echo '</div></div></td>';
    echo '<td width="100%"><div class="reqbg"><b>&nbsp;&nbsp;&nbsp;';
    echo $ary['stitle'];
    echo ' - ';
    echo $ary['sartist'];
    echo '</b><br/>';
    echo '&nbsp;&nbsp;&nbsp;<small><font style="color:#e6e6e6;">Requested by: ';
    echo $ary['reqby'];
    echo '</font></small></div></td>';
    echo '<td></td>';
    echo '</tr>';
    $counter = $counter + 1;
  }
    echo '</table>';
}
else {
echo '<center><b><br/><br/><br/>Sorry, Song Request will not be entertained at this moment.<br/><br/>a Current 

DJ is playing/finishing all remaining song request(s).<br/><br/>or DJ is not accepting song request 

anymore.</b></center>';
}
?>
No changes.. :D
not working. i dont know if i placed the code correctly.
v3inTe
Forum Newbie
Posts: 21
Joined: Thu Oct 06, 2011 2:39 am

Re: Vote once with Status: ON / OFF feature

Post by v3inTe »

here's the result:
Image
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Vote once with Status: ON / OFF feature

Post by social_experiment »

Is there a specific reason for adding the title to the array $ary?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
v3inTe
Forum Newbie
Posts: 21
Joined: Thu Oct 06, 2011 2:39 am

Re: Vote once with Status: ON / OFF feature

Post by v3inTe »

actually none..
why??
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Vote once with Status: ON / OFF feature

Post by social_experiment »

v3inTe wrote:actually none..
why??
Thought there might a issue with adding the value to the array but it doesn't seem to be that. Is there a stitle field within your database?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
v3inTe
Forum Newbie
Posts: 21
Joined: Thu Oct 06, 2011 2:39 am

Re: Vote once with Status: ON / OFF feature

Post by v3inTe »

yes, there is..
stitle, sartist, reqby, etc. :)
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Vote once with Status: ON / OFF feature

Post by social_experiment »

$ary['stitle'] already contains a value you might want to use later; use another variable like $title or $songStatus
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
v3inTe
Forum Newbie
Posts: 21
Joined: Thu Oct 06, 2011 2:39 am

Re: Vote once with Status: ON / OFF feature

Post by v3inTe »

i got it. :)
thanks a lot!
v3inTe
Forum Newbie
Posts: 21
Joined: Thu Oct 06, 2011 2:39 am

Re: Vote once with Status: ON / OFF feature

Post by v3inTe »

social_experiment,
another one..

if the table is empty,
it will echo the following msg "No song added yet"
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Vote once with Status: ON / OFF feature

Post by social_experiment »

For the last message to be displayed you have to count the amount of rows within the table

Code: Select all

<?php
 // 'id' should be some unique key, i use the primary key of the table usually.
 $countSql = "SELECT COUNT(id) FROM table";
 $countQry = mysql_query($countSql);
 $countAry = mysql_fetch_array($countQry);
 $rows = $countAry[0];

 if ($rows == 0) {
    $title = 'No song added yet';
    echo $title;
 }
 else {
    // echo your table, data, etc
 }
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
v3inTe
Forum Newbie
Posts: 21
Joined: Thu Oct 06, 2011 2:39 am

Re: Vote once with Status: ON / OFF feature

Post by v3inTe »

thank you so much!
great help.
v3inTe
Forum Newbie
Posts: 21
Joined: Thu Oct 06, 2011 2:39 am

Re: Vote once with Status: ON / OFF feature

Post by v3inTe »

hello social!
if i place the separate code in the page, it shows two echos.. :(
is there a way to combine the two??

Code: Select all

<?php
 // check the value from the voting status table
 $qry = "SELECT status FROM songreqstat";
 $sql = mysql_query($qry);
 $ary = mysql_fetch_array($sql);
 $value = $ary['status'];
if (strtolower($value) == 'yes' or strtolower($value) == 'pause') {

 // select the data from the database
 $qry = "SELECT * FROM songreqlist WHERE songstatus='approved' ORDER BY srlid ASC";
 $sql = mysql_query($qry);
 $counter = 1;

  echo '<table broder="0" width="305">';
  // echo table headers, etc
  while ($ary = mysql_fetch_array($sql)) {

switch($counter) {
                case 1:
                $title = '<font style="color: red;"><b>&nbsp;NOW PLAYING</b></font> | Req by:&nbsp;';
                break;
                case 2:
                $title = '<font style="color: red;"><b>&nbsp;UP NEXT</b></font> | Req by:&nbsp;';
                break;
                default:
                $title = '&nbsp;Requested by:&nbsp;';
                break;
        }
    echo '<tr>';
    echo '<td><div class="number-bg"><div class="number">';
    echo $counter;
    echo '</div></div></td>';
    echo '<td width="100%"><div class="reqbg"><b>&nbsp;';
    echo $ary['stitle'];
    echo ' - ';
    echo $ary['sartist'];
    echo '</b><br/>';
    echo '<small>';
    echo $title;
    echo $ary['reqby'];
    echo '</small></div></td>';
    echo '<td></td>';
    echo '</tr>';
    $counter = $counter + 1;
}
    echo '</table>';
}
else {
echo '<center><b><br/><br/><br/>Sorry, Song Request will not be entertained at this moment.<br/><br/>a Current 

DJ is playing/finishing all remaining song request(s).<br/><br/>or DJ is not accepting song request 

anymore.</b></center>';
}
?>
and

Code: Select all

<?php
 // 'id' should be some unique key, i use the primary key of the table usually.
 $countSql = "SELECT COUNT(id) FROM table";
 $countQry = mysql_query($countSql);
 $countAry = mysql_fetch_array($countQry);
 $rows = $countAry[0];

 if ($rows == 0) {
    $title = 'There are no song on the list.<br/>Please wait the current DJ to approve your Song Request.<br/>Thank you!';
    echo $title;
 }
 else {
    // echo your table, data, etc
 }
?>
so that, if the status is not set to "yes" or "pause"
it'll echo this line:

Code: Select all

Sorry, Song Request will not be entertained at this moment.
a Current DJ is playing/finishing all remaining song request(s).
or DJ is not accepting song request anymore.
if the status is YES / PAUSE AND the table has no data yet,
that's the time that "No song added yet" will appear..
otherwise, display all data in the table..

because in my case,
there are 2 messages display..
Sorry, Song Request will not be entertained at this moment.

a Current DJ is playing/finishing all remaining song request(s).

or DJ is not accepting song request anymore.


There are no song on the list.

Please wait the current DJ to approve your Song Request.

Thank you!
i hope you can help with this.
thank you. :)
Post Reply