MySQL Table Loop using PHP

Posted by JM4 on Stack Overflow See other posts from Stack Overflow or by JM4
Published on 2010-06-14T19:57:21Z Indexed on 2010/06/14 20:12 UTC
Read the original article Hit count: 130

Filed under:
|

I have an online form which collects consumer data and stores in a dedicated MySQL database. In some instances, data is passed in the URL under the "RefID" variable which is also stored in the database and attached to each registration.

I use the 'mysql_num_rows ($result)' to fetch all agent details on another page but this only returns ALL available details. My goal is as follows:

GOAL

I want to create an HTML table in which rows are automatically generated based on the list of all registrations on my site. A new row is created IF and ONLY IF a unique RefID is present on that particular record. In the event the field is NULL, it is reported on a single line.

In short, the HTML table could look something like this:

RefID - Number of Enrollments

abc123 - 10

baseball - 11

twonk - 7

NULL - 33

Where abc123 is a particular RefID and 10 is the number of times that RefID appears in the DB. If a new registration comes in with RefID = "horses", a new row is created, showing "horses - 1". The HTML table will be viewable by account administrators needing to see the number of enrollments for a particular RefID (which they won't know ahead of time).

Anybody have any suggestions?

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql