Solved

Arrange by highest (Javascript)

Posted on 2013-01-20
7
212 Views
Last Modified: 2013-01-21
Hi all,

I have a short little php script done that takes the values from the datasbase and displays them on a page. I wonder could someone help me to create an addition to this so that the result count is arranged in descending order, like this:

For example:

<!--<p>New Members: 86
<p>Meditations Today: 45
<p>Journal Entries Today: 22

Here is the print out part of the script:

<!--<p>New Members: <?php echo $new_members_today;  ?> </p>--!>
<p>M Today: <?php echo $total_meditations_today;  ?>  </p>	
<p>J Today: <?php echo $total_journals_today; ?> </p>
<p>ELogged: <?php echo $total_exercises_today; ?></p>
<p>DT oday: <?php echo $total_dyads_today; ?>  </p>
<p>Ebooks Downloaded: <?php echo $total_ebooks_downloaded_today; ?> </p>
<p>Ebooks On Shelf: <?php echo $total_ebooks_shelf_today; ?></p>

Open in new window


Thanks so much for your help,

Derek
0
Comment
Question by:TLN_CANADA
  • 3
  • 3
7 Comments
 
LVL 22

Expert Comment

by:Ivo Stoykov
ID: 38799996
just add
ORDER BY your_filed DESC

Open in new window

to your database query...

HTH

Ivo Stoykov
0
 

Author Comment

by:TLN_CANADA
ID: 38800001
Thanks Ivo but I don't think this will work as they are in different tables. Here is the db part of the code so you'll get a better idea of what I mean.

$query1 = mysql_query("SELECT * FROM exercising_table WHERE exercise_timestamp  > timestampadd(hour, -24, now())");
	$total_exercises_today = mysql_num_rows($query1);
	
	$query2 = mysql_query("SELECT * FROM meditation_table WHERE session_timestamp  > timestampadd(hour, -24, now())");
	$total_meditations_today = mysql_num_rows($query2);
	
	$query3 = mysql_query("SELECT * FROM journal_table WHERE entry_timestamp  > timestampadd(hour, -24, now())");
	$total_journals_today = mysql_num_rows($query3);
	
	$query4 = mysql_query("SELECT * FROM dyad_counter_table WHERE dyad_counter_time   > timestampadd(hour, -24, now())");
	$total_dyads_today = mysql_num_rows($query4);
	
	$query5 = mysql_query("SELECT * FROM phpfox_ebooks_user_downloads WHERE download_timestamp   > timestampadd(hour, -24, now())");
	$total_ebooks_downloaded_today = mysql_num_rows($query5);
	
	$query6 = mysql_query("SELECT * FROM phpfox_ebooks_user_shelf WHERE download_timestamp   > timestampadd(hour, -24, now())");
	$total_ebooks_shelf_today = mysql_num_rows($query6);
	
	//$query7 = mysql_query("SELECT * FROM phpfox_user WHERE ('joined > time() - 86400'); ") ;
	//$new_members_today = mysql_num_rows($query7);




?>
<p><strong>Today</strong></p>
<!--<p>New Members: <?php echo $new_members_today;  ?> </p>--!>
<p>Med Today: <?php echo $total_meditations_today;  ?>  </p>	
<p>Journal Entries Today: <?php echo $total_journals_today; ?> </p>
<p>Exercises Logged: <?php echo $total_exercises_today; ?></p>
<p>D Completed Today: <?php echo $total_dyads_today; ?>  </p>
<p>Ebooks Downloaded: <?php echo $total_ebooks_downloaded_today; ?> </p>
<p>Ebooks On Shelf: <?php echo $total_ebooks_shelf_today; ?></p>

Open in new window

0
 
LVL 22

Expert Comment

by:Ivo Stoykov
ID: 38800020
and these have nothing in common so you could join them?

if they really haven't you could use array like:
$res = array('total_meditations_today' => $total_meditations_today, 'total_journals_today' => $total_journals_today, as so on ...)
array_reverse(sort($res, SORT_NUMERIC))

Open in new window


HTH

Ivo Stoykov
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:TLN_CANADA
ID: 38800025
Yes Ivo, they have nothing in common. So how would I print this array in order then?

Thanks for your help, D
0
 
LVL 12

Expert Comment

by:sivagnanam chandrakanth
ID: 38800039
Try like this, I have hardcoded values for variables

<?php
$array=array();
/*$query1 = mysql_query("SELECT * FROM exercising_table WHERE exercise_timestamp  > timestampadd(hour, -24, now())");
	$array['total_exercises_today'] = mysql_num_rows($query1);
	
	$query2 = mysql_query("SELECT * FROM meditation_table WHERE session_timestamp  > timestampadd(hour, -24, now())");
	$array['total_meditations_today'] = mysql_num_rows($query2);
	
	$query3 = mysql_query("SELECT * FROM journal_table WHERE entry_timestamp  > timestampadd(hour, -24, now())");
	$array['total_journals_today'] = mysql_num_rows($query3);
	*/
	$array['total_exercises_today'] = '5';
	$array['total_meditations_today'] = '8';
	$array['total_journals_today'] = '2';
	asort($array);
	echo "<pre>";
	print_r(($array));
	echo "</pr>";
	

Open in new window

0
 
LVL 22

Accepted Solution

by:
Ivo Stoykov earned 500 total points
ID: 38800061
$html = array('total_meditations_today' => '<p>M Today: __  </p>',
              'total_journals_today' => '<p>J Today: __ </p>', and so on ...);

$res = array('total_meditations_today' => $total_meditations_today,
             'total_journals_today' => $total_journals_today, as so on ...);
arsort($res, SORT_NUMERIC); //Sort an array in reverse order
foreach ($res as $k => $v) {
    echo str_replace('__', $v, $html[$k]) . PHP_EOL;
}

Open in new window


HTH

Ivo Stoykov
0
 

Author Closing Comment

by:TLN_CANADA
ID: 38803596
Thank you, works perfectly!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now