Skip to content Skip to sidebar Skip to footer

Using Select Query Inside A While Loop In Php

I am trying to Print some data from 2 tables when i try to execute 2nd select query inside while loop its not showing any result My query is $query=mysql_query('SELECT * FROM buse

Solution 1:

You can continue with your solution but for efficiency sake, you shouldn't be doing a SELECT inside a loop, you should be using an SQL JOIN.

Your query should be joining the two tables on the Route field:

SELECT*FROM buses b
INNERJOIN routes r ON b.Route = r.Route;

No extra queries will be needed inside the loop as you'll have access to the fromcity from this query. You may want to specifically declare the fields in the SELECT rather than using *.

Post a Comment for "Using Select Query Inside A While Loop In Php"