tags:

views:

143

answers:

6

hi all,

There is a problem in this code I can not detected

<?php echo "<a href ='$rows['Link']'> .$rows['UploadName']</a> "; ?>

Do you find you have a solution???

Thank you very much.

+6  A: 

My guess is that your problem is that it isn't writing out the data in $rows['Link'] ... if that is the case, then your solution is to change it to {$rows['Link']} ... actually, you'll probably want to change both, since it looks like you started doing string concatenation and then switched halfway through.

So:

<?php echo "<a href ='$rows['Link']'> .$rows['UploadName']</a> "; ?>

becomes:

<?php echo "<a href ='{$rows['Link']}'>{$rows['UploadName']}</a> "; ?>

See: The PHP Manual on Variable Parsing in strings

Sean Vieira
Oh - nice. Haha I didn't know you could do that. +1 - that'll probably save me a lot of time.
Cam
don't forget to sanitize your variables
knittl
@knittl -- absolutely! Actually, they should be sanitized **before** they get to this point. (Which is why I left it out -- I'm assuming that the data he's using already has been sanitized for html output.)
Sean Vieira
A: 

There's a problem in parsing variables in the string. Use curl braces:

<?php echo "<a href ='{$rows['Link']}'> .{$rows['UploadName']}</a> "; ?>

Take a look to this php.net page, under "variable parsing".

Nicolò Martini
+2  A: 

It should be:

<?php echo "<a href ='{$rows['Link']}'>{$rows['UploadName']}</a>"; ?> 

Or:

<?php echo "<a href ='{$rows['Link']}'>" . $rows['UploadName'] . "</a>"; ?> 
Isaac
If you start with those two there would be still two more possibilities ;)
Felix Kling
Yeah, I mean no doubt.Hey, we could go with the HEREDOC route and say ...echo <<<EOF ....EOF; But you're right, "there's more than one way to do it.".
Isaac
A: 

More alternatives:

<?php echo '<a href ="' . $rows['Link'] . '">' . $rows['UploadName'] . '</a>'; ?>

or

<?=('<a href ="' . $rows['Link'] . '">' . $rows['UploadName'] . '</a>')?>

Dolph
Thank you allNow code is working properly
sandy
A: 

Another alternative (that I tend to prefer, given I know that both 'Link' and 'UploadName' are valid indices of $row.

<a href="<?=$rows['Link']?>"><?=$rows['UploadName']?></a>

I'm not sure what that does for readability for most people, but on color-coded IDEs, it tends to help, because the HTML isn't just seen as one giant ugly single-colored string.

ashays
A: 
thank you all 

Here I have a another  problem in this code ..

I want to specify the 4 values in each page ..
But I can not ... So far there is a problem, I think, in limit


    <?php

if(!isset($_GET["page"]))
{
$page=1;


include ("connect.php"); 
}
else
{
$page= intval($_GET['page']);
}
$max=4;
$from=($max*$page)- $max;
$sql = mysql_query("select * from uploads,members,rooms where uploads.MemberID = members.MemberID and uploads.RoomID = rooms.RoomID and UploadCategory='L' order by UploadID desc limit $from,$max  "); 
$num_sql = mysql_num_rows($sql);

?>


<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<div align="center">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF">&nbsp;</td>
<td colspan="4" bgcolor="#FFFFFF">
<p align="center"><font size="4"> file</font></td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>

<td align="center" bgcolor="#FFFFFF"><strong>member</strong></td>

<td align="center" bgcolor="#FFFFFF"><strong> Name</strong></td>

</tr>
</div>

<?php


//$sql1 = mysql_query("select * from book order by id desc limit $from,$max ");
//$num_sql1 = mysql_num_rows($sql1);
$pages=ceil($num_sql/$max);
$num = mysql_num_rows($sql);
//$result = mysql_query("SELECT * FROM book order by id");

while($row = mysql_fetch_array($sql))


  {

     ?>




<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['UploadID']; ?>"></td>
<td bgcolor="#FFFFFF"> <?php echo $row[MemberName]. "<br />";  ?></td>


<td bgcolor="#FFFFFF"> <?php echo $row[UpoadName]."<br />";  ?></td>



</tr>

<?php

}

?>

<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="delete"></td>
</tr>


<?php


if($page>1)
{
$prev=$page-1;
echo"<a href=".$PHP_SELF."?page=$prev\"></a>";
}
for($i=1;$i<=$pages;$i++)
{
if($page==$i) echo" [$i] ";
else
{
echo" <a href=".$PHP_SELF."?page=$i\">$i</a> ";
}
}
if($page<$pages)
{
$next=$page+1;
echo"<a href=".$PHP_SELF."?page=$next\"></a>";
}
 ?>


</html>
sandy
@Sandy - if you have another problem, it's best to post a new question rather than another answer. This answer doesn't help anybody with your original question should they have the same initial problem :-)
richsage