messinWifU Posted July 7, 2011 Share Posted July 7, 2011 When I execute this code it pulls both rows twice. $q = ('SELECT count(*) FROM `shows`'); $num = mysql_query($q); $i=1; while($i<$num){ $query = sprintf("SELECT pid,epid,title FROM `shows` WHERE cid=" . $i); $result = mysql_query($query); while($ds = mysql_fetch_assoc($result)){ echo(' <ul id="' . $ds['pid'] . '" title="' . $ds['title'] . '"> '); $q = sprintf('SELECT episodes.pid,episodes.ptid FROM episodes JOIN shows ON episodes.epid="'. $ds['epid'] .'" ORDER BY episodes.ptid'); $res = mysql_query($q); while($ds1 = mysql_fetch_assoc($res)){ echo(' <li><a href="#' . $ds1['pid'] . '#_video">' . $ds1['ptid'] . '</a></li> '); } echo "</ul>"; } $i++; } Here is the output: <li><a href="#swid">SW</a></li> <li><a href="#bid">B</a></li> </ul> <ul id="swid" title="SW"> <li><a href="#sw1#_video">(LQb)EP SW 1</a></li> <li><a href="#sw1#_video">(LQ)EP SW 1</a></li> </ul> <ul id="bid" title="Bleach"> <li><a href="#b1#_video">(HQ)EP B 1</a></li> <li><a href="#b1#_video">(HQ)Ep B 1</a></li> </ul> I probably have a simple mistake but I cant find it, all help/suggestions are welcome Link to comment https://forums.phpfreaks.com/topic/241296-pulling-data-from-database-issue/ Share on other sites More sharing options...
sKunKbad Posted July 7, 2011 Share Posted July 7, 2011 You're not really echoing it twice. If you look closely, the content of the list items is slightly different. Link to comment https://forums.phpfreaks.com/topic/241296-pulling-data-from-database-issue/#findComment-1239466 Share on other sites More sharing options...
messinWifU Posted July 7, 2011 Author Share Posted July 7, 2011 "(LQb)EP SW 1" that was an accident. Link to comment https://forums.phpfreaks.com/topic/241296-pulling-data-from-database-issue/#findComment-1239468 Share on other sites More sharing options...
Network_ninja Posted July 7, 2011 Share Posted July 7, 2011 You can try out this one if you love to: $query = mysql_query("SELECT pid,epid,title FROM shows"); if(mysql_num_rows($query) > 0) { while($ds = mysql_fetch_array($query)) { echo(' <ul id="' . $ds['pid'] . '" title="' . $ds['title'] . '"> '); $res = mysql_query('SELECT episodes.pid,episodes.ptid FROM episodes JOIN shows ON episodes.epid="'. $ds['epid'] .'" ORDER BY episodes.ptid'); while($ds1 = mysql_fetch_array($res)){ echo(' <li><a href="#' . $ds1['pid'] . '#_video">' . $ds1['ptid'] . '</a></li> '); } echo "</ul>"; } } Link to comment https://forums.phpfreaks.com/topic/241296-pulling-data-from-database-issue/#findComment-1239475 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.