0

Hey guys,
Sorry if I am cross-posting, but I can't seem to find a solution to this problem. I have a PHP while loop that retrieves records from my database. Inside the loop, I also have a Javascript counter that I need to generate for each record I retrieve (for each iteration). However, the counter only works for one record (i think it's the last iteration of the while loop). I'm guessing it's to do with a clash between the client-side javascript and the server-side php.
Can anyone confirm this or tell me if there is a work around? Many thanks.

<?php 

$request = mysql_query("SELECT * FROM auctions WHERE category_id BETWEEN '12' AND '84' ORDER BY a_timestamp DESC");	
	
	$i = 0;		
	while ($i <= 6 and $result = mysql_fetch_assoc($request)) {

		$time = $result['a_timestamp'];
		$length = $result['a_length'];
	
		$expires = strtotime($time. '+' .$length. 'days');
		$expires = date('m/d/Y g:i A',$expires);
?>
	<table border="0" cellpadding="5px">
			<tr class="shade1">
				<td rowspan="3" height="50px" width="50px">
		<?php echo "<img src=https://students.ee.port.ac.uk/ece60363/".$result['a_image'] ." height=70px width=70px>"; ?>
				</td>
				<td class="error">Buy it Now price: £<?php echo $result['a_buyitnow']; ?></td>
				<td class="error">Current Price: £</td>
				<td class="error">
					Time Remaining: 

<!--------THIS ONLY WORKS ONCE, RATHER THAN EACH ITERATION---------->
					<script language="JavaScript">
						TargetDate = "<?php echo $expires; ?>";
						BackColor = "";
						ForeColor = "";
						CountActive = true;
						CountStepper = -1;
						LeadingZero = true;
						DisplayFormat = "%%D%% Days %%H%% Hrs %%M%% Mins %%S%% Secs";
						FinishMessage = "Auction Ended!";
					</script>
					<script language="JavaScript" src="/ece60363/count.js"></script>


				</td>
			</tr>
			<tr class="shade2">
				<td colspan="2"><a href="/ece60363/auction.php?auc=<?php echo $result['a_id']; ?>">
						<?php echo $result['a_title'];?></a>
				</td>
				<td>Quantity Remaining: <?php echo $result['a_quantity']; ?></td>
				
			</tr>
			<tr class="shade1">
				<td colspan="6" rowspan="2"><?php echo $result['a_description'];?></td>
			</tr>
			<tr>
				
			</tr>
	</table>
	<hr>
<?php 
	$i++;
	}	
?>
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by almostbob
0

of course it doesnt work,
language='javascript' is deprecated
that will fix much of it
all that code above is the wrong color due to the unescaped quotes
img src attributes arent quoted, failure could be due to something as simple as that putting browser into quirks mode


get a code highlighting editor and all these problems vanish

Edited by almostbob: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.