Jump to content

how can I integrate column....


nec9716

Recommended Posts

with this code I see NAME TEAMNAME AND EMAIL all that on the same row

if I want to keep that but in column ( like a table )

all name in the same column

all teamname in the same column

all email in the same column

How can i do that?

 

 

function list_users()

{

$y = 0; //counter

 

$sql = "select * from user ";

$result = conn($sql);

 

//EDIT

echo "<table width='400' align='center' cellpadding='0' cellspacing='0'>

<tr><td colspan='2' align='center' style='font-size:28px; font-weight:bold;'>Manage User Data</td></tr>

<tr><td colspan='2'> </td></tr>

<tr><td colspan='2' align='center' ><a href='".$_SERVER['PHP_SELF']."?action=add'>Add A new User</a></td></tr>

<tr><td colspan='2'> </td></tr>";

echo "<tr><td colspan='2' align='center'><b>Click A User To Edit </b></td></tr>";

if (mysql_num_rows($result)){

 

while($rows = mysql_fetch_array($result)){

 

//change row background color

(($y % 2) == 0) ? $bgcolor = "#99ff66" : $bgcolor=" #33ff00";

 

$name = $rows['name'].' '.$rows['teamname'].' '.$rows['email'];

$id = $rows['userid'];

 

//echo out the row

echo "<tr style='background-color:$bgcolor;'><td><a href='".$_SERVER['PHP_SELF']."?id=$id'>$name</a></td><tr>";

$y++; //increment the counter

}//end while

echo "</table>";

}else{

 

echo "<tr><td colspan='2' align='center'><b>No data found.</b></td></tr>";

}//endif

}

Link to comment
https://forums.phpfreaks.com/topic/98173-how-can-i-integrate-column/
Share on other sites

Basically run each row in your while loop where you are grabbing your information from the database.

 

<table>

Grab database information
while (blabla) {

<tr><td></td></tr>

}

</table>

 

Very basic but its just so you know the idea you need. Start and end your table before the while and create your new rows each time the while loop is ran. If you want a header row you can put that up above the while also.

<?php
$sql = "SELECT * FROM `table`";
$result = mysql_query($sql) OR DIE("Error!<br />$sql<br />".mysql_error());
if (mysql_num_rows($result) > 0)
{
echo "<table>";
echo "<tr><th>Name</th><th>Team Name</th><th>Email</th>";
while ($row = mysql_fetch_array($result))
{
	$name = empty($row['name']) ? $row['name'] : " ";
	$team = empty($row['team']) ? $row['team'] : " ";
	$email = empty($row['email']) ? $row['email'] : " ";
	echo "<tr><td>$name</td><td>$team</td><td>$email</td></tr>";
}
echo "</table>";
}
?>

 

The reason for the

$name = empty($row['name']) ? $row['name'] : " ";

is because I don't know how your data is being stored, but if any of those have the possiblity of being NULL/empty, you'll want at least a non-breaking-space ( ), which is like hitting the spacebar, in the cell so it can render the table properly.

function list_users()

{

$y = 0; //counter

 

$sql = "select * from pilote ";

$result = conn($sql);

 

echo "<table width='70%' align='center' cellpadding='0' cellspacing='0'>

<tr><td colspan='2' align='center' style='font-size:28px; font-weight:bold;'>Manage Pilotes Data</td></tr>

<tr><td colspan='2'> </td></tr>

<tr><td colspan='2' align='center' ><ahref='".$_SERVER['PHP_SELF']."?action=add'>Add A Pilote</a></td></tr>

<tr><td colspan='2'> </td></tr>";

echo "<tr><td colspan='2' align='center'><b>Click A Pilote Name To Edit </b></td></tr>";

if (mysql_num_rows($result)){

//show a list prepopulated form with their data in it

while($rows = mysql_fetch_array($result)){

//change row background color

(($y % 2) == 0) ? $bgcolor = "#99ff66" : $bgcolor=" #33ff00";

 

$tname = $rows['name'];

$tteam = $rows['team'];

$tchassis = $rows['chassis'];

$tengine = $rows['engine'];

$id = $rows['id'];

//echo out the row

echo "<tr style='background-color:$bgcolor;'><td><a href='".$_SERVER['PHP_SELF']."?id=$id'>$tname</a></td>

<td>$tteam</TD><td>$tchassis</td><td>$tengine</td></tr>";

$y++; //increment the counter

}//end while

echo "</table>";

}else{

//handle no results

echo "<tr><td colspan='2' align='center'><b>No data found.</b></td></tr>";

}//endif

}

 

 

thank you ...I have modify the script and it work perfectly

thank again

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.