PHP - Querying mysql and outputting table

Hi All,

I'm only a day into learning PHP. I'm trying to query my database and output the results. I am expecting 6 lines of results from my query (which works fine when running directly against the database), but on the browser, it's missing the first and last result. Can anyone help with where i'm going wrong?

Many thanks

Pete

Query
$sql2 = "SELECT interviewees.firstname, interviewees.lastname, timetable.starttime, timetable.endtime, timetable.description, timetable.meetingperson, interviewers.firstname, interviewers.lastname FROM interviewees INNER JOIN timetable on interviewees.candidateid=timetable.candidateid JOIN interviewers ON timetable.meetingperson=interviewers.meetingperson WHERE interviewees.candidateid=1 ORDER BY starttime";
$result2 = $conn->query($sql2);
$row2 = $result2->fetch_assoc();

Open in new window


Code for Output
while($row2 = $result2->fetch_assoc()) {
        echo $row2["starttime"]. " - ". $row2["description"]. "<br>";
     }

Open in new window

universalmonsterAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TONY TAYLORCommented:
Check out this.

Between the both, I think it should look something like this:

$sql2 = "SELECT interviewees.firstname, interviewees.lastname, timetable.starttime, timetable.endtime, timetable.description, timetable.meetingperson, interviewers.firstname, interviewers.lastname FROM interviewees INNER JOIN timetable on interviewees.candidateid=timetable.candidateid JOIN interviewers ON timetable.meetingperson=interviewers.meetingperson WHERE interviewees.candidateid=1 ORDER BY starttime";
if ($result2 = $conn->query($sql2)) {
     while($row2 = $result2->fetch_assoc()) {
        echo $row2["starttime"]. " - ". $row2["description"]. "<br>";
     }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
universalmonsterAuthor Commented:
Thank you - that was exactly what I needed. It's working perfectly!
1
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.