help in loading customer details onto templates

Hi all,

I need to load client details such as address, telephone number and logos automatically into order/invoice templates etc. My previous system was to query the database and echo the results based upon who was logged in (which client)…

This was working until I introduced another query directly on the page i.e query database to pull order information.

Is there any advice on how to pull the information?

I currently have a page called ‘config_settings.php’ which is;-
[php]<?php
// query company details…
$company_query = "SELECT * FROM fms_tbl_company WHERE client_id=’{$_SESSION[‘client_id_of_user’]}’ ";
$result = mysqli_query($db, $company_query);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);

?>[/php]

So on my order page it would pull this file using “include ‘config_settings.php’;”

I just echoed the values using ‘$row[‘database_value’]’

Dan, there are many ways to handle user data. Every programmer has their own preferred way to do this.
In my experience, if there are a small amount of data needed, you can load that data into the $_SESSION[]
array when the user logs in. That data is gone once they close the browser or log out. This is not a good
way to handle it if there is a lot of data involved.

If there is only address, phone and logo names needed, that is easy to set up during the login process. You
just load that data into $_SESSION variables when the user logs in. Then, they are always there to be used
to display on orders or invoices, etc.

If you have a large number of different forms that require different data, then you need to think of how the
data is loaded to keep the speed of the system up to a good responsive level. Most likely this would mean
using your config_settings.php page in each of these to load the correct data for them. If the data changes
often, that is about the only way to get the current data. Using $_SESSION variables loaded upon user
login would not work well if the data can change during the user’s use of the site.

To recap these thoughts, it really depends on what the data is. Small amounts of user data that do not
change can be handled by setting them up when the user logs into the site and will be available to use
on any page in the system. Large amounts of data or if the data changes often must be reloaded as it is
needed on every page. The best place to start is to make a list of all your data needed and mark which
could change during the user’s access to your site. That would give you an idea how to handle it’s access.

Not sure if this helps, but, gives you some things to think about to get you started.

EDIT: Added… Note that “USER” data and “INVOICE” data are two different things. User’'s data seldom
changes and I usually use the $_SESSION array for those. Invoices and order info constantly change, such
as adding/removing items, shipping status and other things which makes this data needing refreshing at
each time it is used…

Hi Ernie,

This makes sense, I have around 10 column values - in your opinion is this too many to use in user sessions?

Well, 10 items are not many as long as they are stable data values. I mean, if it is the user’s name, address,
city, state, zip, phone, etc, these do not change unless they change their profile info. This is fine to use in the
$_SESSION variables. I have a site that uses about a dozen seldom-changing items including a user-level
number. Then, on various pages, the user-level number shows different displays and options if they have the
correct user level access.

I would say 10 is fine. It the user changes their profile, you need to reload these 10 values after they press
the update button on the profile page. ( In case they change their shipping address, etc. ) Not a big process.

I tend to only want bare details for session use. A user and or company id for instance. If you need the info, such as mailing, or phone number you query for it. That information is rarely needed for the actual system.

Yep, I agree with most of my sites I have worked on. It really depends on how often you use the data.

If you can save redundant queries, then use a few more values. A PHP query to load user info does not take
a lot of server resources, but to get the same value over and over is a waste. Depends on his data usage,
hence why I told him to think about that before deciding

Thanks for your input guys, I think the best route is to run a query as the user/s will have the option to edit their contact details so it would be a pain for them to log out and then back in again for the changes to take effect.

I currently have similar queries running and I think this is my issue…

My query for the company info etc is:-
[php]<?php
// connect to db
include ‘mysqli_connect.php’;

// query company details…
$company_query = "SELECT * FROM fms_tbl_company WHERE client_id=’{$_SESSION[‘client_id_of_user’]}’ ";
$result = mysqli_query($db, $company_query);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);

?>[/php]

And I would normally echo $row[‘address’];, $row[‘tel’]; etc

Most of my pages use the above query for additional lookups i.e projects, orders, suppliers so I looking for a way to have both queries but not clash

Well, Dan, that is easy… Just use different variables. You are not locked into $result or $row, they are just
variable names… Therefore, you can use it like this…

$query=“SELECT * FROM users WHERE id=1”;
$result = mysqli_query($db, $query);
$user_indo = mysqli_fetch_array($result);
$user_id = $user_info[“id”];
$query=“SELECT * FROM company WHERE client_id=” . $user_id;
$result = mysqli_query($db, $query);
$company_indo = mysqli_fetch_array($result);

Just off top of my head, not real code based on your code. Just to give you an idea how keep two querie’s
data in separate variables… $row is just a variable…

thanks Ernie, it worked a treat!

LOL, I just noticed, I mistyped INFO a couple times, not sure what INDO is… LOL

Glad you solved it… See you in the bitstream!

Sponsor our Newsletter | Privacy Policy | Terms of Service