Code to Create Table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
avvishnu
Forum Newbie
Posts: 3
Joined: Thu Jul 12, 2007 7:38 am

Code to Create Table

Post by avvishnu »

[s]Hei[/s] Hey [s]frnds[/s] friends.. am a new user in this forum.. i am new php programmer. i need to show the values in a table in the webpage which are taken from the database. what is the PHP code for this. please anyone help me.. am a new php programmer. studied php [s]frm[/s] from internet so [s]plz[/s] please anyone help me....

[s]Lov[/s] Love [s]nd[/s] and [s]Pryr[/s] prayer

a v vishnu
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.

Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

There are many, many, examples of this online. What have you tried?
avvishnu
Forum Newbie
Posts: 3
Joined: Thu Jul 12, 2007 7:38 am

Post by avvishnu »

i need to know the code for showing the values of tables in the webpage wchich are selected from the database. if there are 3 row , 3 cloumn of data in the database, i need to show the 3 row 3 cloumn values inside a table in the webpage. i think for that need dyanamic display code is needed. so please anyone help me. i dont no much about php.

Love and Prayer

a v vishnu
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Apparently I need to repeat myself. There are many, many, examples of this online. What have you tried?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

If you are looking for someone to give you code you came to the wrong place. If you need help with code you have written, we can help with that.
avvishnu
Forum Newbie
Posts: 3
Joined: Thu Jul 12, 2007 7:38 am

Post by avvishnu »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hai.. friends... am not looking for the exact code.. i need some helps from you people.. 
i tried the code

Code: Select all

<html> 
<head><title>Display Table</title></head> 
<body> 
<?php 
$database="temp";					/* DB name       */
$host="localhost";
$user="root";						/* Set DB Username */
$pass="";							/* Set DB password*/
mysql_pconnect($host,$user,$pass);  /* DB connect....*/
 
mysql_connect ($host,$user,$pass);
@mysql_select_db($database) or die( "Unable to select database"); 
$result = mysql_query( "SELECT Username,Primaryid FROM registration" ) 
or die("SELECT Error: ".mysql_error()); 
$num_rows = mysql_num_rows($result); 
//print "There are $num_rows records.<P>"; 
print "<table width=500 border=1>\n"; 
while ($get_info = mysql_fetch_row($result)){ 
print "<tr>\n"; 
foreach ($get_info as $field) 
print "\t<td><font face=Copperplate Gothic size=4/>$field</font></td>\n"; 
print "</tr>\n"; 
} 
print "</table>\n"; 
?> 
</body> 
</html>
i need to display the table in the exact postion in the webpage. for that what i need to add.
and also i need to give some different colours for the border and rows

please help me...!!
Any assistance is much appreciated.

a v vishnu


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Your problem has nothing to do with PHP. It is all HTML. You need to know how to format tables.

Code: Select all

<html> 
<head><title>Display Table</title></head> 
<body> 
<?php 
$database="temp";
$host="localhost"; 
$user="root";
$pass="";
if ($!con = mysql_connect($host,$user,$pass)) {
  die('Could not connect to database server.');
}
if (!mysql_select_db($database)) {
  die( "Unable to select database"); 
}

$result = mysql_query( "SELECT `Username`, `Primaryid` FROM `registration`" ) 
or die("SELECT Error: ".mysql_error()); 

$num_rows = mysql_num_rows($result); 
//print "There are $num_rows records.<P>"; 
echo '<table width="500" border="1">'; 
// Row color manager
$alt = false;
while ($row = mysql_fetch_array($result)) { 
  if ($alt) {
    $rowcolor = '#ccc';
  } else {
    $rowcolor = '#fff';
  }

  $alt = !$alt;
  echo '<tr style="background: ' . $rowcolor . ';">
    <td><font face="Copperplate Gothic" size="4">' . $row['Username'] . '</font></td>
    <td><font face="Copperplate Gothic" size="4">' . $row['Primaryid'] . '</font></td>
</tr>'; 
} 
echo '</table>'; 
?> 
</body> 
</html>
Post Reply