I have two tables, “customers” and “users”.
In the customers table, I have a column titled “name”. This has all customer names.
In my users table, I have a column titled “managing”. This has certain customer names.
I am trying to display content if “managing” CONTAINS ANY customer from “name”.
Here is an example…
“name” contains customers “applebees”, “johnny carinos”, and “pizza hut”.
User rick is “managing” “applebees” and “pizza hut”. In his row/the column, it looks like “applebees,pizza hut” (i am using the implode function which is why there is a ,”)
So, on my customers page, I want rick to see applebees and pizza hut. I do NOT want to him to see johnny carinos, since he isn’t managing it.
How can I do this? I’ve tried preg match & strpos but failed miserably. (I’m still rather new to php). This would be much easier of it was a single value, so I can just set value = value. Unfortunately, having multiple values for “managing” really messes me up!
Hope this made sense. Thanks for any help!
Here’s what I have now (yes, i know, it’s terribly wrong, probably.)
<?php
$sql = "SELECT * FROM customers";
$result = mysql_query($sql);
$thecust = $_SESSION['user']['managing'];
$thecustomers = htmlentities($row['name']);
$check = strprk(wing, $thecust);
if ($check) {
while ($row = mysql_fetch_array($result)) {
?>
<tr>
<td><?php echo "<a href='customer.php?id=" . $row['id'] . "'>" . $row['name'] . "</a>"?></td>
<td><?php echo htmlentities($row['contact_name'], ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo htmlentities($row['contact_number'], ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo htmlentities($row['contact_email'], ENT_QUOTES, 'UTF-8'); ?></td>
</tr>
<? } ?>
The answer lies in your database schema and the way you query it. You didn’t really get into your DB table structure but I would propose you use something like this
Note I have three tables here. This allows you to relate any number of users to any number of customers. NOw to get teh information you are looking for, let’s assume you know the
user_idof the user viewing the customers page. You query might look likeThis will give you customer information for those customers related to the the user.
You also should not be using the
mysql_*functions are they are deprecated (note the big red warning in PHP.net documentation). perhaps use mysqli_* functions.