Jump to content

Pulling data from database issue


messinWifU

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/241296-pulling-data-from-database-issue/
Share on other sites

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

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.