Greystoke Posted March 9, 2011 Share Posted March 9, 2011 Hi, Can anyone help with this please. <?php $check = tep_db_query("SELECT * FROM tickets ORDER BY `ticket` ASC"); while ($ticket = tep_db_fetch_array($check)) { print_r($ticket); ?> <div> <?php echo $ticket['userid']; ?></div> <div><?php echo $tickets_qty;?></div> <?php } ?> print_r($ticket); is outputting: Array ( [ticket] => 1 [userid] => 2 [day] => 8 [time] => 1299558047 [winner] => 0 ) Array ( [ticket] => 2 [userid] => 1 [day] => 8 [time] => 1299558236 [winner] => 0 ) Array ( [ticket] => 3 [userid] => 1 [day] => 8 [time] => 1299558047 [winner] => 0 ) Array ( [ticket] => 4 [userid] => 1 [day] => 8 [time] => 1299558236 [winner] => 0 ) What I want is for it to display the Userid and the number of tickets that user has. e.g. Userid_____________________Tickets 1___________________________3 2___________________________1 Link to comment https://forums.phpfreaks.com/topic/230058-can-anyone-help-with-this-please/ Share on other sites More sharing options...
Greystoke Posted March 9, 2011 Author Share Posted March 9, 2011 Can anyone help with this, please. Link to comment https://forums.phpfreaks.com/topic/230058-can-anyone-help-with-this-please/#findComment-1184881 Share on other sites More sharing options...
trinaryoc Posted March 9, 2011 Share Posted March 9, 2011 Try this: <?php $check = tep_db_query("SELECT userid, count(ticket) AS 'tick_qty' FROM tickets GROUP BY userid); while ($ticket = tep_db_fetch_array($check)) { ?> <div><?php echo $ticket['userid']; ?></div> <div><?php echo $ticket['tick_qty'];?></div> <?php } ?> if you're running MySQL replace tep_db_ with mysql_ Link to comment https://forums.phpfreaks.com/topic/230058-can-anyone-help-with-this-please/#findComment-1184883 Share on other sites More sharing options...
Greystoke Posted March 9, 2011 Author Share Posted March 9, 2011 That's just what I needed. Thank you. Link to comment https://forums.phpfreaks.com/topic/230058-can-anyone-help-with-this-please/#findComment-1184886 Share on other sites More sharing options...
trinaryoc Posted March 9, 2011 Share Posted March 9, 2011 Glad i could help. Link to comment https://forums.phpfreaks.com/topic/230058-can-anyone-help-with-this-please/#findComment-1184887 Share on other sites More sharing options...
Greystoke Posted March 10, 2011 Author Share Posted March 10, 2011 Try this: <?php $check = tep_db_query("SELECT userid, count(ticket) AS 'tick_qty' FROM tickets GROUP BY userid"); while ($ticket = tep_db_fetch_array($check)) { ?> <div><?php echo $ticket['userid']; ?></div> <div><?php echo $ticket['tick_qty'];?></div> <?php } ?> Hi, How can I get it to show the Username instead of the userid. The Username is stored in a different Table in the database: CREATE TABLE `user` ( userid int(10) unsigned NOT NULL auto_increment, username varchar(100) collate utf8_unicode_ci NOT NULL default '', PRIMARY KEY (userid), KEY username (username), ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=2 ; -- -- Dumping data for table 'user' -- INSERT INTO `user` (userid, username) VALUES (1, 'Admin'); Link to comment https://forums.phpfreaks.com/topic/230058-can-anyone-help-with-this-please/#findComment-1185304 Share on other sites More sharing options...
trinaryoc Posted March 13, 2011 Share Posted March 13, 2011 Hi, How can I get it to show the Username instead of the userid. The Username is stored in a different Table in the database: CREATE TABLE `user` ( userid int(10) unsigned NOT NULL auto_increment, username varchar(100) collate utf8_unicode_ci NOT NULL default '', PRIMARY KEY (userid), KEY username (username), ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=2 ; -- -- Dumping data for table 'user' -- INSERT INTO `user` (userid, username) VALUES (1, 'Admin'); <?php $check = tep_db_query("SELECT t.userid AS 'userid', count(t.ticket) AS 'tick_qty', u.username AS 'username' FROM tickets AS 't' JOIN users AS 'u' ON t.userid = u.userid GROUP BY userid"); while ($ticket = tep_db_fetch_array($check)) { ?> <div><?php echo $ticket['userid']; ?></div> <div><?php echo $ticket['username']; ?></div> <div><?php echo $ticket['tick_qty'];?></div> <?php } ?> I'm worried that my syntax might be off... i dont know TEP databases at all. But that should work. Link to comment https://forums.phpfreaks.com/topic/230058-can-anyone-help-with-this-please/#findComment-1187169 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.