Jump to content

show certain rows in mysql depending on logged in user


indexia

Recommended Posts

Hello i have the following code and i want to show only loged in user inputed form. The current code shows inputed form from all users.

Also each user in my db has an unique id called user_id and each contact added by users has and id called contact_id and contact_user that links to a user_id Thank you

 

<?php require_once('includes/config.php');
include('includes/sc-includes.php');
$pagetitle = 'Lista Soferi';

//SORTING
$sorder = '';
$name = "name_up";
if (isset($_GET['name_up'])) {
$sorder = "ORDER BY contact_last ASC";
$name = "name_down";
} elseif (isset($_GET['name_down'])) {
$sorder = "ORDER BY contact_last DESC";
}

$email = "email_up";
if (isset($_GET['email_up'])) {
$sorder = "ORDER BY contact_email ASC";
$email = "email_down";
} elseif (isset($_GET['email_down'])) {
$sorder = "ORDER BY contact_email DESC";
}

$phone = "phone_up";
if (isset($_GET['phone_up'])) {
$sorder = "ORDER BY contact_phone ASC";
$phone = "phone_down";
} elseif (isset($_GET['email_phone'])) {
$sorder = "ORDER BY contact_phone DESC";
}
//END SORTING

//PAGINATION
$limit = "10";
$epp = 10;  //entries per page

record_set('results',"SELECT contact_id FROM contacts");

$entries_per_page = $epp;

$page_number = empty($_GET['page']) ? 1 : $_GET['page']; //current page

$total_pages = ceil($totalRows_results / $entries_per_page); 
$offset = ($page_number - 1) * $entries_per_page; 

$prev = $page_number -1;
$next = $page_number + 1;

$limit = "LIMIT $offset, $entries_per_page";
//

//get contacts
record_set('contactlist',"SELECT * FROM contacts $sorder $limit");



?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo $pagetitle; ?></title>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
// Popup window code
function newPopup(url) {
popupWindow = window.open(
	url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>
<link href="includes/simplecustomer.css" rel="stylesheet" type="text/css" />
<script type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_setTextOfTextfield(objName,x,newText) { //v3.0
  var obj = MM_findObj(objName); if (obj) obj.value = newText;
}

//-->
</script type="text/JavaScript">
<script language="javascript" src="modal.popup.js"></script>
<script language="javascript">
$(document).ready(function() {

	//Change these values to style your modal popup
	var align = 'center';										//Valid values; left, right, center
	var top = 100; 												//Use an integer (in pixels)
	var padding = 10;											//Use an integer (in pixels)
	var backgroundColor = '#FFFFFF'; 							//Use any hex code
	var borderColor = '#000000'; 								//Use any hex code
	var borderWeight = 4; 										//Use an integer (in pixels)
	var borderRadius = 5; 										//Use an integer (in pixels)
	var fadeOutTime = 300; 										//Use any integer, 0 = no fade
	var disableColor = '#666666'; 								//Use any hex code
	var disableOpacity = 40; 									//Valid range 0-100
	var loadingImage = 'loading.gif';	//Use relative path from this page

        $(".modal").click(function() {
		var id = $(this).attr("data-usrid");

		if(!id) return;
		var source = 'contact-details.php?id='+id;	//Refer to any page on your server, external pages are not valid
		var width = 500; 					//Use an integer (in pixels)
            
		modalPopup(align, top, width, padding, disableColor, disableOpacity, backgroundColor, borderColor, borderWeight, borderRadius, fadeOutTime, source, loadingImage);

        });	

        

	//This method hides the popup when the escape key is pressed
	$(document).keyup(function(e) {

		if (e.keyCode == 27) {
			closePopup(fadeOutTime);
		}

	});

    });
</script>
<script>
$(function() {  

  $("#submit-search").click(function() {  
  $("#tester").hide(500);
  $.ajax({
	  url: "getSearchResults.php",
	  type: "GET",
	  data: {s : $("#s").val()},		  
	  success: function(data) {		
		$("#result").text(data);
		$("#result").html(data); 
		$("#result").show(2000);


	  }
	});
   });  
}); 
</script>
<script>
$(document).ready(function() {
            $('#back').click(function() {
                location.reload();
            });
        });
</script>
</head>

<body>
<?php include('includes/header.php'); ?>
  
  <div class="searchbar">
  <form id="form3" name="form3" method="POST" action="<?php $_SERVER["PHP_SELF"] ?>" enctype="multipart/form-data">
  <input name="s" type="text" id="s" onfocus="MM_setTextOfTextfield('s','','')" value="Nume, Prenume, Telefon sau CNP" size="40" />
  <input type="button" name="Submit_search" value="Cauta" id="submit-search" />
  </form>
  </div>
  </br><br/><br/><br/><br/>
  <div class="container">
  <div class="leftcolumn">
    <h2>Lista Soferi</h2>

<?php if (!$totalRows_contactlist) { ?>
<br />
No contacts have been added yet.
<br />
<br />
<strong><a href="contact.php">Add</a> or <a href="import.php">Import</a> Contacts </strong><br />
<br />
<?php } ?>
<div id ="test" style="display:none">


</div>
<?php 
$s=$_GET["s"];

mysql_select_db("cazier");
$sql="select * from contacts";

$contactsArray = array();
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
$contactsArray[] = $row;
}


  foreach($contactsArray as &$contact){
$contact['notes']=array();
//$sql2="select user_firma,user_name from users where user_id='".$contact['contact_id']."'";

$result2 = mysql_query("select notes.note_text AS 'note_text', users.user_nume AS 'user_nume', users.user_email AS 'user_email', users.user_telefon AS 'user_telefon', users.user_firma AS 'user_firma' from notes, users where notes.note_contact='".$contact['contact_id']."' AND users.user_id=notes.note_user");

while ($row2 = mysql_fetch_assoc($result2)){
$contact['notes'][] = $row2; 
} 
mysql_free_result($result2);
}


$test="<a href=''>Adauga detalii sofer</a>";

$tableHtml = "<table border ='1' bgcolor='#ffffdd' id='tester' width='900' border='0' cellspacing='0' cellpadding='0'><tr>
<th  align=\"center\" colspan='3'>Nume sofer</th>
<th align=\"center\" colspan='3'>CNP&nbsp</th>
<th align=\"center\" colspan='3'>Telefon sofer</th>
<th align=\"center\" colspan='3'>Detalii sofer</th>
</tr>";

for ($i=0;$i<count($contactsArray);$i++)	{

$tableHtml .= "<tr>
<td width=\"10%\" align=\"center\" colspan='3'>".$contactsArray[$i]['contact_first']." ".$contactsArray[$i]['contact_last']."  </td>
<td width=\"10%\" align=\"center\" colspan='3'>".$contactsArray[$i]['contact_title']."  </td>
<td width=\"10%\" align=\"center\" colspan='3'>".$contactsArray[$i]['contact_phone']."  </td>
<td width=\"70%\" colspan='3'>  ";

$notesString = "<ul><table border='1' width='550' ><tr>";
foreach ($contactsArray[$i]['notes'] as $note){
$notesString .= "<tr><td BGCOLOR=\"#DDDDDD\"><center>".$note['user_firma']."</center>"; 
$notesString .= "<center>".$note['user_nume']."</center>"; 
$notesString .= "<center>".$note['user_email']."</center>"; 
$notesString .= "<center>".$note['user_telefon']."</center>"; 
$notesString .= "<center><font color='#0404B4'> Note si comentarii : </font></center>";
$notesString .= "<center>".$note['note_text']."</center></td></tr>"; 
}
$notesString .= "</tr></table></ul>";

$tableHtml .= $notesString ;
$tableHtml .= "<center><a href='#' data-usrid='".$contactsArray[$i]['contact_id']."' class='modal'>Adauga detalii</a> </center></td></tr>";


}

$tableHtml .= "</table>" ;
echo $tableHtml;




?>

<div id="result"  >

</div>




   <div>
  <?php //include('includes/right-column.php'); ?>
  <br clear="all" />
</div>
<?php include('includes/footer.php'); ?>

</body>
</html>

Link to comment
Share on other sites

<?php 
$s=$_GET["s"];

mysql_select_db("cazier");
$sql="select * from contacts";

$contactsArray = array();
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
$contactsArray[] = $row;
}


  foreach($contactsArray as &$contact){
$contact['notes']=array();

$result2 = mysql_query("select notes.note_text AS 'note_text', users.user_nume AS 'user_nume', users.user_email AS 'user_email', users.user_telefon AS 'user_telefon', users.user_firma AS 'user_firma' from notes, users where notes.note_contact='".$contact['contact_id']."' AND users.user_id=notes.note_user");

while ($row2 = mysql_fetch_assoc($result2)){
$contact['notes'][] = $row2; 
} 
mysql_free_result($result2);
}


$test="<a href=''>Adauga detalii sofer</a>";

$tableHtml = "<table border ='1' bgcolor='#ffffdd' id='tester' width='900' border='0' cellspacing='0' cellpadding='0'><tr>
<th  align=\"center\" colspan='3'>Nume sofer</th>
<th align=\"center\" colspan='3'>CNP&nbsp</th>
<th align=\"center\" colspan='3'>Telefon sofer</th>
<th align=\"center\" colspan='3'>Detalii sofer</th>
</tr>";

for ($i=0;$i<count($contactsArray);$i++)	{

$tableHtml .= "<tr>
<td width=\"10%\" align=\"center\" colspan='3'>".$contactsArray[$i]['contact_first']." ".$contactsArray[$i]['contact_last']."  </td>
<td width=\"10%\" align=\"center\" colspan='3'>".$contactsArray[$i]['contact_title']."  </td>
<td width=\"10%\" align=\"center\" colspan='3'>".$contactsArray[$i]['contact_phone']."  </td>
<td width=\"70%\" colspan='3'>  ";

$notesString = "<ul><table border='1' width='550' ><tr>";
foreach ($contactsArray[$i]['notes'] as $note){
$notesString .= "<tr><td BGCOLOR=\"#DDDDDD\"><center>".$note['user_firma']."</center>"; 
$notesString .= "<center>".$note['user_nume']."</center>"; 
$notesString .= "<center>".$note['user_email']."</center>"; 
$notesString .= "<center>".$note['user_telefon']."</center>"; 
$notesString .= "<center><font color='#0404B4'> Note si comentarii : </font></center>";
$notesString .= "<center>".$note['note_text']."</center></td></tr>"; 
}
$notesString .= "</tr></table></ul>";

$tableHtml .= $notesString ;
$tableHtml .= "<center><a href='#' data-usrid='".$contactsArray[$i]['contact_id']."' class='modal'>Adauga detalii</a> </center></td></tr>";


}

$tableHtml .= "</table>" ;
echo $tableHtml;




?>

 

This how my db is structured

CjL6

 

This is the contacts table

CjKT

 

This is the users table

CjLv

 

A user_id can be connected with contact_user and contact_id to show from a certain user what content they have submited

 

Hope i was clear enough

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.