Jump to content

Can anyone help with this please


Greystoke

Recommended Posts

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

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_

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');

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.