Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mysql query problem

Status
Not open for further replies.

MJB3K

Programmer
Jul 16, 2004
524
GB
Hi, i have the following code, but it doesn't output properly, as in it does 2 things for each section.

Can anybody help me?


Here is the code
Code:
<?php
include "../config.php";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
$q = mysql_query("SELECT `subDate` FROM news_computing ORDER BY `subDate` DESC");
	while(list($subDate) = mysql_fetch_row($q)){
	
	$h = date("H",$subDate)+6;
		if($h == 24){
			$h = "00";
		}
	$mnth = date("F",$subDate);
	$subDate = date("D, M jS, Y $h:i",$subDate);
	
?>
<table width="100%" cellpadding="0" cellspacing="0" class="tableBG" align="center" border="1" bordercolor="#CCCCCC" style="border-collapse: collapse"> 
  <tr class="tableBGtitleRow"> 
    <td background="assets/navTitleRowContentMid.png"><strong>News for <?php echo $mnth; ?></strong><small></small></td> 
   </tr> 
  <tr> 
    <td style="padding:0px 5px 0px 5px; " align="center"><br />
		<table width="90%" cellpadding="0" cellspacing="0" class="tableBG" border="1" bordercolor="#CCCCCC" style="border-collapse: collapse">
			<tr>
				<td width="40%">News Article</td>
				<td width="20%">Submitted By</td>
				<td width="30%">Submitted On</td>
			</tr>
<?php
$q2 = mysql_query("SELECT `aid`, `newsTitle`, `subBy`, `subDate` FROM news_computing ORDER BY `subDate` DESC");
	while(list($aid,$newsTitle,$subBy) = mysql_fetch_row($q2)){
?>
			<tr>
				<td><a href="/?p=compnews&aid=<?php echo $aid; ?>"><?php echo $newsTitle; ?></a></td>
				<td><?php echo $subBy; ?></td>
				<td><?php echo $subDate; ?></td>
			</tr>
<?php
	}
?>
		</table><br />
	</td> 
   </tr> 
</table>
<br /> 
<?php
}
?>
</body>
</html>
any ideas??

Regards,

Martin

Computing Help And Info:
 
What did you expect it to do? What does your database hold and what are the field definitions?

Also, why are you using the following code:
Code:
while(list($subDate) = mysql_fetch_row($q))
When this
Code:
while($rw = mysql_fetch_assoc($q))
will work as well. You can then refer to each field as an index of $rw:
Code:
$rw['subDate']
Ken
 
i prefer using the list method because i can define all the variables when they come out.

I wanted it to look like this:

Month
News 1
News 2

July
News 1
News 2

June
Playstation 3 | MJB3K | DATE
Google | MJB3K | DATE

Regards,

Martin

Computing Help And Info:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top