Jump to content
xisto Community
Neyoo

How To Show Serial Nums In PHP Table For Contents Of MySQL DB Serial Numbering for output contents of mysql in php table

Recommended Posts

Hello there,I'm looking for some education. How would you show the serial numbering for outputted contents of mysql database. I used a table created in PHP to output content (i.e. an alumni database) and I created a column for S/N, so that at a glance anyone can tell how many members have registered. Thanks house.Neyoo

Share this post


Link to post
Share on other sites

Hello there,
I'm looking for some education. How would you show the serial numbering for outputted contents of mysql database. I used a table created in PHP to output content (i.e. an alumni database) and I created a column for S/N, so that at a glance anyone can tell how many members have registered. Thanks house.

Neyoo

Well if i understand correctly your post, try this:
<?php// Extra variables$StartRec="<tr>\n<td width='100%'>\n";$EndRec="</td>\n</tr>\n";$End="</td>\n</tr>\n</table>\n";// Table Heading$data='<table width="100%" align="center" valign="top" border="1" cellspacing="0" cellpadding="0">' ."\n";$data.="<tr>\n";$data.='<td width="100%" style="text-align:center; font-weight:bold; padding:5px">'."\n";$data.="Your Table Title";$data.=$EndRec;// Total number of records in your table, is optional, use it if you want// this one can be calculated with the mysql_num_rows() function$Total=0; // query to the database, you must change it to work.$query=mysql_query("select serialnumber, other_info from table_name order by serialnumber");// loop to store the datawhile($row=mysql_fetch_array($query)) {	$data.=$StartRec;	$data.="Data: " . $row["serialnumber"] . " " . $row["other_info"] . "\n";	$data.=$EndRec;	$Total++;}// Table Footer$data.="<tr>\n";$data.='<td width="100%" style="text-align:left; font-weight:bold; padding:5px">'."\n";$data.="Total: " . $Total . " Records.\n";$data.=$End;// Show your table infoecho $data;?>
As you see, it is very simple and also I don't include the code that connects to your database, and remember to modify the table name and the columns names that you want to show in your query, in this case, the $query variable.

Best regards,

Share this post


Link to post
Share on other sites

Hello Tavox,Thanx for the reply. A line in your reply ($query=mysql_query("select serialnumber, other_info from table_name order by serialnumber"); suggests that I want the serial numbering to come from the sql table. This is not so...I want the serial numbering to be exclusive of the sql table. A code done in PHP that will just loop through all the records echoed out. Further help needed pls. Thanx.

Share this post


Link to post
Share on other sites

Without doing a lot of copying and pasting and a ton of quoting what your looking for can be set up from one of these sites, In which I start with the best one first and an ok one last. However these are tutorials so you would have to read them and of course figure which one is the better of the tutorials.

https://bytes.com/browse/ https://8'>https://8 https://8'>https://8'>https://bytes.com/browse/ https://8'>https://8 https://8'>https://8
http://v2.scriptplayground.com/tutorials/php/Fetch-MySQL-Row/
'>
http://v2.scriptplayground.com/tutorials/etch-MySQL-Row/

https://www.hugedomains.com/domain_profile.cfm?d=sigsource&e=com https://6'>https://6 https://6'>https://6'>https://www.hugedomains.com/domain_profile.cfm?d=sigsource&e=com https://6'>https://6 https://6'>https://6

From the looks of these tutorials you would have to set up the rows you would need including serial numbers.

Although I somewhat recommend if you do have is set up your DBs with Access and then with that info set up your MYSQL tables with that info (Access course helped out somewhat).

Share this post


Link to post
Share on other sites

Hello Tavox,Thanx for the reply. A line in your reply ($query=mysql_query("select serialnumber, other_info from table_name order by serialnumber"); suggests that I want the serial numbering to come from the sql table. This is not so...I want the serial numbering to be exclusive of the sql table. A code done in PHP that will just loop through all the records echoed out. Further help needed pls. Thanx.

Let me see if i understand correctly, what do you want is to show a serial number where begins at 1 and the last serial number is equal to the total number of rows of your table????? well if it is what you want, you almost get it with my previous code.

Simply change the variable $Total to starts at 1 and echoes it in the loop, then after the loop and before the table footer substract 1 to the variable $Total to show the correct number of rows of your table.

$Total=1; // query to the database, you must change it to work.$query=mysql_query("select serialnumber, other_info from table_name order by serialnumber");// loop to store the datawhile($row=mysql_fetch_array($query)) {	$data.=$StartRec;	$data.="S/N: " . $Total . " Data: " . $row["serialnumber"] . " " . $row["other_info"] . "\n";	$data.=$EndRec;	$Total++;}$Total--;

Let me know if i'm correct, and change the variable names to whatever you want.

Best regards,

Share this post


Link to post
Share on other sites

This is the simplest code to select and display records from MySQL database table and display in PHP.

$cn=mysql_connect($db_host,$db_user,$db_password) or die(mysql_error());mysql_select_db($db_name,$cn) or die(mysql_error());$sql = “SELECT field_name FROM table_name”;$rs = mysql_query($sql) or die(mysql_error());while($row = mysql_fetch_array($rs)){echo $field_name = $row["field_name"];echo “</br>”;}mysql_free_result($rs);

Source:

OR


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.