I have a while loop and its working properly, i am new to php and cannot figure out how to append the .php extention in the href inside php. This is my loop:
while($get = mysqli_fetch_assoc($result))
{
echo"<tr>
<td><a href=". $get['title'] ." target=\"_blank\">".$get['title']."</a></td>
<td>".$get['info']."</td>
<td>".$get['author']."</td>
<td>".$get['price']."</td>
<td><a href='dwn.php?rn=$get[id]' target=\"_blank\">Download</a></td>
</tr>";
}
I want to add . php extention inside the href in the first tag , i thought it would be something like this :
<td><a href=" . $get['title'] . '.php'" target=\"_blank\">".$get['title']."</a></td>
But ofcourse this doest work, So please help me what should i do Thanks in advance and Sorry for Bad English.
CodePudding user response:
you missed a poi after .php
to concatenate
while($get = mysqli_fetch_assoc($result))
{
echo"<tr>
<td><a href='". $get['title'] .'.php'."' target=\"_blank\">".$get['title']."</a></td>
<td>".$get['info']."</td>
<td>".$get['author']."</td>
<td>".$get['price']."</td>
<td><a href='dwn.php?rn=$get[id]' target=\"_blank\">Download</a></td>
</tr>";
}
I suggest you to take a look to printf
for this type of string templating
while($get = mysqli_fetch_assoc($result))
{
printf("<tr>
<td><a href='%s.php' target=\"_blank\">%s</a></td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td><a href='dwn.php?rn=%d' target=\"_blank\">Download</a></td>
</tr>",
$get['title'],
$get['title'],
$get['info'],
$get['author'],
$get['price'],
$get['id']
);
}
CodePudding user response:
Found an very easy solution while messing with the code.
Turns out i just had to contain ". $get['title'] ."
inside Single apostrophe(''), Like this:
<td><a href='". $get['title'] .".php' target=\"_blank\">".$get['title']."</a></td>
It works and the problem is Solved.