my while loop is only returning 1 row when there is clearly 2 results

this is my query

$query_Recordset_links= "SELECT * FROM shipbook_links
LEFT JOIN tps_tour ON shipbook_links.shipbook_links_tps = tps_tour.tps_tour_id 
LEFT JOIN invoice_project ON shipbook_links.shipbook_links_invoice = invoice_project.invoice_project_id 
LEFT JOIN cc_rentals ON shipbook_links.shipbook_links_ccrental = cc_rentals.cc_rentals_id 
WHERE shipbook_links_order = $shipbook_id ORDER BY shipbook_links_active ASC ";
		 $result_Recordset_links= $link->query($query_Recordset_links);
		 $row_Recordset_links = $result_Recordset_links->fetch_assoc();

Open in new window

export it

 if(mysqli_num_rows($result_Recordset_links) >0) {
	  do {   	

echo $row_Recordset_links['tps_tour_id'];	  

	 } while ($row_Recordset_links = mysqli_fetch_assoc($Recordset_links)); 

Open in new window

now for testing, i use this

  echo mysqli_num_rows($result_Recordset_links);

Open in new window

and is echos 2..

but when i try to echo $row_Recordset_links['tps_tour_id'];
it only displays 1 result...
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

Chris StanyonWebDevCommented:
In your while clause you are trying to fetch_array from $Recordset_links which doesn't appear to exist. I think you mean to use $result_Recordset_links.

Your code does look a little odd though - is there are reason why you're mixing object and procedural or why you're pulling out one record before doing the loop. Maybe this is a cleaner way to do it:

$results =  $link->query($query_Recordset_links);

while ( $row = $results->fetch_assoc() ) {
    echo $row['tps_tour_id'];	  

Open in new window

jblayneyAuthor Commented:
I'm trying to update older code without rewriting the page from scratch and it may be getting a bit messy ( it is all in mysql not mysqli)
Chris StanyonWebDevCommented:
OK. If you rewrite your code like I've posted then you'll get all the records from your query echoed out. There's no need to check the number of rows, as the while loop will only fire if you actually have rows.

Any trace of mysql should definitely be removed. If you don't do it, then your site is very likely to just die at some point. You can generally do a straight swap for the mysqli procedural style, but personally I find the object way of doing things feels cleaner and more logical.

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
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

From novice to tech pro — start learning today.