Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
nickman013
Forum Regular
Posts: 764 Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York
Post
by nickman013 » Sat Mar 04, 2006 1:02 am
Hello.
I have a code that connects to 2 tables.
Here is the code.
Code: Select all
<?
error_reporting('e_all');
$username2= "muot_report";
$password2= "report";
$database2= "muot_report";
$connection2 = mysql_connect('localhost',$username2,$password2);
mysql_select_db($database2);
$sql2 = "SELECT * FROM `report` WHERE Live = 1";
$result = mysql_query($sql2) or die(mysql_error());
$row = mysql_fetch_assoc($result);
echo $row['Code'];
?><br><br>
<form action=/site/muotReport/addComment.php method=get>
<table border=1>
<tr>
<td>
Your Name:
</td>
<td><input type=text size=23 name=yourname></td>
</tr>
<tr>
<td>Your Comment:</td>
<td><textarea rows=10 name=comments></textarea></td>
</tr>
<tr><td colspan=2 align=center><input type=hidden name=who value="<? echo $row['Number']; ?>"> <input type=submit></td></tr>
</table>
</form>
<?
$sql4 = "SELECT * FROM `comments` WHERE who =".$row['Number'];
$result4 = mysql_query($sql4) or die(mysql_error());
while($row4 = mysql_fetch_array($query4)) {
echo $row4['comment'];
};
mysql_close($connection2);
?>
I am having trouble with $sql4. I think it is working. However it does not show all of the rows that have the value of the number. How can I make it view all?
Thanks!
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Mar 04, 2006 1:05 am
use a loop with the mysql_fetch_assoc()
Code: Select all
while($row4 = mysql_fetch_assoc($result4))
{
var_dump($row4);
}
nickman013
Forum Regular
Posts: 764 Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York
Post
by nickman013 » Sat Mar 04, 2006 1:07 am
I actually edited my code right before you posted. I added the loop.
And I just tried yours but it still does not show anything.
There is stuff in the rows.
josh
DevNet Master
Posts: 4872 Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida
Post
by josh » Sat Mar 04, 2006 10:32 pm
What about DO you get? Run the query in phpmyadmin
nickman013
Forum Regular
Posts: 764 Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York
Post
by nickman013 » Sat Mar 04, 2006 10:34 pm
Well when I run it in phpmyadmin. For the $row['Number'] I just put in a number that exist. And it works.