vinpkl Posted September 20, 2009 Share Posted September 20, 2009 hi all i m creating navigation from database. There are around 30 dealers names entered in database like 1) Nokia 2) Samsung 3) sony continue till... 30) panasonic but the problem is that in the navigation the names will not be displayed according to series they were entered. So if i have to display the navigation according to changed series then i have to repeat this query 30 times. Is there any other way to display and change series but not repeating the query 30 times. vineet <?php $leftqry="select * from dealer_table where category_id=1 and dealer_name='nokia'"; $leftresult=mysql_query($leftqry); $leftrow=mysql_fetch_array($leftresult); $category_id=$_REQUEST['category_id']; echo "<tr>"; echo "<td>" . "<a class='leftnav'>» " .$leftrow['dealer_name']. "</a></td>"; echo "</tr>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/174873-navigation-with-changed-series/ Share on other sites More sharing options...
RussellReal Posted September 20, 2009 Share Posted September 20, 2009 I don't exactly follow 'changed series' do you mean they change order in your database? and if so why would it matter? but a solution to this problem being that there IS a low number of manufacturers, you could just pull all the fields from the db at once, then loop through them and do with the data whatever you want to do with it. Quote Link to comment https://forums.phpfreaks.com/topic/174873-navigation-with-changed-series/#findComment-921675 Share on other sites More sharing options...
ignace Posted September 20, 2009 Share Posted September 20, 2009 SELECT * FROM dealer_table ORDER BY category_id Altough I assume this is the default behavior if you don't specify any 'order by' rule Quote Link to comment https://forums.phpfreaks.com/topic/174873-navigation-with-changed-series/#findComment-921703 Share on other sites More sharing options...
vinpkl Posted September 20, 2009 Author Share Posted September 20, 2009 hi Russell Yes 'Changed Series' means 'Changed order'. means the dealer name entered at serial no. 1 will be at no. 5 and dealer name entered at serial no. 10 will be at no.2. so if i loop them in single query then they will display acording to the serial number they were entered. like the below code will display only one manufacturer 'Nokia' <?php $leftqry="select * from dealer_table where category_id=1 and dealer_name='nokia'"; $leftresult=mysql_query($leftqry); $leftrow=mysql_fetch_array($leftresult); $category_id=$_REQUEST['category_id']; echo "<tr>"; echo "<td>" . "<a class='leftnav'>» " .$leftrow['dealer_name']. "</a></td>"; echo "</tr>"; ?> and below query will output all dealers acording to serial no. they were entered in database. <?php $leftqry="select * from dealer_table where category_id=1"; $leftresult=mysql_query($leftqry); while($leftrow=mysql_fetch_array($leftresult)) { $category_id=$_REQUEST['category_id']; echo "<tr>"; echo "<td>" . "<a class='leftnav'>» " .$leftrow['dealer_name']. "</a></td>"; echo "</tr>"; } ?> now how will i change their serial no. or order sequence. vineet I don't exactly follow 'changed series' do you mean they change order in your database? and if so why would it matter? but a solution to this problem being that there IS a low number of manufacturers, you could just pull all the fields from the db at once, then loop through them and do with the data whatever you want to do with it. Quote Link to comment https://forums.phpfreaks.com/topic/174873-navigation-with-changed-series/#findComment-921707 Share on other sites More sharing options...
vinpkl Posted September 20, 2009 Author Share Posted September 20, 2009 hi ignace "order by category_id" will fetch results acording to category. but i want to fetch results all dealers in one category and that i m able to do. what i want to ask is after fetching how can i change their order sequence. at My present i am able to set sequence with my below query. But if i have 30 dealers then i have repeat this same query 30 times and it wil make my code very lenghty. vineet <?php $leftqry="select * from dealer_table where category_id=1 and dealer_name='nokia'"; $leftresult=mysql_query($leftqry); $leftrow=mysql_fetch_array($leftresult); $category_id=$_REQUEST['category_id']; echo "<tr>"; echo "<td>" . "<a class='leftnav'>» " .$leftrow['dealer_name']. "</a></td>"; echo "</tr>"; ?> vineet SELECT * FROM dealer_table ORDER BY category_id Altough I assume this is the default behavior if you don't specify any 'order by' rule Quote Link to comment https://forums.phpfreaks.com/topic/174873-navigation-with-changed-series/#findComment-921715 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.