I have piece of php code which I want to put as a link.
echo"<img border='1' src='$images[$i]' width='350' height='250'>";
This is what I came up with
<a href = "something"> above statement <a>
but this gives me error.
<?php echo "<a href = 'something'><img border='1' src='".$images[$i]."' width='350' height='250'></a>"; ?>
echo"<img border='1' src='$images[$i]' width='350' height='250'>";
echo "<a href="url" > <img border='1' src='".$images[$i]."' width='350' height='250'> </a>";
OR
<a href="url" > <?php echo "<img border='1' src='".$images[$i]."' width='350' height='250'>"; ?></a>
echo"
<a href='...'>
<img border='1' src='{$images[$i]}' width='350' height='250'>
</a>
";
You can use the concatenate dot operator in this way:
<?php
echo '<img border="1" width="350" height="250" src="'.$images[$i].'"'>;
?>
Related
I have tried to echo the table fields one by one.
But I can't echo the image field.
My code is:
if ($data->Prophylaxis_Indicated == 1) {
echo "<td><span title='true_logo'> <img src='url('images/1-icon.png')' height='20' width='20'></span></td>";
} else {
echo "<td> <span title='true_logo'><img src='url('images/0-icon.png')'height='20' width='20'></span></td>";
}
this works for me
if(($data->Prophylaxis_Indicated)==1){
echo "
<td>
<span title='true_logo'>
<img src='/../images/1-icon.png' height='20' width='20'>
</span>
</td>";
}
else{
echo "<td> <span title='true_logo'>
<img src='/../images/0-icon.png' height='20' width='20'>
</span></td>";
}
i think the problem is you are trying to use blade syntax in controller.
use this code this will work
if(($data->Prophylaxis_Indicated)==1){
echo " <td><span title='true_logo'>
<img src='images/1-icon.png'
height='20' width='20'>
</span></td>";
}
else{
echo "<td> <span title='true_logo'>
<img src='images/0-icon.png'
height='20' width='20'>
</span></td>";
}
Use double underscore so it may not cz syntax error
src="url('images/0-icon.png')"
instead
src='url('images/0-icon.png')'
here i want to pass a dynamic variable '$cost' to another php page 'onewaytrip_passanger_data.php', through dynamically generated href link image. The code for href link image write into php tag
This is my code. but it is not working..
<?php
$cost=$row['fare'];
echo '<img src="images/bookbutton.png" width="85" height="20" />';
?>
Change this :
echo '<img src="images/bookbutton.png" width="85" height="20" />';
to
echo '<img src="images/bookbutton.png" width="85" height="20" />';
use this instead:
echo '<img src="images/bookbutton.png" width="85" height="20" />';
echo "<img src=\"images/bookbutton.png\" width="85" height="20" />";
or
echo "<img src=\"images/bookbutton.png\" width="85" height="20" />";
Always keep yourself confuse free. What is the need to do echo anchor tag. When, it can be done like this way.
Now, try.
<?php $cost=$row['fare'];?>
<a href="onewaytrip_passenger_data.php?fare=<?echo $cost;">
<img src="images/bookbutton.png" width="85" height="20" />
</a>
I am creating a row of "product related table of x5" and using MYSQLcode RAND to generate RANDOM products and a exception clause using id!='$id' - where id is existing product that is being viewed currently.
However the problem is that all the product images generated were all of the same similar product image.
Can anyone shed some light on this?
Pic for better reference:
include "MyOnlineStore/storescripts/connect_to_mysql.php";
$sql2 = mysql_query("SELECT * FROM bag WHERE id!='$id'ORDER BY RAND()LIMIT 5");
$productCount2 = mysql_num_rows($sql2); // count the output amount
if ($productCount2 > 0) {
?>
<table border="1">
<tr>
<?php
while ($row2 = mysql_fetch_array($sql2)) {
$idrelated = $row2["id"];
$imagerelated = $row2["image"];
$titlerelated = $row2["title"];
}
} else {
echo "That item does not exist.";
exit();
}
mysql_close();
HTML
<table border="1">
<tr>
<td>
<a href="http://example.net/product.php?id=<?php echo $idrelated; ?>">
<img src="admin/product/uploaded_files/<?php echo $imagerelated; ?>" width="100" height="100" alt="<?php echo $titlerelated; ?>" />
</a>
</td>
<td>
<a href="http://example.net/product.php?id=<?php echo $idrelated; ?>">
<img src="admin/product/uploaded_files/<?php echo $imagerelated; ?>" width="100" height="100" alt="<?php echo $titlerelated; ?>" />
</a>
</td>
<td>
<a href="http://example.net/product.php?id=<?php echo $idrelated; ?>">
<img src="admin/product/uploaded_files/<?php echo $imagerelated; ?>" width="100" height="100" alt="<?php echo $titlerelated; ?>" />
</a>
</td>
<td>
<a href="http://example.net/product.php?id=<?php echo $idrelated; ?>">
<img src="admin/product/uploaded_files/<?php echo $imagerelated; ?>" width="100" height="100" alt="<?php echo $titlerelated; ?>" />
</a>
</td>
<td>
<a href="http://example.net/product.php?id=<?php echo $idrelated; ?>">
<img src="admin/product/uploaded_files/<?php echo $imagerelated; ?>" width="100" height="100" alt="<?php echo $titlerelated; ?>" />
</a>
</td>
</tr>
</table>
Your code should be something like this
include "MyOnlineStore/storescripts/connect_to_mysql.php";
$sql2 = mysql_query("SELECT * FROM bag WHERE id!='$id'ORDER BY RAND()LIMIT 5");
$productCount2 = mysql_num_rows($sql2); // count the output amount
if ($productCount2 > 0) {
?>
<table border="1">
<tr>
<?php
while ($row2 = mysql_fetch_array($sql2)) {
$idrelated = $row2["id"];
$imagerelated = $row2["image"];
$titlerelated = $row2["title"];
?>
<td>
<a href="http://example.net/product.php?id=<?php echo $idrelated; ?>">
<img src="admin/product/uploaded_files/<?php echo $imagerelated; ?>" width="100" height="100" alt="<?php echo $titlerelated; ?>" />
</a>
</td>
<?php
}
?>
</tr>
</table>
As far as I can see from your code, the following variables:
$idrelated, $imagerelated, $titlerelated
remains unchanged after leaving the loop. So in each line you refer to the same variable and value.
If you want to keep use some array to keep all five values:
<?php
$index = 0;
while (...) {
$relatedA[$index] = ...;
$relatedB[$index] = ...;
$relatedC[$index] = ...;
$index++;
}
?>
...
<?php echo $relatedA[0]; ?>
<?php echo $relatedA[1]; ?>
...
<?php echo $relatedA[4]; ?>
The last you can put in the loop again to avoid redundant code.
UPDATE
Try to resist the temptation of putting echoes into the first loop where you fetch values - as it could result in hard to maintenance spaghetti-style code (unfortunately quite commonly seen in many php sources).
I have the following string where I want to remove everything between the following tags including those tags:
<br> and the </span>
<a class='interactive' href='http://mathbench.umd.edu/modules/microbio_counting-methods/page01.htm' target='_blank' alt='Counting bacteria' >Counting bacteria<br><span class='attribute'> - University of Maryland</span></a>
I have tried preg_replace('/<br>.*?</a>/', '', $link) but that seems to remove the href...
Any ideas how I should do this?
EDIT:
After using:
preg_replace('/<br>.*?<\/span>/', '', $link)
I now see in the source:
<tr>
<td><a class='interactive' href='http://www.proteinatlas.org/' target='_blank' alt='The protein atlas' >The protein atlas<br><span class='attribute'> - Uppsala Univeristät</td>
<td width='16' align='center' valign='middle'><a class='delete_link' href='#' data_link='%3Ca+class%3D%27interactive%27+href%3D%27http%3A%2F%2Fwww.proteinatlas.org%2F%27+target%3D%27_blank%27+alt%3D%27The+protein+atlas%27+%3EThe+protein+atlas%3Cbr%3E%3Cspan+class%3D%27attribute%27%3E+-+Uppsala+Univerist%C3%A4t' data_topic='161' data_introduction=''><img src="../images/delete.png" width="16" height="16" alt="delete" title="delete this link" border='0' /></a></td>
</tr>
<tr>
<td> funded by the Knut and Alice Wallenberg Foundation</span></a></td>
<td width='16' align='center' valign='middle'><a class='delete_link' href='#' data_link='+funded+by+the+Knut+and+Alice+Wallenberg+Foundation%3C%2Fspan%3E%3C%2Fa%3E' data_topic='161' data_introduction=''><img src="../images/delete.png" width="16" height="16" alt="delete" title="delete this link" border='0' /></a></td>
</tr>
Edit: Also tried;
preg_replace('/<br><span class=\'attribute\'>.*?<\/span>/', '', $link)
but problem persists.
EDIT
Still see the source showing as:
<a class='interactive' href='http://www.tinyurl.com/immunologygame/' target='_blank' alt='Innate Immunology game' >Innate Immunology game<br><span class='attribute'> - University of Ballarat</span></a>
Try this :
<?php
$str = "<a class='interactive' href='http://mathbench.umd.edu/modules/microbio_counting-methods/page01.htm' target='_blank' alt='Counting bacteria' >Counting bacteria<br><span class='attribute'> - University of Maryland</span></a>";
$r = '/<br>(.+?)<\/span>/';
$str = preg_replace($r, '', $str);
echo $str;
?>
Output :
<a class='interactive' href='http://mathbench.umd.edu/modules/microbio_counting-methods/page01.htm' target='_blank' alt='Counting bacteria' >Counting bacteria</a>
Demo : http://regexr.com?33s84
Try this
$str = "<a class='interactive' href='http://mathbench.umd.edu/modules/microbio_counting-methods/page01.htm' target='_blank' alt='Counting bacteria' >Counting bacteria<br><span class='attribute'> - University of Maryland</span></a>";
echo htmlspecialchars(preg_replace('#(<a[^>]+?>)([^<>]+).*#i', '$1$2</a>', $str));
Just use this short pattern:
/<br>.*?<\/span>/
The output will be something like this:
<a class='interactive' href='http://mathbench.umd.edu/modules/microbio_counting-methods/page01.htm' target='_blank' alt='Counting bacteria' >Counting bacteriabla</a>
Why am I getting an undefined under the large photo when I click on a thumbnail here and how do I fix this? I have tried commenting out everything here to no effect? Here is the code and a URL for review:
http://tinyurl.com/6pbkhg7
<td><div id="loadarea" style="width: 400px; height: 300px;">
<img width="400" height="300" src="http://www.mydomain.com/feeds/fmfl/rets_images/<?php echo(rawurlencode($row['ListingRid'])); ?>_1.jpg" alt="<?php echo(rawurlencode($row['MLNumber'])); ?>" align="left" border="0">
</div>
<?
$image = "<br>";
$ListingRid = $row['ListingRid'];
$img_cnt = 1;
//$image .= "<img src=/feeds/fmfl/rets_images/{$ListingRid}_1.jpg alt='' width='100' height='75' border='0' /> ";
for ($c=1;$c<10;$c++) {
if ($c<10)
$c_ext = $c;
else
$c_ext = $c;
if (file_get_contents("http://www.mydomain.com/feeds/fmfl/rets_images/{$ListingRid}_{$c_ext}.jpg"))
$image .= "<img src=/feeds/fmfl/rets_images/{$ListingRid}_{$c_ext}.jpg alt='' width='100' height='75' border='0' /> ";
else
$c=12;
$img_cnt++;
if ($img_cnt == 5) {
$image .= "<br>";
$img_cnt = 0;
}
}
?>
Because you are missing the title tag
try this with title:
$image .= "<img src=/feeds/fmfl/rets_images/{$ListingRid}_{$c_ext}.jpg alt='' width='100' height='75' border='0' /> ";
or this without title:
$image .= "<img src=/feeds/fmfl/rets_images/{$ListingRid}_{$c_ext}.jpg alt='' width='100' height='75' border='0' /> ";
lightbox requires a title, you should set title="" if you don't want anything there.