473,394 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

view singular, not multiple records

17
I want to change the following piece of code to only show the actual user who is logged in, and not let them see other peoples information.

What can i do. Im totally baffled.

Could the answer please include line numbers.

thank y ou so much for you help

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3. //connect to database
  4. $mysqli = mysqli_connect("localhost", "geothermal", "password", "geothermal");
  5.  
  6. if (!$_POST)  {
  7.     //haven't seen the selection form, so show it
  8.     $display_block = "<h1>Select an Entry</h1>";
  9.  
  10.     //get parts of records
  11.     $get_list_sql = "SELECT master_id,
  12.                      CONCAT_WS(', ', l_name, f_name) AS display_name
  13.                      FROM tbl_master_name ORDER BY l_name, f_name";
  14.     $get_list_res = mysqli_query($mysqli, $get_list_sql) or die(mysqli_error($mysqli));
  15.  
  16.     if (mysqli_num_rows($get_list_res) < 1) {
  17.         //no records
  18.         $display_block .= "<p><em>Sorry, no records to select!</em></p>";
  19.  
  20.     } else {
  21.         //has records, so get results and print in a form
  22.         $display_block .= "
  23.         <form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">
  24.         <p><strong>Select a Record to View:</strong><br/>
  25.         <select name=\"sel_id\">
  26.         <option value=\"\">-- Select One --</option>";
  27.  
  28.         while ($recs = mysqli_fetch_array($get_list_res)) {
  29.             $id = $recs['master_id'];
  30.             $display_name = stripslashes($recs['display_name']);
  31.  
  32.             $display_block .= "<option value=\"".$id."\">".$display_name."</option>";
  33.         }
  34.  
  35.         $display_block .= "
  36.         </select>
  37.         <p><input type=\"submit\" name=\"submit\" value=\"View Selected Entry\"></p>
  38.         </form>";
  39.     }
  40.     //free result
  41.     mysqli_free_result($get_list_res);
  42.  
  43. } else if ($_POST) {
  44.     //check for required fields
  45.     if ($_POST["sel_id"] == "")  {
  46.         header("Location: selentry.php");
  47.         exit;
  48.     }
  49.  
  50.     //get master_info
  51.     $get_master_sql = "SELECT concat_ws(' ', f_name, l_name) as display_name
  52.                        FROM tbl_master_name WHERE master_id = '".$_POST["sel_id"]."'";
  53.     $get_master_res = mysqli_query($mysqli, $get_master_sql) or die(mysqli_error($mysqli));
  54.  
  55.     while ($name_info = mysqli_fetch_array($get_master_res)) {
  56.         $display_name = stripslashes($name_info['display_name']);
  57.     }
  58.  
  59.     $display_block = "<h1>Showing Record for ".$display_name."</h1>";
  60.  
  61.     //free result
  62.     mysqli_free_result($get_master_res);
  63.  
  64.     //get all addresses
  65.     $get_addresses_sql = "SELECT address1, address2, town, county, postcode, type
  66.                           FROM tbl_address WHERE master_id = '".$_POST["sel_id"]."'";
  67.     $get_addresses_res = mysqli_query($mysqli, $get_addresses_sql) or die(mysqli_error($mysqli));
  68.  
  69.      if (mysqli_num_rows($get_addresses_res) > 0) {
  70.  
  71.         $display_block .= "<p><strong>Addresses:</strong><br/>
  72.         <ul>";
  73.  
  74.         while ($add_info = mysqli_fetch_array($get_addresses_res)) {
  75.             $address1 = stripslashes($add_info['address1']);
  76.             $address2 = stripslashes($add_info['address2']);
  77.             $town = stripslashes($add_info['town']);
  78.             $county = stripslashes($add_info['county']);
  79.             $postcode = stripslashes($add_info['postcode']);
  80.             $address_type = $add_info['type'];
  81.  
  82.             $display_block .= "<li>$address1 $address2 $town $county $postcode ($address_type)</li>";
  83.         }
  84.  
  85.         $display_block .= "</ul>";
  86.     }
  87.  
  88.     //free result
  89.     mysqli_free_result($get_addresses_res);
  90.  
  91.     //get all tel
  92.     $get_tel_sql = "SELECT tel_number, type FROM tbl_telephone
  93.                     WHERE master_id = '".$_POST["sel_id"]."'";
  94.     $get_tel_res = mysqli_query($mysqli, $get_tel_sql) or die(mysqli_error($mysqli));
  95.  
  96.     if (mysqli_num_rows($get_tel_res) > 0) {
  97.  
  98.         $display_block .= "<p><strong>Telephone:</strong><br/>
  99.         <ul>";
  100.  
  101.         while ($tel_info = mysqli_fetch_array($get_tel_res)) {
  102.             $tel_number = stripslashes($tel_info['tel_number']);
  103.             $tel_type = $tel_info['type'];
  104.  
  105.             $display_block .= "<li>$tel_number ($tel_type)</li>";
  106.         }
  107.  
  108.         $display_block .= "</ul>";
  109.     }
  110.  
  111.     //free result
  112.     mysqli_free_result($get_tel_res);
  113.  
  114.     //get all fax
  115.     $get_fax_sql = "SELECT fax_number, type FROM tbl_fax
  116.                     WHERE master_id = '".$_POST["sel_id"]."'";
  117.     $get_fax_res = mysqli_query($mysqli, $get_fax_sql) or die(mysqli_error($mysqli));
  118.  
  119.     if (mysqli_num_rows($get_fax_res) > 0) {
  120.  
  121.         $display_block .= "<p><strong>Fax:</strong><br/>
  122.         <ul>";
  123.  
  124.         while ($fax_info = mysqli_fetch_array($get_fax_res)) {
  125.             $fax_number =  stripslashes($fax_info['fax_number']);
  126.             $fax_type = $fax_info['type'];
  127.  
  128.             $display_block .= "<li>$fax_number ($fax_type)</li>";
  129.         }
  130.  
  131.         $display_block .= "</ul>";
  132.     }
  133.  
  134.     //free result
  135.     mysqli_free_result($get_fax_res);
  136.  
  137.     //get all email
  138.     $get_email_sql = "SELECT email, type FROM tbl_email
  139.                       WHERE master_id = '".$_POST["sel_id"]."'";
  140.     $get_email_res = mysqli_query($mysqli, $get_email_sql) or die(mysqli_error($mysqli));
  141.  
  142.      if (mysqli_num_rows($get_email_res) > 0) {
  143.  
  144.         $display_block .= "<p><strong>Email:</strong><br/>
  145.         <ul>";
  146.  
  147.         while ($email_info = mysqli_fetch_array($get_email_res)) {
  148.             $email = stripslashes($email_info['email']);
  149.             $email_type = $email_info['type'];
  150.  
  151.             $display_block .= "<li>$email ($email_type)</li>";
  152.         }
  153.  
  154.         $display_block .= "</ul>";
  155.     }
  156.  
  157.     //free result
  158.     mysqli_free_result($get_email_res);
  159.  
  160.     //get personal note
  161.     $get_notes_sql = "SELECT note FROM tbl_personal_notes
  162.                       WHERE master_id = '".$_POST["sel_id"]."'";
  163.     $get_notes_res = mysqli_query($mysqli, $get_notes_sql) or die(mysqli_error($mysqli));
  164.  
  165.     if (mysqli_num_rows($get_notes_res) == 1) {
  166.         while ($note_info = mysqli_fetch_array($get_notes_res)) {
  167.             $note = nl2br(stripslashes($note_info['note']));
  168.         }
  169.  
  170.         $display_block .= "<p><strong>Personal Notes:</strong><br/>$note</p>";
  171.     }
  172.  
  173.     //free result
  174.     mysqli_free_result($get_notes_res);
  175.  
  176.     $display_block .= "<br/>
  177.     <p align=\"center\"><a href=\"".$_SERVER["PHP_SELF"]."\">select another</a></p>";
  178. }
  179. //close connection to MySQL
  180. mysqli_close($mysqli);
  181. ?>
  182. <html>
  183. <head>
  184. <title>My Records</title>
  185. </head>
  186. <body>
  187. <?php echo $display_block; ?>
  188. </body>
  189. </html>
  190.  
Feb 12 '08 #1
1 1193
Markus
6,050 Expert 4TB
That's alot of code to look through, but if i understand you right you could just add the LIMIT to your sql query.

[php]
$_query = "SELECT * FROM `tbl_name` WHERE `something` = 'something' LIMIT 1";
[/php]
Feb 12 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Neil | last post by:
I previously posted re. this, but thought I'd try again with a summary of facts. I have an Access 2000 MDB with a SQL Server 7 back end. There is a view that is linked to the database via ODBC...
8
by: xixi | last post by:
hi, we are using db2 udb v8.1 on windows, i have a table contains over one million records, it has seperate own tablespace than others, with bufferpool size 250, i have created multiple views on...
4
by: | last post by:
I have an ACCESS db from a DEXA machine (bone scanner). The data is in seperate tables and I want to link them so that I can query and create one table with all the data I need from the seperate...
2
by: Steve - DND | last post by:
Just wondering if anyone out there has any code to convert a plural word to it's singular form and vice versa. Most of our database tables are named in a plural fashion. When we go to create...
2
by: Robert W. | last post by:
In my current work I noticed that I have several circumstances where I need to create little if/else constructs to handle the phrasing of a message. This typically involves a ternary situation like...
7
by: Bosconian | last post by:
This might seem like a trivial thing, but has anyone has come up with a better way of outputting a singular vs. plural string? For example: // default plural label $string = "appointments";...
1
by: lmawler | last post by:
Hi, I have a list of offices that I've put in a form in datasheet view (so all the records show at once). I want my users to be able to update the list, and then when they click a button, it...
8
by: Arno R | last post by:
Hi all. When I need to search for pictures, I always have too choose thumbnail-view manually. Is it possible to open the common dialog in thumbnail-view programmatically? Example ?? At the...
2
by: pipeme | last post by:
Hi I am not terribly proficient in access coding so please excuse my ignorance if this is easier than what I think it will be! I have a query which has 3 columns and varying amounts of records...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.