Davie33 Posted January 14, 2012 Share Posted January 14, 2012 Hi am in need of help with a query and just to say sry for the long post. I want to query user and news tables with newblog. $row['topic']; is from news table which i want to add to this code. The avatars i need to query from user table. <?php $query = yasDB_select("SELECT * FROM newsblog"); if($query->num_rows == 0) { echo '<div id="newsblog_text">This news blog has no comments, become a member and be the first to add one!</div>'; } else { $query = yasDB_select("SELECT * FROM newsblog WHERE userid = '$id'"); while($row = $query->fetch_array(MYSQLI_ASSOC)) { $date = date("M j, y, g:i a"); $text = $row['comment']; $text = str_replace('','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/biggrin.gif" title="biggrin" alt="biggrin" />',$text); $text = str_replace(':?','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/confused.gif" title="confused" alt="confused" />',$text); $text = str_replace('','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/cool.gif" title="cool" alt="cool" />',$text); $text = str_replace('','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/cry.gif" title="cry" alt="cry" />',$text); $text = str_replace(':shock:','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/eek.gif" title="eek" alt="eek" />',$text); $text = str_replace(':evil:','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/evil.gif" title="evil" alt="evil" />',$text); $text = str_replace('','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/lol.gif" title="lol" alt="lol" />',$text); $text = str_replace(':x','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/mad.gif" title="mad" alt="mad" />',$text); $text = str_replace('','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/razz.gif" title="razz" alt="razz" />',$text); $text = str_replace(':oops:','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/redface.gif" title="redface" alt="redface" />',$text); $text = str_replace(':roll:','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/rolleyes.gif" title="rolleyes" alt="rolleyes" />',$text); $text = str_replace('','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/sad.gif" title="sad" alt="sad" />',$text); $text = str_replace('','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/smile.gif" title="smile" alt="smile" />',$text); $text = str_replace('','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/surprised.gif" title="surprised" alt="surprised" />',$text); $text = str_replace(':twisted:','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/twisted.gif" title="twisted" alt="twisted" />',$text); $text = str_replace(':wink:','<img src="' . $siteurl . 'templates/' . $theme . '/styles/images/smileys/wink.gif" title="wink" alt="wink" />',$text); echo '<div class="newsblog_box1">'; echo '<div class="newsblog_name"><a href="'.$memberlink.'">' . $row['name'] . '</a>'; echo '<div class="avatar"><a href="'.$memberlink.'"><img src="'.$avatarimage.'" height="80" width="80" align="left"></a></div>'; echo '<br />'.$row['formatted_time'].'</div><div class="newsblog_box2">'.$row['topic'].'<br />' . $text . '</div></div>'; } }?> Do i need to add anything to this sql ?. CREATE TABLE IF NOT EXISTS `newsblog` ( `id` int(11) NOT NULL AUTO_INCREMENT, `userid` int(11) NOT NULL DEFAULT '0', `ipaddress` varchar(255) NOT NULL DEFAULT '', `comment` text NOT NULL, `name` varchar(255) NOT NULL DEFAULT '', `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; CREATE TABLE IF NOT EXISTS `news` ( `id` int(11) NOT NULL AUTO_INCREMENT, `news_text` text NOT NULL, `edit` int(11) DEFAULT '0', `date` varchar(255) NOT NULL, `topic` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; Link to comment https://forums.phpfreaks.com/topic/255029-query-3-sql-tables-from-one-query/ Share on other sites More sharing options...
Muddy_Funster Posted January 14, 2012 Share Posted January 14, 2012 I'm not sure what it is you actually want to do...but I will guarantee it's going to use JOIN's. What exactly do you want to return from your query? Link to comment https://forums.phpfreaks.com/topic/255029-query-3-sql-tables-from-one-query/#findComment-1307716 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.