Center the image in PHP - php

i have this code. how i can make the image be at the center and the text make it more bigger?
if ($spell_checker->check_word($_GET['wordtext'])) {
echo '<img src="images/betul.jpg" width="100" height="100" >'.'<br />';
echo 'Tahniah, Ejaan Anda Tepat Sekali!';
}
else {
echo '<img src="images/salah.jpg" width="100" height="100">'.'<br />';
echo 'Opss.Ejaan Yang Betul Ialah: ';
print_r(implode($spell_checker->suggest($_GET['wordtext'])));
}

Related

i want to pass php variable through the dynamic href link image to another php page

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>

Multiple page ids in an array

I'm fairly new to PHP so go easy.
<?php
$body_classes = get_body_class();
$ScanL="url";
if(in_array('parent-pageid-385', $body_classes))
{
echo '<img src="'. $ScanL.'/images/product-logos/image1.gif" />';
}
else if(in_array('parent-pageid-394', $body_classes)) {
echo '<img src="'. $ScanL.'/images/product-logos/image2.gif" />';
}
else if(in_array('parent-pageid-238', $body_classes)) {
echo '<img src="'. $ScanL.'/images/product-logos/image3.gif" />';
}
else if(in_array('parent-pageid-382', $body_classes)) {
echo '<img src="'. $ScanL.'/images/product-logos/image4.gif" />';
}
else if(in_array('page-id-391', $body_classes)) {
echo '<img src="'. $ScanL.'/images/product-logos/image5.gif" />';
}
else if (in_array('page-id-334', $body_classes)) {
echo '<img src="'. $ScanL.'/images/product-logos/image6.gif" />';
}
if(in_array('parent-pageid-385', $body_classes))
I need the above to be applied to more than one page id - I tried adding , '' but that broke the code and also tried or / ||
I'm sure I'm probably missing something obvious.
Thanks,

How to echo picture using php?

Please help me with this guys,
I have this code:
if(move_uploaded_file($_FILES['userfile']['tmp_name'],"C:/xampp/htdocs/new/admin/gallery/{$_FILES['userfile']['name']}")
{
echo '<center><img src="admin/gallery/{$_FILES['userfile']['name']}" width="100" height="100"/>'.'</center>';
// echo "success!:)";
}
else
{
echo "photo not uploaded";
}
the problem here is when i echo it and use its tmpname i am having an error in this section
<img src="admin/gallery/{$_FILES['userfile']['name']}" width="100" //....
the userfile is underlined in red. Is it wrong to use its tempname in echoing it?
help me please...
Change your echo statement like this,
echo '<center><img src="admin/gallery/'.{$_FILES['userfile']['name']}.'" width="100" height="100"/>'.'</center>';
Also your if checks showing incorrectly.
May be like this,
if(move_uploaded_file($_FILES['userfile']['tmp_name'],"C:/xampp/htdocs/new/admin/gallery/{$_FILES['userfile']['name']")
{
.....
}
try with proper quoting and if()
if(move_uploaded_file($_FILES['userfile']['tmp_name'],"C:/xampp/htdocs/new/admin/gallery/".$_FILES['userfile']['name']))
{
echo '<center><img src="admin/gallery/'.$_FILES['userfile']['name'].'" width="100" height="100"/>'.'</center>';
// echo "success!:)";
}else
echo "photo not uploaded";
}
you just have a problems with your ' and "
i would do it like this
$filename = $_FILES['userfile']['name'];
echo "<center><img src='admin/gallery/{$filename}' width='100' height='100' /></center>";
this should do it
total source is
if(move_uploaded_file($_FILES['userfile']['tmp_name'],"C:/xampp/htdocs/new/admin/gallery/{$_FILES['userfile']['name']}")
{
$filename = $_FILES['userfile']['name'];
echo "<center><img src='admin/gallery/{$filename}' width='100' height='100' /></center>";
}
else
{
echo "photo not uploaded";
}
Try this. You can use php in html attributes and tags
<img src="admin/gallery/<?php {$_FILES['userfile']['name']} ?>" width="100" />
You should use:
if(move_uploaded_file($_FILES['userfile']['tmp_name'],"C:/xampp/htdocs/new/admin/gallery/{$_FILES['userfile']['name']}")
And
echo "<img src='admin/gallery/{$_FILES['userfile']['name']}' width='100'...";
or better close php with an ?>then
<img src='admin/gallery/<?php echo $_FILES['userfile']['name'];?>' width='100'...

How to show images from my sql to this table? in php

i have a pagination code in php ,i tried to show images post_images from my sql to this table in my code but nothing happen ,i tried echo '<img src= images/$post_image />';
,can you tell me please what i can do ?
my code :
<table height="200px" style="border:3px black solid;border-radius:5px" width="550px">
<tr>
<th colspan="2" height="40px" style="border-bottom:3px black solid">posts in this site</th>
</tr>
<?php
$link=mysql_connect("localhost","username","pass");
mysql_select_db("itstuff_paging",$link);
$q="select count(*) \"total\" from posts";
$ros=mysql_query($q,$link) or die(mysql_error());
$row=mysql_fetch_array($ros);
$total=$row['total'];
$dis=4;
$total_page=ceil($total/$dis);
$page_cur=(isset($_GET['page']))?$_GET['page']:1;
$k=($page_cur-1)*$dis;
$q="select * from posts limit $k,$dis";
$ros=mysql_query($q,$link);
while($row=mysql_fetch_array($ros))
{
echo '<tr>';
echo '<td width="10px" style="border-bottom:1px #a1a1a1 solid">'.$row
['post_id'].'.';
echo '<br/>';
echo '<td style="border-bottom:1px #a1a1a1 solid">'.$row['post_title'];
echo '<br/>';
echo ($row['post_content']);
echo '<br/>';
echo '<img src= images/$post_image />';
echo '</tr>';
}
echo '</table>';
echo '<br/>';
if($page_cur>1)
{
echo '<a href="index.php?page='.($page_cur-1).'"
style="cursor:pointer;color:green;" ><input style="cursor:pointer;background-
color:green;border:1px black solid;border-radius:5px;width:120px;height:30px;color:white;font-
size:15px;font-weight:bold;" type="button" value=" Previous "></a>';
}
else
{
echo '<input style="background-color:green;border:1px black solid;border-
radius:5px;width:120px;height:30px;color:black;font-size:15px;font-weight:bold;" type="button"
value=" Previous ">';
}
for($i=1;$i<$total_page;$i++)
{
if($page_cur==$i)
{
echo ' <input style="background-color:green;border:2px black
solid;border-radius:5px;width:30px;height:30px;color:black;font-size:15px;font-weight:bold;"
type="button" value="'.$i.'"> ';
}
else
{
echo '<a href="index.php?page='.$i.'"> <input style="cursor:pointer;background-
color:green;border:1px black solid;border-radius:5px;width:30px;height:30px;color:white;font-
size:15px;font-weight:bold;" type="button" value="'.$i.'"> </a>';
}
}
if($page_cur<$total_page)
{
echo '<a href="index.php?page='.($page_cur+1).'"><input
style="cursor:pointer;background-color:green;border:1px black solid;border-
radius:5px;width:90px;height:30px;color:white;font-size:15px;font-weight:bold;" type="button"
value=" Next "></a>';
}
else
{
echo '<input style="background-color:green;border:1px black solid;border-
radius:5px;width:90px;height:30px;color:black;font-size:15px;font-weight:bold;" type="button"
value=" Next ">';
}
?>
</table>
You never define $post_image before you use it, so you're generating <img src="" />. Perhaps you meant:
echo "<img src=images/{$row['post_image']} />";
instead?
Your code is malformed. Please try:
echo '<img src="images/'.$post_image.'" />';

displaying a post thumbnail depending on category in Wordpress?

Is it possible to display a specific post thumbnail image based on the category ID, something like this:
<?php if ( has_post_thumbnail() ) {
if ( cat = 2 ) {
echo '<img src="image1.jpg" width="" height="" class="live-holder-img" />';
} elseif( cat = 3 ) {
echo '<img src="image2.jpg" width="" height="" class="live-holder-img" />';
} else {
echo '<img src="default.jpg" width="" height="" class="default" />'
}
?>
You may want to look into category templates: http://codex.wordpress.org/Category_Templates
The quick solution would be something like this:
if (is_category('1')) {
echo '<img src="image1.jpg" width="" height="" class="live-holder-img" />';
} else if (is_category('2')) {
echo '<img src="image2.jpg" width="" height="" class="live-holder-img" />';
} else {
echo '<img src="default.jpg" width="" height="" class="default" />';
}
//you can also do this by name
if (is_category('Category A')) {
echo '<img src="image1.jpg" width="" height="" class="live-holder-img" />';
} else if (is_category('Category B')) {
echo '<img src="image2.jpg" width="" height="" class="live-holder-img" />';
} else {
echo '<img src="default.jpg" width="" height="" class="default" />';
}
is_category function reference: http://codex.wordpress.org/Function_Reference/is_category

Categories