1

Here is my code

$sql = "SELECT distinct s.doc_id, s.pat_id, s.approved, p.pat_fullname, p.pat_id from patient p, subscribe s WHERE s.doc_id = '$doc_id' AND s.approved = '1' AND s.pat_id = p.pat_id;";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
    $patname = $row['p.pat_fullname'];      
    echo "<label>Patient:</label>";
    echo "<option value='$patname'>$patname</option>";

}

Notice: Undefined index: p.pat_fullname in C:\Program Files (x86)\EasyPHP-5.3.9\www\PHR system\doc_patdoc.php on line 60

Above is the notice from browser. The sql query is definitely worked as I have tried it in my database. So what row's name should I put instead of p.pat_fullname?

2 Answers 2

5

The result does not contain the p. prefix, so remove that:

 $patname = $row['pat_fullname']; 
Sign up to request clarification or add additional context in comments.

3 Comments

+1 this is a correct answer - but what if there are columns with the same name ? (I know there isnt in the OPs case, which is why I voted up)
If they are the same name, you need to alias them so that they have unique names.
@TheodoreR.Smith you mean just like my answer ;-)
1

Use an alias in your query :

p.pat_fullname as fullname

then access it like this :

$row['fullname']

You can access it without the p. table alias but if you have multiple columns with the same name this is the safest way to go

1 Comment

Thanks, this is the answer I want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.