Page 1 of 1

Need help selecting certain values

Posted: Sat Mar 04, 2006 1:02 am
by nickman013
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!

Posted: Sat Mar 04, 2006 1:05 am
by feyd
use a loop with the mysql_fetch_assoc()

Code: Select all

while($row4 = mysql_fetch_assoc($result4))
{
  var_dump($row4);
}

Posted: Sat Mar 04, 2006 1:07 am
by nickman013
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.

Posted: Sat Mar 04, 2006 10:32 pm
by josh
What about DO you get? Run the query in phpmyadmin

Posted: Sat Mar 04, 2006 10:34 pm
by nickman013
Well when I run it in phpmyadmin. For the $row['Number'] I just put in a number that exist. And it works.