Page 1 of 1

Script causing anothr script not to display info

Posted: Tue Jun 12, 2007 6:00 pm
by thefreebielife
This script:

Code: Select all

	<table style="border:1px solid #0099CC; width:635px; font-size:12px; margin-left:80px;" cellpadding="2" cellspacing="0">
	<tr>
	<td colspan="4" style="border-bottom:1px solid #0099CC" bgcolor="#CC00FF"><div align="center"><strong>News</strong></div></td>
	</tr>
	<tr bgcolor="#CCEAEA">
	<td width="15%" style="border-bottom:1px solid #0099CC"><div align="center">Date </div></td>
	<td width="15%" style="border-bottom:1px solid #0099CC"><div align="center">User Posted</div></td>
	<td width="50%" style="border-bottom:1px solid #0099CC"><div align="center">Title</div></td>
	<td width="20%" style="border-bottom:1px solid #0099CC"><div align="center">View</div></td>
	</tr>
	<?
$sql = "SELECT * FROM news order by date DESC";
	$result = mysql_query($sql);
	$i=0;
	while($r=mysql_fetch_array($result))
	{	
		$i=$i+1;
		?>
		<tr bgcolor="#<?= ($i++%2) ? 'FFFFFF' : 'F5F5F5' ?>">
		<td width="15%" style="border-bottom:1px dashed purple; border-right:1px dashed purple"><div align="center"><FONT SIZE="2"><? echo $r["date"]; ?></FONT></div></td>
		<td width="15%" style="border-bottom:1px dashed purple; border-right:1px dashed purple"><div align="left"><FONT SIZE="2">&nbsp;<? echo $r["user"]; ?></FONT></div></td>
		<td width="50%" style="border-bottom:1px dashed purple; border-right:1px dashed purple"><div align="center"><FONT SIZE="2"><? echo $r["title"]; ?></FONT></div></td>
		<td width="20%" style="border-bottom:1px dashed purple; border-right:1px dashed purple"><div align="center"><FONT SIZE="2"><a href="viewnews.php?newsID=<? echo $r["newsID"]; ?>">View</a></FONT></div></td>
		</tr>  

		<? } 
	if($i==0)
	{
		?>
		<tr>
		<Td colspan=3 align="center"><FONT SIZE="2" COLOR="#FF0000"><B>There are news articles submitted.</B></FONT></Td>
		</tr>

		<? } ?>
	</table>	<p>	<p>		
Is causing this one..

Code: Select all

	<table width="400" style="border:1px solid #0099CC; width:735px; font-size:12px; margin-left:30px;" cellpadding="2" cellspacing="0" class="reftable">
	<tr>
	<td colspan="2" style="border-bottom:1px solid #0099CC"><div align="center"><strong>Your Referrals </strong></div></td>
	</tr>
	<tr bgcolor="#CCEAEA">
	<td width="50%" style="border-bottom:1px solid #0099CC"><div align="center">Username</div></td>
	<td width="50%" style="border-bottom:1px solid #0099CC"><div align="center">Offer Status</div></td>
	</tr><? if ($count == 0) { ?>
		<tr>
		<td colspan="2"><div align="center"><font color="#FF0000">You Have No Referrals</font></div></td>
		</tr>
		<? } ?>

	<?
	//grab all the content
	while($r=mysql_fetch_array($result))
	{	
		$ruser=$r["username"];
		$roffer=$r["ostatus"];
		?>
		<tr bgcolor="#<?= ($i++%2) ? 'FFFFFF' : 'F5F5F5' ?>">
		<td width="50%" style="color:#0099FF "><div align="center"><? echo "$ruser"; ?></div></td>
		<td width="50%"><div align="center"><? if ($roffer == 1) { echo "<font color=#009900>Offer Completed</font>"; }
		else if ($roffer == 0.2) { echo "<font color=red>Completed 1/5 Credits</font>"; } 
		else if ($roffer == 0.4) { echo "<font color=red>Completed 2/5 Credits</font>"; } 
		else if ($roffer == 0.6) { echo "<font color=red>Completed 3/5 Credits</font>"; } 
		else if ($roffer == 0.8) { echo "<font color=red>Completed 4/5 Credits</font>"; }
		else if ($roffer == 0) { echo "<font color=red>Offer Not Completed</font>"; } 
		else if ($roffer == 2) { echo "<font color=red>User Removed</font>"; }
		
		?> </div></td>
		</tr> 
		<? } ?>

	<?
	//grab all the content
	while($r=mysql_fetch_array($result))
	{	
		$ruser=$r["username"];
		$roffer=$r["ostatus"];
		?>
		<tr>
		<td width="50%" style="color:#0099FF "><div align="center"><? echo "$ruser"; ?></div></td>
		<td width="50%"><div align="center"><? if ($roffer == 1) { echo "<font color=#009900>Offer Completed</font>"; }
		else if ($roffer == 0.2) { echo "<font color=red>Completed 1/5 Credits</font>"; } 
		else if ($roffer == 0.4) { echo "<font color=red>Completed 2/5 Credits</font>"; } 
		else if ($roffer == 0.6) { echo "<font color=red>Completed 3/5 Credits</font>"; }
		else if ($roffer == 0.8) { echo "<font color=red>Completed 4/5 Credits</font>"; } 
		else if ($roffer == 0) { echo "<font color=red>Offer Not Completed</font>"; } 
		else if ($roffer == 2) { echo "<font color=red>User Removed</font>"; }
		
		?> </div></td>
		</tr>>  

		<? }  ?>
	</table>	<p>
Not to display any of the info called on.

I know this because if i take the top one out, the bottom works fine.

i am completely confused here

Posted: Tue Jun 12, 2007 6:32 pm
by smudge
Are they in the same file? If so, check to see if you are using a variable again w/o knowing it.
Also, try replacing your if/else if statements with a switch statement. it may not fix your problems, but it looks better. :)

Posted: Tue Jun 12, 2007 6:44 pm
by aaronhall
If those two code segments are in the same file, you'll need to use mysql_data_seek to reset the pointer -- when you iterate through a result resource ($result), the internal pointer doesn't automatically reset to 0 -- you need to do that manually before looping through the same result resource a second time (and every time thereafter).

Posted: Tue Jun 12, 2007 7:00 pm
by thefreebielife
yes they are in the same file, but the variables dont appear more then once.

also, they are different scripts with different variables, should i still try data seek?

Posted: Tue Jun 12, 2007 7:14 pm
by aaronhall
$result appears more than once: if you haven't reassigned it, it refers to the same result resource, and the pointer needs to be reset if you want to loop over it again.

To your second question: no, variables don't persist across different requests (sessions aside).

Posted: Tue Jun 12, 2007 7:24 pm
by thefreebielife
i tried that, it still doesnt work.

i have no errors in my cgi log either

also i have more "$result"'s on this page, and they work fine together. just ever since i added this script it took away the info ONLY from the other script i posted