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
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_

Link to comment
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

}
?>

 

 

 

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.