Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem outputing result of inner join query using php

Status
Not open for further replies.

david55

Programmer
Oct 23, 2007
6
NL
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.

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'


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

}


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 ;
 
I would hazard a guess that your column references in PHP are incorrect, because you are using a JOIN query. Check what column names are being returned using PHPMyAdmin, or by print_r($row) before trying to display the data.

-Geeeeeeeeeeeeeeeeeeeeeeee-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top