Note that there are some explanatory texts on larger screens.

plurals
  1. POList records where IDs match from two seperate tables
    primarykey
    data
    text
    <p>i have two tables in my database, one (table 1) which is for users which includes: ID, firstname, lastname, login and password. the other table (table2) has the data in it, which also has an ID field. i want to know how i only display the data in table 2, when the ID of table 2 = the ID of table 1.</p> <p>i think i need to add to the below parameter, but unsure of how to do it</p> <pre><code>$sql="SELECT * FROM Triage WHERE completed= 'no'"; $result=mysql_query($sql); </code></pre> <p>any clarification please let me know and thanks</p> <p>Page of code which list the data from table 2 <pre><code>require_once('auth.php'); $host="*"; // Host name $username="*"; // Mysql username $password="*"; // Mysql password $db_name="*"; // Database name $tbl_name="*"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM Triage WHERE completed= 'no'"; $result=mysql_query($sql); ?&gt; &lt;style type="text/css"&gt; body { background-color: #FFF; } &lt;/style&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;table width="1270" border="0" cellspacing="1" cellpadding="0"&gt; &lt;tr&gt; &lt;td width="1270"&gt;&lt;table width="1270" border="1" cellspacing="0" cellpadding="3"&gt; &lt;tr&gt; &lt;td colspan="400"&gt;&lt;p align="center"&gt;&lt;strong&gt;List of patients for triage&lt;/strong&gt;&lt;/p&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="70" align="center"&gt;&lt;strong&gt;Reference&lt;/strong&gt;&lt;/td&gt; &lt;td width="120" align="center"&gt;&lt;strong&gt;Forename&lt;/strong&gt;&lt;/td&gt; &lt;td width="120" align="center"&gt;&lt;strong&gt;Surname&lt;/strong&gt;&lt;/td&gt; &lt;td width="100" align="center"&gt;&lt;strong&gt;DOB&lt;/strong&gt;&lt;/td&gt; &lt;td width="120" align="center"&gt;&lt;strong&gt;Mobile Number&lt;/strong&gt;&lt;/td&gt; &lt;td width="120" align="center"&gt;&lt;strong&gt;Home Number&lt;/strong&gt;&lt;/td&gt; &lt;td width="100" align="center"&gt;&lt;strong&gt;Date of Call&lt;/strong&gt;&lt;/td&gt; &lt;td width="100" align="center"&gt;&lt;strong&gt;Time of call&lt;/strong&gt;&lt;/td&gt; &lt;td width="100" align="center"&gt;&lt;strong&gt;Physio ID&lt;/strong&gt;&lt;/td&gt; &lt;td width="120" align="center"&gt;&lt;strong&gt;Triage completed&lt;/strong&gt;&lt;/td&gt; &lt;td width="120" align="center"&gt;&lt;strong&gt;Update&lt;/strong&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php while($rows=mysql_fetch_array($result)){ ?&gt; &lt;tr&gt; &lt;td&gt;&lt;? echo $rows['Reference']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;? echo $rows['Forename']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;? echo $rows['surname']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;? echo $rows['DOB']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;? echo $rows['Mobile']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;? echo $rows['Home']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;? echo $rows['Date']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;? echo $rows['Time']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;? echo $rows['PhysioID']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;? echo $rows['completed']; ?&gt;&lt;/td&gt; &lt;td align="center"&gt;&lt;a href="update.php?Reference=&lt;? echo $rows['Reference']; ? &gt;"&gt;update&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php } ?&gt; &lt;/table&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;p&gt; &lt;?php mysql_close(); ?&gt; &lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; </code></pre> <p>Update <pre><code>//Include database connection details require_once('config.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $login = clean($_POST['login']); $password = clean($_POST['password']); //Input Validations if($login == '') { $errmsg_arr[] = 'Login ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'Password missing'; $errflag = true; } //If there are input validations, redirect back to the login form if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: login-form.php"); exit(); } //Create query $qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'"; $result=mysql_query($qry); //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) == 1) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['member_id']; $_SESSION['SESS_FIRST_NAME'] = $member['firstname']; $_SESSION['SESS_LAST_NAME'] = $member['lastname']; session_write_close(); header("location: member-index.php"); exit(); }else { //Login failed header("location: login-failed.php"); exit(); } }else { die("Query failed"); } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload