Jump to content

how to load correct php pages for specific users


Go to solution Solved by cainam29,

Recommended Posts

how can i load a specific pages for specific users, what i have in mind is to create multiple php pages for each user, lets say,

 

php pages A, B, C, D, E, F, G

 

then i would create pages for user 1 - 1A, 1B, 1C, 1D, 1E, 1F, 1G

then for 2nd user - 2A, 2B, 2C, 2D, 2E, 2F, 2G

so on and so forth for the other users...

 

then i would just edit the header to land the user to their own php pages, is this the correct way to redirect a user to their own page or there is a much better way?

that is what i have in mind right now, because each php page that i have would have this section wherein they will not have to input their name, because it already has the value, im trying to read thru forums on how to use dynamic website but nothing seems to fit to what i intend. please help in at least showing me the right direction to achieve this...

<tr>
<td style="font-size:12px"><strong>iD, Name:</strong></td>
<td><input type="text" name="iD" id="iD" value="USER1" readonly="readonly" /></td>
</tr>
Edited by cainam29

Do you think every time you make a post on this forum a new php page is created for it? No, your data is stored in a database and a single (actually a few - but you get the idea) php page is used to display it.

 

So... all you do is store all your data that will change per user in a database. You then create pages that pull this data from the database to display it.

 

This is what php is all about. Not dynamically generating more and more code.

im kinda confused here, how can i make such php pages dynamic, now what if i have this code which calls another php page, below is my php page that calls

<script type="text/javascript">

 $(document).ready(function(){
 $("#RetrieveList").on('click',function() {
var xid = $('#XiD').val();
var date = $('#Date').val();
$.post('retrieve_ticket.php',{xid:xid, date:date}, function(data){
$("#results").html(data);
});
return false;
});
});
</script>

<form id="form2" name="form2" method="post" action="">
    
      <table width="741" border="0" align="center">
        <tr>
          <th colspan="9" align="center" style="font-size:14px" scope="col">Xid, Name:<span>
            <select name="XiD" id="XiD">
              <option value="USER1">USER1</option>
              <option value="USER2">USER2</option>
              <option value="USER3">USER3</option>
              <option value="USER4">USER4</option>
              <option value="USER5">USER5</option>
              <option value="USER6">USER6</option>
              <option value="" selected="selected">Please Select...</option>
            </select>
          </span><span style="font-size:14px">
<label for="date">Date:</label><input type="text" name="Date" id="Date" size="8"/>
<input name="action" type="button" id="RetrieveList" value="Retrieve List" />
<input name="Clear" type="reset" id="Clear" value="Clear" onClick="window.location.reload()" />
 <p></p>
 <p></p>
 <p></p>
 <p></p>
   <label for="Clear"></label>
   <div align="center"></div></th>
    </tr>
</table>
</form>

and here is the page being called,

<html>
<head>
</head>
<body>
<script>
jQuery(document).ready(function () {
  jQuery("input[name=checkall]").click(function () {
    jQuery('input[name=checkall]').prop('checked', this.checked);
    jQuery('input[name=checkbox]').prop('checked', this.checked);
  });

  // if all checkbox are selected, check the selectall checkbox
  // and viceversa
  jQuery("input[name=checkbox]").click(function(){

    if(jQuery("input[name=checkbox]").length == jQuery("input[name=checkbox]:checked").length) {
        jQuery("input[name=checkall]").prop("checked", true);
    } else {
        jQuery("input[name=checkall]").prop("checked", false);
    }
  });
});
</script>

<?php
require 'include/DB_Open.php';

$xid = $_POST['xid'];
$date = $_POST['date'];

$sql="SELECT ars_no, phone_number, category_1, category_2, status, create_date, trouble_type_priority, ban_type
FROM tbl_main
WHERE employee_id_name = '" . $xid . "' AND resolved_date = '" . $date . "'
ORDER BY category_1, category_2, status";
$myData = mysql_query($sql);

//to count if there are any results
$numrow = mysql_num_rows($myData);

if($numrow == 0)
{
echo "No results found.";
}
else
{
echo "Ticket Count: $numrow";
}
{

echo "<table width='auto' cellpadding='1px' cellspacing='0px' border=1 align='center'>
<tr>
<th align='center'><strong>Remedy Ticket No.</strong></th>
<th align='center'><strong>Phone/Incident No.</strong></th>
<th align='center'><strong>Category 2</strong></th>
<th align='center'><strong>Category 3</strong></th>
<th align='center'><strong>Status</strong></th>
<th align='center'><strong>Create Date</strong></th>
<th align='center'><strong>Severity</strong></th>
<th align='center'><strong>Ban Type</strong></th>
<!--<th align='center'><strong>Date Submitted</strong></th>-->
</tr>"; 

while($info = mysql_fetch_array($myData)) 
{
echo "<form action='retrieve_ticket.php' method='post'>";

echo"<tr>"; 
echo  "<td align='center'>" . $info['ars_no'] . "<input type=hidden name=ars_no value=" . $info['ars_no'] . " </td>";
echo  "<td align='center'>" . $info['phone_number'] . "<input type=hidden name=phone_number value=" . $info['phone_number'] . " size='11' maxlength='11' /> </td>"; 
echo  "<td align='center'>" . $info['category_1'] . "<input type=hidden name=category_1 value=" . $info['category_1'] . "' /> </td>"; 
echo  "<td align='center'>" . $info['category_2'] . "<input type=hidden name=category_2 value=" . $info['category_2'] . "' /> </td>";
echo  "<td align='center'>" . $info['status'] . "<input type=hidden name=status value=" . $info['status'] . "' /> </td>"; 
echo  "<td align='center'>" . $info['create_date'] . "<input type=hidden name=create_date value=" . $info['create_date'] . "' /> </td>";
echo  "<td align='center'>" . $info['trouble_type_priority'] . "<input type=hidden name=trouble_type_priority value=" . $info['trouble_type_priority'] . " size='1' maxlength='1' /> </td>"; 
echo  "<td align='center'>" . $info['ban_type'] . "<input type=hidden name=ban_type value=" . $info['ban_type'] . " size='1' maxlength='1' /> </td>";
echo "</tr>"; 
echo "</form>";
}
}
echo "</table>"; 

include 'include/DB_Close.php';
?>
</body>
</html>
Edited by cainam29

In your previous posting you mentioned that you didn't have SQL.  How are you going to maintain the data necessary to create a dynamic website such as trq is suggesting?  It's tougher to do with just a straight text file or something to read as a reference.  And surely you will want to branch out and expand on this simple approach after awhile.

 

In general you would use a db  to store the individual data you want to put into these "separate" pages you have in mind.  Then your select box gives you the user as you already know how to do.  But then you would take the selection and read your db and put that data into your standard page template.  Basically just one or two scripts.

So you do have access to an sql database.  That means you can create whatever tables you need to store data in.  Then you can use those tables to get the data you need to put on your "dynamic pages" all using one script.

 

You make a script that displays an html page containing several php vars around the page.  Then you use php to take the selected user id and look up the data in your sql db and place that data into those php vars.  That's a dynamic page, all generated by one script

YOu already know how to write the html.  Just bury php vars in where you want the dynamic data to show up.  I do this by using a function that simply displays the html page.  I use global vars to pass the data into it, use heredocs statement to make it easy to setup and to read later on and then just call the function after my php code has done it's thing.

 

<?

(startup php stuff)

if (no submit button)

{

   $step =1;

   DisplayPage($step);

   exit();

}

if (submit == "get user")

{

   (retrieve the user id input by the user on the first page display)

   (get the user info from the db)

   (assign data to vars)

   $phoneno= $qrslts[0]['phone_number'];

   $createdt = $qrslts[0]['create_date'];

   $step = 2;

   DisplayPage(2);

   exit();

}

if (submit == "try again")

{

   $step = 1;

   DisplayPage($step);

   exit();

}

function DisplayPage($step)

{

   global  $phoneno,$createdt,$morevars......;

  ( the rest of this function is your html layout with some php stuff inserted)

  $code =<<<heredocs

   <doctype html>.....

   <meta tag>

   <meta tag>

   <head>

   (js)

   (css)

   </head>

   <body>

   <h1>asdfasdf</h1>

   <h2>asdfasdfasdf</h2>

   <p  blah blah blah</p>

heredocs;

    echo $code;

   // if step is 1 just show the user the input box for an id

   if ($step==1)

   {

      $code=<<<heredocs

      <form>

     <input type='text' name='uid' value='$uid'>

     <input type='submit' name='btn' value='Get User'>

     </form>

heredocs;

      echo $code;

    }

   if ($step ==2)

   {

    $code=<<<heredocs

    <p> For user id $uid the following was found on file:</p>

    <table border=1>

    <tr><th>Phone #</th><th>Create Date</th></tr>

    <tr><td>$phoneno</td><td>$created</td></tr>

    </table>

    <br><br>

    <form>

    <input type='submit' name='btn' value='Try Again'>

    </form>

heredocs;

    echo $code;

   } 

  echo "</body></html>";

  return

}

 

Note the php vars embedded in ordinary html code, which are passed into the function using the global statement.

 

Also note the use of the heredocs syntax to make it easier to combine html and php code in your display logic

 

I user this model for *every* one of my pages.  Serves me well.  Created a template in my IDE to help me begin every page with all the usual stuff I need.

hi there i think i figured out what i really want now, i think i may just need a client side script to accomplish what i want, so instead of using the SELECT, what i want is to replace it with a TEXT FIELD with the name of the user who logs in, so that when he retrieves data from the DB, he would just have to select the date and user's name is already pre-defined, in that way, datas that will be gerated by the SQL script is just for the user and does not have option to select or view other users records, i think i need a java script code here, can you show me a sample code as well?

 

here is the SELECT which should be replaced by TEXT FIELD with pre-defined USERS value already

 

<select name="XiD" id="XiD">
<option value="USER1">USER1</option>
<option value="USER2">USER2</option>
<option value="USER3">USER3</option>
<option value="USER4">USER4</option>
<option value="USER5">USER5</option>
<option value="USER6">USER6</option>
<option value="" selected="selected">Please Select...</option>
</select>

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.