I'm trying to select data from 2 databases then use php do I just want to give an example that will explain every thing:
php code:
- first database name is comments.
$colname_Program = "Any title from programs table :)";
mysql_select_db($database_Comments, $Comments);
$comments = mysql_query('SELECT * FROM programs WHERE title = "$colname_Program"', $Comments) or die(mysql_error());
$row_comments = mysql_fetch_assoc($comments);
$totalRows_comments = mysql_num_rows($comments);
$commentuserid = $row_comments['userid'];
- "userid" is the id of the user which i will use in my second select from another database"
All what im trying to do from second select is to bring user information from second database using his id.
- Second database name is naitreno.
mysql_select_db($database_NaiTreNo, $NaiTreNo);
$commentsuser = mysql_query('SELECT * FROM users WHERE id = "$commentsuserid"', $Comments) or die(mysql_error());
$row_commentsuser = mysql_fetch_assoc($commentsuser);
$username = $row_commentsuser['UserName'];
html and php code bundle now:
<?php do { ?>
<div class="comment-text"><?php echo $username;?></div>>
<?php } while ($row_comments = mysql_fetch_assoc($comments)); }?>
The code is not working :O what have I done wrong or what i have to do its just showing the first username in html<div class="comment-text"></div>
.