displays the right info but won't add to link

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mwphurst
Forum Newbie
Posts: 17
Joined: Fri Jan 16, 2004 9:59 pm

displays the right info but won't add to link

Post by mwphurst »

I am trying to get my script to display a list of items ready for download, and provide a link for each one. It requires a status to be set to 5.

Code: Select all

if ($status==5){ $status="$la_download_link";}
The problem is I have to set the value of $la_download_link on each cycle of the product.

Code: Select all

$la_download_link = "<a href="$site_url/files/$file_name">Download</a>";
It should check for orders -> products -> file_name.
If there are multiple products in each order, it seems to be always selecting the first one.
For some reason each time it cycles it chooses the first item, atleast to add to the $la_download_link. I added echo" after each query to see what it was getting, and that seemed to be working fine. It displayed each product and filename as they should be.

Code: Select all

while ($row = mysql_fetch_array($sql_select))&#123;
										$order_id=$row&#1111;"cart_order_id"]; 
										$status=$row&#1111;"status"]; 
										$time=$row&#1111;"time"];
      									$year=substr($row&#1111;"date"],0,2);
										$month=substr($row&#1111;"date"],2,2);
										$day=substr($row&#1111;"date"],4,2);
										$prod_total=$row&#1111;"prod_total"];
										
		
						$get_product = mysql_query("SELECT product FROM ".$prefix."store_order_inv WHERE cart_order_id='$order_id'");
						$count = mysql_num_rows($get_product);while ($row = mysql_fetch_array($get_product)) &#123;
						$product = $row&#1111;"product"];echo"$product<BR>";
								
						$get_file_name = mysql_query("SELECT file_name FROM ".$prefix."store_inventory WHERE product='$product'");
						$count = mysql_num_rows($get_file_name);						
							while ($row = mysql_fetch_array($get_file_name)) &#123; 
						$file_name = $row&#1111;"file_name"];echo"$file_name";
	&#125;
						
$la_download_link = "<a href="$site_url/files/$file_name">Download</a>";										
if($date_style=="0")
											&#123;
												$date="$month/$day/$year";&#125;
										// EU date format
										if($date_style=="1")
											&#123;
											$date="$day/$month/$year";&#125;
			
										if ($bgcolour ==$colour_3)&#123;
											$bgcolour =$colour_4;&#125;
										elseif ($bgcolour ==$colour_4)&#123;
											$bgcolour =$colour_3;&#125;
           
										if ($status==1)&#123;
											$status="$la_order_pending";&#125;
										if ($status==2)&#123;
											$status="$la_order_await_ship";&#125;
										if ($status==3)&#123;
											$status="$la_order_shipped";&#125;
										if ($status==4)&#123;
											$status="$la_order_declined";&#125;
										if ($status==5)&#123;
											$status="$la_download_link";&#125;						
																	
						echo"<tr bgcolor="$bgcolour" align="center">
								<td>$order_id</td>
								<td>$status</td>
								<td>$date - $time</td>
								<td>$currency$prod_total</td>
								<TD>$file_name</td>
								<td align="center">
									<table width="94" height="24" border="0" cellpadding="0" cellspacing="0">
										<tr>
											<td height="24" width="94" background="images/white_button.gif" align="center" valign="middle" style="cursor: hand;" onClick="location.href='view_order.php?order_id=$order_id'"><a href="view_order.php?order_id=$order_id"><font class="wht_btn">$la_more_info</font></a></td>
										</tr>
									</table>	
							</tr>";
						&#125;							
						&#125;// end while
Even down near the bottom, I added <TD>$file_name</td> to see what that displayed. It displayed each filename as it should be. Why won't it add the right file name into the $la_download_link?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

while ($row = mysql_fetch_array($get_file_name)) {
$file_name = $row["file_name"];echo"$file_name";
}
That bit of code will overwrite $file_name on every loop. Not exactly sure where to start with the fix ;) It really needs some serious indenting and removal of html from php :o
mwphurst
Forum Newbie
Posts: 17
Joined: Fri Jan 16, 2004 9:59 pm

Post by mwphurst »

Then why is it displaying the right info if I just echo it or call for it later to display as <TD>?
It really needs some serious indenting and removal of html from php
Who ever wrote this originaly chose this form. I hate it. Starts on the left, then moves right so you can't see half the code. Why can't people keep everything nice and tight on the left? :lol:
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Who ever wrote this originaly chose this form. I hate it. Starts on the left, then moves right so you can't see half the code.
A snazzy regex in vi/vim will fix that up in no time at all ;)
Then why is it displaying the right info if I just echo it
Because the echo is inside the loop?
while ($row = mysql_fetch_array($get_file_name)) {
$file_name = $row["file_name"];echo"$file_name";
}
so the echo will always display the correct/current file name, but $file_name is finally assigned the last value from the loop.
mwphurst
Forum Newbie
Posts: 17
Joined: Fri Jan 16, 2004 9:59 pm

Post by mwphurst »

I've used

Code: Select all

if($count>0)
	&#123;
$option_number = 0;
				
	while ($row = mysql_fetch_array($get_file_name))
	&#123;
$option_number = $option_number + 1;
before to do something similar to this. But I tried it this time and it didn't work. Was I on the right track with this?
Post Reply