Need help selecting certain values

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Need help selecting certain values

Post 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!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

use a loop with the mysql_fetch_assoc()

Code: Select all

while($row4 = mysql_fetch_assoc($result4))
{
  var_dump($row4);
}
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post 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.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

What about DO you get? Run the query in phpmyadmin
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

Well when I run it in phpmyadmin. For the $row['Number'] I just put in a number that exist. And it works.
Post Reply