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!

while loop not outputting properly??

Status
Not open for further replies.

MJB3K

Programmer
Jul 16, 2004
524
GB
Hi, i have this code i wrote, but it doesn't seem to output anything. All it outputs is "0"?
Code:
global $h;
$h = "";

$q = mysql_query("SELECT `nid`, `title`, `news`, `subBy`, `view` FROM `news` WHERE `teamID` = '".$_SESSION['teamID']."' AND `view` = 'Y' ORDER BY `subDate` DESC") or die(mysql_error());
	while(list($nid,$t,$n,$sb,$v) = mysql_fetch_row($q)){
		$d = date("l jS F Y",$ts);
		$n = nl2br($n);
		
		$h += "<b>$t</b><br>
		<font color=\"#CCCCCC\">$d</font><br><br>
		$n<br><br>
		<hr size=\"1\" color=\"#CCCCCC\"><div align=right>Posted By: $sb :: <a href=\"?index&s=comments\">(0) Comments</a></div><br><br>";
	}

echo $h;
Any ideas??

Regards,

Martin

Computing Help And Info:
 
can you be certain that the query is retrieving data? to test change the while loop:

Code:
while ($row=mysql_fetch_assoc($result)):
  echo "</br><pre>";
  print_r ($row);
  echo "</pre>";
endwhile;
 
sorry
Code:
while ($row=mysql_fetch_assoc($q)):
  echo "</br><pre>";
  print_r ($row);
  echo "</pre>";
endwhile;
 
Try changing the
Code:
 $h += "<b>$t</b><br>....

to

$h[red].[/red]="....

The [blue]+[/blue] is an aruthmetic operator in PHP and oinly works with numbers, what you want to do is concatenate strings and for that you have to use the period "[blue].[/blue]"

Otherwise, addding a string plus a another sttring will always return 0 since strings have no arithmetic value.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
agreed, but if that were the only problem there would be "posted by:" and "comments" also being output each loop. since we are told there is no output other than "0" my working assumption is that we're not getting into the inside of the while loop.
 
vacunita: that worked perfectly, i do remember now, i was getting confused with actionscript for flash because you do += for strings!

Cheers

Regards,

Martin

Computing Help And Info:
 
Since the "posted by" and the "Comments" are part of the string he is trying to concatenatre they get ignored all together with the + operator.

So the resut of 0 is correct seeing as string+string+string is still = 0

The only problem there was the operator.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
fantastic - it's boxing day, nearly the new year and i'm still learning new things!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top