r0b3rt9 Posted November 3, 2010 Share Posted November 3, 2010 HI guys, i been stressing over this for some time. i have a table that pulls in data from a database, sadly 1 of the cells shows up as the ID number of the submited form not the value. How do i go about showing the Value in the table instead of the ref number? thanks rob Quote Link to comment https://forums.phpfreaks.com/topic/217650-ref-a-table-cell-phpmysql/ Share on other sites More sharing options...
inversesoft123 Posted November 3, 2010 Share Posted November 3, 2010 Reply with code. Quote Link to comment https://forums.phpfreaks.com/topic/217650-ref-a-table-cell-phpmysql/#findComment-1129867 Share on other sites More sharing options...
trq Posted November 3, 2010 Share Posted November 3, 2010 Were going to need code to understand exactly what your talking about. In tags please. Quote Link to comment https://forums.phpfreaks.com/topic/217650-ref-a-table-cell-phpmysql/#findComment-1129870 Share on other sites More sharing options...
r0b3rt9 Posted November 3, 2010 Author Share Posted November 3, 2010 <?php require_once('Connections/Database.php'); ?> <?php require_once('Connections/Database.php'); ?> <?php //initialize the session if (!isset($_SESSION)) { session_start(); } // ** Logout the current user. ** $logoutAction = $_SERVER['PHP_SELF']."?doLogout=true"; if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){ $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){ //to fully log out a visitor we need to clear the session varialbles $_SESSION['MM_Username'] = NULL; $_SESSION['MM_UserGroup'] = NULL; $_SESSION['PrevUrl'] = NULL; unset($_SESSION['MM_Username']); unset($_SESSION['MM_UserGroup']); unset($_SESSION['PrevUrl']); $logoutGoTo = "Index.php"; if ($logoutGoTo) { header("Location: $logoutGoTo"); exit; } } ?> <?php if (!isset($_SESSION)) { session_start(); } $MM_authorizedUsers = "User,Admin,SuperAdmin"; $MM_donotCheckaccess = "false"; // *** Restrict Access To Page: Grant or deny access to this page function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { // For security, start by assuming the visitor is NOT authorized. $isValid = False; // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. // Therefore, we know that a user is NOT logged in if that Session variable is blank. if (!empty($UserName)) { // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. // Parse the strings into arrays. $arrUsers = Explode(",", $strUsers); $arrGroups = Explode(",", $strGroups); if (in_array($UserName, $arrUsers)) { $isValid = true; } // Or, you may restrict access to only certain users based on their username. if (in_array($UserGroup, $arrGroups)) { $isValid = true; } if (($strUsers == "") && false) { $isValid = true; } } return $isValid; } $MM_restrictGoTo = "Index.php"; if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) { $MM_qsChar = "?"; $MM_referrer = $_SERVER['PHP_SELF']; if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&"; if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) $MM_referrer .= "?" . $QUERY_STRING; $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer); header("Location: ". $MM_restrictGoTo); exit; } ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $maxRows_user = 1; $pageNum_user = 0; if (isset($_GET['pageNum_user'])) { $pageNum_user = $_GET['pageNum_user']; } $startRow_user = $pageNum_user * $maxRows_user; mysql_select_db($database_Database, $Database); $query_user = "SELECT * FROM users"; $query_limit_user = sprintf("%s LIMIT %d, %d", $query_user, $startRow_user, $maxRows_user); $user = mysql_query($query_limit_user, $Database) or die(mysql_error()); $row_user = mysql_fetch_assoc($user); if (isset($_GET['totalRows_user'])) { $totalRows_user = $_GET['totalRows_user']; } else { $all_user = mysql_query($query_user); $totalRows_user = mysql_num_rows($all_user); } $totalPages_user = ceil($totalRows_user/$maxRows_user)-1; $maxRows_Record = 15; $pageNum_Record = 0; if (isset($_GET['pageNum_Record'])) { $pageNum_Record = $_GET['pageNum_Record']; } $startRow_Record = $pageNum_Record * $maxRows_Record; mysql_select_db($database_Database, $Database); $query_Record = "SELECT * FROM main ORDER BY `Date Booked` DESC"; $query_limit_Record = sprintf("%s LIMIT %d, %d", $query_Record, $startRow_Record, $maxRows_Record); $Record = mysql_query($query_limit_Record, $Database) or die(mysql_error()); $row_Record = mysql_fetch_assoc($Record); if (isset($_GET['totalRows_Record'])) { $totalRows_Record = $_GET['totalRows_Record']; } else { $all_Record = mysql_query($query_Record); $totalRows_Record = mysql_num_rows($all_Record); } $totalPages_Record = ceil($totalRows_Record/$maxRows_Record)-1; $colname_Recordloc = "-1"; if (isset($_GET['Location.Location ID'])) { $colname_Recordloc = (get_magic_quotes_gpc()) ? $_GET['Location.Location ID'] : addslashes($_GET['Location.Location ID']); } mysql_select_db($database_Database, $Database); $query_Recordloc = sprintf("SELECT Location FROM main WHERE Location = %s", GetSQLValueString($colname_Recordloc, "text")); $Recordloc = mysql_query($query_Recordloc, $Database) or die(mysql_error()); $row_Recordloc = mysql_fetch_assoc($Recordloc); $totalRows_Recordloc = mysql_num_rows($Recordloc); mysql_select_db($database_Database, $Database); $query_Location = "SELECT * FROM location"; $Location = mysql_query($query_Location, $Database) or die(mysql_error()); $row_Location = mysql_fetch_assoc($Location); $totalRows_Location = mysql_num_rows($Location); ?> <html> <head> <title>MKDons Maintenace Help Desk</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> .style2 { color: #FFFFFF; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; } .style3 {color: #FFFFFF; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; } </style> </head> <body bgcolor="#174775" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <table id="Table_01" align="center" width="900" height="600" border="0" cellpadding="0" cellspacing="0"> <tr> <td colspan="2" height="123"> <img src="images/1.gif" width="900" height="123" alt=""></td> </tr> <tr> <td width="189" align="center" valign="top" bgcolor="#02103b"> <img src="Images/Main Menu/mini-banner.png" width="197" height="54"> <a href="Home.php"><img src="Images/Main Menu/Home.png" width="188" height="42" border="0"></a> <a href="List.php"><img src="Images/Main Menu/List.png" width="188" height="42" border="0"></a><a href="New_record.php"><img src="Images/Main Menu/add_record.png" width="188" height="42" border="0"></a> <?php $accessLevels = array("Admin","SuperAdmin"); $validLevel = $_SESSION['MM_UserGroup']; if(array_search($validLevel, $accessLevels)>-1){ ?> <a href="#"><img src="Images/Main Menu/records.png" width="188" height="42" border="0"></a> <?php } ?> <a href="<?php echo $logoutAction ?>"><img src="Images/Main Menu/logout.png" width="188" height="42" border="0"></a> <br> <?php $accessLevels = array("Admin","SuperAdmin"); $validLevel = $_SESSION['MM_UserGroup']; if(array_search($validLevel, $accessLevels)>-1){ ?> <img src="Images/Main Menu/admin-panel.png" width="197" height="54"> <a href="#"></a> <a href="User_panel.php"><img src="Images/Main Menu/user_panel.png" width="188" height="42" border="0"></a> <a href="record_panel.php"><img src="Images/Main Menu/record_panel.png" width="188" height="42" border="0"></a> <?php } ?> </td> <td valign="top" width="711"> <br><br> <?php do { ?> <div> <table border="1"> <tr> <td width="50" class="style2"><strong>Job ID</strong></td> <td width="150" class="style3">Subject</td> <td width="100" class="style3">Location</td> <td width="150" class="style3">Date</td> <td></td> </tr> <tr> <td width="50" class="style2"><?php echo $row_Record['Main ID']; ?></td> <td width="150" class="style2"><?php echo $row_Record['Subject']; ?></td> <td width="100" class="style2"><?php echo $row_Record['Location']; ?></td> <td width="150" class="style2"><?php echo $row_Record['Date Booked']; ?></td> <?php $accessLevels = array("Admin","SuperAdmin"); $validLevel = $_SESSION['MM_UserGroup']; if(array_search($validLevel, $accessLevels)>-1){ ?><td><label><a href="edit_record.php?record=<?php echo $row_Record['Main ID']; ?>" class="style2">Edit</a></label></td><?php } ?> </tr> </table> <p></p> </div> <?php } while ($row_Record = mysql_fetch_assoc($Record)); ?></td> </tr> </table> </body> </html> <?php mysql_free_result($user); mysql_free_result($Record); mysql_free_result($Recordloc); mysql_free_result($Location); mysql_free_result($Records); ?> Quote Link to comment https://forums.phpfreaks.com/topic/217650-ref-a-table-cell-phpmysql/#findComment-1129873 Share on other sites More sharing options...
inversesoft123 Posted November 3, 2010 Share Posted November 3, 2010 sadly 1 of the cells shows up as the ID number of the submited form not the value. Please tell us name of the cell / field to get proper and fast solution. Quote Link to comment https://forums.phpfreaks.com/topic/217650-ref-a-table-cell-phpmysql/#findComment-1129874 Share on other sites More sharing options...
r0b3rt9 Posted November 3, 2010 Author Share Posted November 3, 2010 the cell is called Location all i want it to do is give me the value instead of the ID from a different table in the same database. Quote Link to comment https://forums.phpfreaks.com/topic/217650-ref-a-table-cell-phpmysql/#findComment-1129876 Share on other sites More sharing options...
inversesoft123 Posted November 3, 2010 Share Posted November 3, 2010 You are fetching records into different variable and using different variable to display results eg: $row_Record you must use $totalRows_Location for Location. Always consider JOINING of tables into a single query. this will save your cpu resources. http://dev.mysql.com/doc/refman/5.1/en/join.html Quote Link to comment https://forums.phpfreaks.com/topic/217650-ref-a-table-cell-phpmysql/#findComment-1129878 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.