nec9716 Posted March 27, 2008 Share Posted March 27, 2008 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 More sharing options...
aebstract Posted March 27, 2008 Share Posted March 27, 2008 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. Link to comment https://forums.phpfreaks.com/topic/98173-how-can-i-integrate-column/#findComment-502276 Share on other sites More sharing options...
nec9716 Posted March 27, 2008 Author Share Posted March 27, 2008 can I just do that? ( but that not working) error: Parse error: syntax error, unexpected '<' in ........... I ahve try few things but my experience is limited <td>$name = $rows['name'] </td><td>$rows['teamname'] </td><td> $rows['email'] </td>; Link to comment https://forums.phpfreaks.com/topic/98173-how-can-i-integrate-column/#findComment-502297 Share on other sites More sharing options...
soycharliente Posted March 27, 2008 Share Posted March 27, 2008 <?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. Link to comment https://forums.phpfreaks.com/topic/98173-how-can-i-integrate-column/#findComment-502305 Share on other sites More sharing options...
aebstract Posted March 27, 2008 Share Posted March 27, 2008 Well you're obviously gonna have to echo your results.. I was just showing you what you needed to do, the structure.. Link to comment https://forums.phpfreaks.com/topic/98173-how-can-i-integrate-column/#findComment-502344 Share on other sites More sharing options...
soycharliente Posted March 27, 2008 Share Posted March 27, 2008 $name = empty($row['name']) ? $row['name'] : " "; That's actually backwards by the way. Just wanted to point that out. Should be ... $name = empty($row['name']) ? " " : $row['name']; Link to comment https://forums.phpfreaks.com/topic/98173-how-can-i-integrate-column/#findComment-502361 Share on other sites More sharing options...
nec9716 Posted March 28, 2008 Author Share Posted March 28, 2008 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 Link to comment https://forums.phpfreaks.com/topic/98173-how-can-i-integrate-column/#findComment-503036 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.