?
Solved

complex function in php for ticker

Posted on 2009-04-03
12
Medium Priority
?
275 Views
Last Modified: 2013-12-12
hi
i am fetching values from the database previously i have fetched single values which works perfectly fine but now i want to fetch multiple columns of the same row once fetched i need to put this in the ticker
as with the below function i can fetch username but i also want to fetch sum(category) and display next to fetched user name i don't understand how to put the 2nd column next to the username .$get['username'].  which is sum(category)


function ticker_user_trivia ()
{
 
 
	
	$query = mysql_query("SELECT distinct quiz, sum(category),username   FROM codes WHERE timestamp > unix_timestamp(now()) - 300 ");
	$trivia= '';
	while($get = mysql_fetch_array($query)) {
		if(_SEOMOD == 1) 
			$caturl = _URL."/browse-".$get['tag']."-videos-1-date.html";
		else
			$caturl = _URL."/category.php?cat=".$get['tag'];
 
		if($get['id'] == $selected){
		$trivia.= "<li class=\"selectedcat\"><a href=\"".$caturl."\">user scored \n".$get['username']. "\nlogged \n in</a></li>"; //seo links
		} else {
			
		$trivia.= "<li><a href=\"".$caturl."\">".$get['username']. "</a></li>"; 
		echo "logged in";
		//seo links
		}
	}

Open in new window

0
Comment
Question by:mattibutt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 9

Expert Comment

by:LinuxNubb
ID: 24061697
$trivia.= "<li><a href=\"".$caturl."\">".$get['username']. " " . $get['category'] . "</a></li>";
0
 
LVL 11

Author Comment

by:mattibutt
ID: 24061739
hi LinuxNubb
i have tried that it doesnt work plus i need to the subtotal of category field
0
 
LVL 9

Expert Comment

by:LinuxNubb
ID: 24061775
define your sum as a value then:

$query = mysql_query("SELECT distinct quiz, sum(category) as category ,username   FROM codes WHERE timestamp > unix_timestamp(now()) - 300 ");

If you're trying to create a sum of a bunch of rows, and also get the values of individuals rows, it's not going to work.
0
Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

 
LVL 11

Author Comment

by:mattibutt
ID: 24061879
hi LinuxNubb
i only want to fetch two cloumn fetch the username based the query and next to it the sum of category field when i run this query from the mysql it does work but problem is in the above php function
0
 
LVL 9

Expert Comment

by:LinuxNubb
ID: 24061908
You can test the output of the query by placing a line in the loop:

print_r($get);

This will show you exactly what the $get array is populated with.
0
 
LVL 11

Author Comment

by:mattibutt
ID: 24061980
hi
it doesnt print anything
0
 
LVL 9

Expert Comment

by:LinuxNubb
ID: 24061987
Where did you place it?  Put it right under:

while($get = mysql_fetch_array($query)) {
   print_r($get);
0
 
LVL 11

Author Comment

by:mattibutt
ID: 24062013
ok sorry done that the following is shown
Array ( [0] => 040309185100 [quiz] => 040309185100 [1] => 902 [sum(category)] => 902 [2] => nows [username] => nows )
0
 
LVL 9

Accepted Solution

by:
LinuxNubb earned 2000 total points
ID: 24062029
OK.  Now if you give your sum(category a name in the query, like ... SUM(category) as category, that array will show that field as category.

Then, you should be able to place the . $get['category'] in your output statement.
0
 
LVL 11

Author Comment

by:mattibutt
ID: 24062065
thanks buddy its done
0
 
LVL 11

Author Closing Comment

by:mattibutt
ID: 31566329
thanks
0
 
LVL 9

Expert Comment

by:LinuxNubb
ID: 24062523
Very good!  Good luck with the rest!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

801 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