Jump to content

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

}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.