[RESOLVED]problem outputing result of inner join query using php
Hi all .I have 2 tables as shown below.
I run this query in phpmyadmin and i get sets of data.But for some
reason my phpscript doesn't output any data.
idyoutube in both tables are the same.
i have 2 playlists and one video in each but my php script returns nothing!!
I be happy if some help me fix this phpscript.
PHP Code:
select F.idyoutube, F.thumbnail_url, F.title, F.view_count, F.comment_count, F.embed_status from playlist as P inner join youtubevideos2 as F on F.idyoutube = P.idyoutube where playlistname='popsong'
PHP Code:
$server = "localhost"; // MySQL hostname
$username = "root"; // MySQL username
$password = "????"; // MySQL password
$dbname = "test"; // MySQL db name
$db = mysql_connect($server, $username, $password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$query = "select F.idyoutube, F.thumbnail_url, F.title, F.view_count, F.comment_count, F.embed_status from playlist as P inner join youtubevideos2 as F on F.idyoutube = P.idyoutube where playlistname='$playlistname'";
$result = mysql_query($query) or die('Error, query failed');
echo '<table width="700" border="0" cellspacing="1" cellpadding="2" align="center">';
while ($row = mysql_fetch_assoc($result)) {
echo '<td width="' . $colWidth . '%">' .
// echo '<td width="120">' .
'<a href="./pagingplayer.php?playlistname='.$s.'&videoid='.$row['idyoutube'].'"style="text-decoration: none">' .
'<img width="120" src="' . $row['thumbnail_url'] . '" height="90" border="0">' .
'<br
}
PHP Code:
CREATE TABLE `playlist` (
`User_ID` int(10) unsigned NOT NULL default '0',
`idyoutube` varchar(93) character set latin1 NOT NULL default '0',
`playlistname` varchar(32) character set latin1 NOT NULL default '',
UNIQUE KEY `Index_1` (`User_ID`,`idyoutube`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
CREATE TABLE `youtubevideos2` (
`ID` int(11) NOT NULL auto_increment,
`author` varchar(93) NOT NULL default '0',
`idyoutube` varchar(93) NOT NULL default '0',
`title` varchar(93) NOT NULL default '0',
`length_seconds` int(10) unsigned NOT NULL default '0',
`rating_avg` int(10) unsigned NOT NULL default '0',
`rating_count` int(10) unsigned NOT NULL default '0',
`description` varchar(255) NOT NULL default '0',
`view_count` int(10) unsigned NOT NULL default '0',
`upload_time` int(10) unsigned NOT NULL default '0',
`comment_count` int(10) unsigned NOT NULL default '0',
`tags` varchar(93) NOT NULL default '0',
`url` varchar(93) NOT NULL default '0',
`thumbnail_url` varchar(93) NOT NULL default '0',
`embed_id` varchar(93) NOT NULL default '0',
`embed_status` varchar(93) NOT NULL default '0',
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=237 ;
Re: problem outputing result of inner join query using php
Your line break doesn't get closed in the echo. Possibly the data is being returned but no shown on the page because it's been put in the HTML source not as output. Fix the line break e.g. <br />.
If it still doesn't work, before you do the echo in the while loop do a
print_r($row);
to check whats actually being returned. If you dont see it on the page, do a view->source on the browser to see it.
Re: problem outputing result of inner join query using php
resolved i was using diffrent varible name to pass it to my where clause query.