Solved

Arrange by highest (Javascript)

Posted on 2013-01-20
7
215 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

756 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