kais99 Posted March 6, 2009 Share Posted March 6, 2009 hey all i stuck with this, i spent 3 hours of internet search but didnt find solution. i want to make a navigation like nokia nokia N95 nokia E71 samsung samsung D500 D900 Sony Erricson w110 p10 i made 2 tables , phone, model phone > id, name model > id, name, phoneid i tried this query in php select phone.id, phone.name, model.id, model.name, model.phoneid from phone, model where model.phoneid= phone.id it shows nokia nokia N95 nokia nokia E71 nokia some model nokia some model samsung samsung D500 samsung D900 and soo on if i use $query= "select * from phone"; $result = mysql_query($query); while ($row= mysql_fetch_array($result)) { $id =$row['id']; $phone= $row['name']; echo "<h1>$phone</h1>"; echo "<ul>"; //[b]2nd while loop[/b] $query2= "select * from model where phoneid='$id'"; $result2 = mysql_query($query2); while ($row= mysql_fetch_array($result2)) { $model= $row['name']; echo "<li>$phone</li>"; } echo "</ul>"; this code just fetch one result nokia nokia n95 please help me , i shall be greatful. Quote Link to comment https://forums.phpfreaks.com/topic/148167-select-1-row-from-1-table-and-all-rows-from-a-second-table-2-while-loops/ Share on other sites More sharing options...
kickstart Posted March 6, 2009 Share Posted March 6, 2009 Hi You could do it as 2 seperate pieces of SQL, looping through one and for each entry performing the other and looping through what it returns. However, a join would be most sensible, and just keep track of when the phoneid changes. Something like:- SELECT phone.id, phone.name, model.id, model.name FROM phone JOIN model ON phone.id = model.phoneid ORDER BY phone.id, model.id All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/148167-select-1-row-from-1-table-and-all-rows-from-a-second-table-2-while-loops/#findComment-777767 Share on other sites More sharing options...
kais99 Posted March 6, 2009 Author Share Posted March 6, 2009 Thanks Keith for your help. its working now. Quote Link to comment https://forums.phpfreaks.com/topic/148167-select-1-row-from-1-table-and-all-rows-from-a-second-table-2-while-loops/#findComment-778517 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.