demon917 Posted February 4, 2014 Share Posted February 4, 2014 I have 8 rows/columns. They are; Key (which will never repeat), Name, HireDate, Seniority, VacHrs, PTOhrs, username AND password. After a successful login, this is my code; <?php $dbhost = '***7.000webhost.com'; $dbuser = 'a3674631_***'; $dbpass = 'm***'; $conn = mysql_connect("mysql17.000webhost.com", "a36***31_***n9", "****08"); if(! $conn ) { die('Could not connect: ' . mysql_error()); } $sql = 'SELECT Name, HireDate, Seniority, VacHrs, PTOhrs FROM att'; mysql_select_db('a3674631_test'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not get data: ' . mysql_error()); } while($row = mysql_fetch_array($retval, MYSQL_NUM)) { echo "Name :{$row[0]} <br> ". "Hire Date : {$row[1]} <br> ". "Seniority : {$row[2]} <br> ". "Vacation Hours Remaining : {$row[3]} <br> ". "PTO Hours Remaining : {$row[4]} <br> ". "--------------------------------<br>"; } mysql_free_result($retval); echo "Fetched data successfully\n"; mysql_close($conn); ?> The problem I’m having is it’s putting everyone’s data, all on one page together for everyone to see. This is private information, and Person A should not be able to see the values for person B. My table has 6 records(currently). If user A has a login of 111791, on a successful login, I would like it to say; Name: First Last HireDate: 04/04/2012 Seniority: 1 (dates that are sorted by earliest to latest) VacHrs: 45 PTOhrs: 18 Key, username & password will never show. Can someone tell me what I’m doing wrong. I know that I’m a noob, so please skip all the “I need read this book….or that tutorial”. I know I do, I’m going to, but in the mean time, I need to get this taken care of. I thank you sincerely for any help. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted February 4, 2014 Share Posted February 4, 2014 the following is the part of the book you will eventually read about SELECT queries, with the needed part highlighted - SELECT[ALL | DISTINCT | DISTINCTROW ][HIGH_PRIORITY][sTRAIGHT_JOIN][sql_SMALL_RESULT] [sql_BIG_RESULT] [sql_BUFFER_RESULT][sql_CACHE | SQL_NO_CACHE] [sql_CALC_FOUND_ROWS]select_expr [, select_expr ...][FROM table_references[WHERE where_condition][GROUP BY {col_name | expr | position}[ASC | DESC], ... [WITH ROLLUP]][HAVING where_condition][ORDER BY {col_name | expr | position}[ASC | DESC], ...][LIMIT {[offset,] row_count | row_count OFFSET offset}][PROCEDURE procedure_name(argument_list)][iNTO OUTFILE 'file_name'[CHARACTER SET charset_name]export_options| INTO DUMPFILE 'file_name'| INTO var_name [, var_name]][FOR UPDATE | LOCK IN SHARE MODE]] a WHERE clause is used to pick which row(s) a query matches. also, if you expect a query to at most match one row, you should not loop over the result set, just fetch the one row. Quote Link to comment Share on other sites More sharing options...
SalientAnimal Posted February 5, 2014 Share Posted February 5, 2014 In your case your where clause would also have to point to a unique identifier. This could possibly be your username which you would store in your session data. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.