bubblebla Posted April 7, 2008 Share Posted April 7, 2008 hi, i'm a newbie in php and i need help.. i'm trying to display a list of data which include 3 tables in a time... this is the coding for the display table : $alt = true; for($i = 0; $i < mysql_num_rows($data); $i++) { $client_id = mysql_result($data, $i, 'ID'); $client_login = mysql_result($data, $i, 'client_login'); $client_password = mysql_result($data, $i, 'client_password'); $client_group = mysql_result($data, $i, 'group_id'); $group_id = client_group ($client_id, $client_group, 'group_id'); $group_name = client_group ($client_id, $client_group, $group_id, 'group_name' ); $opt_deleted = mysql_result($data, $i, 'opt_archived'); if ($alt) { $tr_class = " class=\"alt\""; $alt = false; } else { $tr_class = ''; $alt = true; } $link_class = "edit"; if ($opt_deleted == 'n') { $delete = "<a href=\"/manage-clients/delete/$client_id\" title=\"Delete\" >" . ui_fetch_icon('td_delete', 'Delete') . "</a>"; $purge = ""; } else { $delete = "<a href=\"/manage-clients/restore/$client_id\" title=\"Restore\" >" . ui_fetch_icon('td_back', 'Restore') . "</a>"; $purge = " <a href=\"/manage-clients/purge/$client_id\" title=\"Purge\" >" . ui_fetch_icon('td_x_red', 'Purge') . "</a>"; } ?> <tr<?php echo $tr_class;?>> <td><a href="/manage-clients/edit/<?php echo $client_id;?>" class="td_<?php echo $link_class;?>"><?php echo $client_login;?></a></td> <td><?php echo $client_password;?></td> <td><? echo $group_name; ?></td> <td class="opt" ><?php echo $delete.$purge; ?></td> </tr> <?php } ?> </table> <?php mysql_free_result($data); else: endif; } ?> ******************************************************************** and this is the coding to fetch the data from the database : <? # this function is for listing data in table function client_group($ID='',$client_group='', $client_group1) //,$opt_template_type=''<br> { $ret =''; $array = array('group'=>'group','direct'=>'direct'); if(array_search($client_group ,$array)=='group') { $RS__query=sprintf("SELECT * FROM en_clients a LEFT JOIN en_group2clients b ON a.ID = b.client_id LEFT JOIN en_groups c ON c.ID = b.group_id WHERE a.ID=%s", GetSQLValueString($ID, "int")); $RS = mysql_query($RS__query, envoy_fetch_conn()) or die(mysql_error().'589'); $fetch = mysql_fetch_array($RS); $num = mysql_num_rows($RS); if($type=='group' && $num != '0'): $ret = '<a class="td_group" href="manage-'.$type.'s/edit/'.$client_group.'">'.client_empty($fetch['group_name']).'</a>'; else: $ret = ' '; endif; } return $ret; } ?> Link to comment https://forums.phpfreaks.com/topic/99937-please-help~/ Share on other sites More sharing options...
bubblebla Posted April 7, 2008 Author Share Posted April 7, 2008 all data from table en_clients is being displayed.. ex : client_login and client_password the list ain't displaying the client's group_name. but, if i replace <? echo $group_name; ?> with <? echo $client_group; ?> the table will list out the group_id that is belong to each client... unfortunately what i want to display is the group_name. ??? ??? ??? ??? ??? Link to comment https://forums.phpfreaks.com/topic/99937-please-help~/#findComment-511009 Share on other sites More sharing options...
Cep Posted April 7, 2008 Share Posted April 7, 2008 This is because you have told your code to assign the table field group_id to the variable $client_group. <?php $client_group = mysql_result($data, $i, 'group_id'); ?> Change this to the appropriate value in your database and you will get the group name as desired. Link to comment https://forums.phpfreaks.com/topic/99937-please-help~/#findComment-511016 Share on other sites More sharing options...
bubblebla Posted April 7, 2008 Author Share Posted April 7, 2008 This is because you have told your code to assign the table field group_id to the variable $client_group. <?php $client_group = mysql_result($data, $i, 'group_id'); ?> Change this to the appropriate value in your database and you will get the group name as desired. i did change it to $data, $i, 'group_name' but it still doesn't work... Link to comment https://forums.phpfreaks.com/topic/99937-please-help~/#findComment-511033 Share on other sites More sharing options...
Cep Posted April 7, 2008 Share Posted April 7, 2008 I know this sounds obvious but have you checked your database for the correct field name? Link to comment https://forums.phpfreaks.com/topic/99937-please-help~/#findComment-511035 Share on other sites More sharing options...
bubblebla Posted April 8, 2008 Author Share Posted April 8, 2008 I know this sounds obvious but have you checked your database for the correct field name? yes i did... in en_clients table i have ID (for client's id [key]) & group_id and other fields related to client's information. en_group2clients is holding the group_id, client_id. in en_groups i have ID (for group's id [key]), group_name and other fields. i need to fetch all data from en_clients and group_name from en_groups and the en_group2clients as the intermediate table to join both en_clients and en_groups. :-X ??? :-X ??? Link to comment https://forums.phpfreaks.com/topic/99937-please-help~/#findComment-511689 Share on other sites More sharing options...
bubblebla Posted April 8, 2008 Author Share Posted April 8, 2008 for($i = 0; $i < mysql_num_rows($data); $i++) { $client_id = mysql_result($data, $i, 'ID'); $client_login = mysql_result($data, $i, 'client_login'); $client_password = mysql_result($data, $i, 'client_password'); $client_group = mysql_result($data, $i, 'group_id'); $group_id = client_group ($client_id, $client_group, 'group_name'); $group_name = client_group ($client_id, $client_group, $group_id, 'group_name' ); i think the problem occur at this part... but i'm not sure how to fix it Link to comment https://forums.phpfreaks.com/topic/99937-please-help~/#findComment-511712 Share on other sites More sharing options...
bubblebla Posted April 9, 2008 Author Share Posted April 9, 2008 Link to comment https://forums.phpfreaks.com/topic/99937-please-help~/#findComment-512573 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.