Jump to content

Recommended Posts

I want to add unique information to a page on my site depending on the user id number, so i thought of doing this;

<?php
if ( is_user_logged_in() ) 
{
if ( $user_id = 2 ) 
{
// xxxxxxxxxxxxxxx
} 
elseif ( $user_id = 3 ) 
{
// xxxxxxxxxxxxxxx
} 
} else {
  // blank
}
?>

 

// xxxxxxxxxxxxxxx

would be the unique information i want to show.

 

After a while this script would become huge if i had to type all the info in, so is there anyway to show data from an external script. Say i had a script somewhere called 'user_1.php for the person logged in with the user_id of 1, 'user_2.php for the person logged in with the user_id of 2 and so on...

 

In this script (user_1.php) i had the information i want displayed which would be something like;

Current order(s)
[link to order]

Previous order(s)
[link to order]

 

Hope you understand what im trying to do, really appreciate any help as soon as you can.

Thank you.

 

Link to comment
https://forums.phpfreaks.com/topic/242577-user_id-show-unique-information/
Share on other sites

It looks like your trying to do order management / invoicing??? If so, why are you manually creating files for each one? This would be better handled in a database and with one php script importing the information into a template. But i'm only guessing. What is the end goal of what you are trying to make here?

I'm trying to create a profile page, i have the users able to register, login etc.. But they are currently all redirected to the same 'myaccount' page. I want there page to be unique and have information relevant to them, such as current orders and previous orders.

 

Im struggling to grasp how to do this though as my coding skills are extremely limited as you can probably tell. If you have a better way to do this please tell me, im all ears.

 

Also thank you requinix, but i now need to grab the current logged in users id, how would i go about this?

If you follow the route you are on now, you will be hard coding everything. This will make a headache for you later.

 

You need to make a page that dynamically outputs order information.

 

For example:

 

$sql="SELECT ID, ORDERNUM, DATE FROM orderTable WHERE USERID = '{$_SESSION['user_id']}'";
if ($query=@mysql_query($sql)) {
   if (mysql_num_rows($query) > 0) {
      while ($req=mysql_fetch_array($query)) {
          ?>
          <div class="orderInfo">
          <h1><?php echo $req['ORDERNUM'];?></h1>
          <?php echo $req['DATE'];?>
          </div>
          <?php
      }
   }
   else {
        echo "No orders found.";
    }
}
else {
echo "Query failed ".mysql_error();
}

Thank you very much Sir! That was very helpful.

 

Now forgive me if this sounds stupid, My preivous orders wasn't being stored in sql database, so i just added a new table with 'id', 'orderNum' and 'orderDate'. For the 'id' field im typing in the customers 'user_id'. This seems to work as the order number and date also being displayed correctly for the right user, but i cannot add another order because im already using the user_id.

 

Is there a way to display more data, in this case older or multiple orders?

 

Thanks for your time.

ID should be a unique ID for the table. It should not be referencing the userid. You need to make an additional field for the userid. So your mysql table might look like this:

 

id int(11) (unique id, auto increment)

user_id int(11)

orderNum int(30)

orderDate date

Perfect! All i need now is a way to add these values to the database when a user sends an order through, but i can see this be quite complicated because the order number is generated by using

$order = date ("dmyHis\n");

 

then added to message body, its not saved anywhere. Don't suppose you have any ideas on how i would go about grabbing this and saving it in my order table along with the date?

 

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.