473,387 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

If Statement Problem

Hi,

I have a page that has several stories that run on it from a mysql
database. Right now I use this code:
<img src="Images/NewsPics/<?php echo $row["id"];?>.jpg" border="1"to
display the image.

BUT I have added a column to the database with 1 or 2 (1=has pic, 2=no
pic). I would like to use an IF STATEMENT - so that:
<?php
if (<?php echo $row["PicNumber"];?== "2") {
echo "";
} else {
echo "<img src="Images/NewsPics/<?php echo $row["id"];?>.jpg"
border="1">";
}
?>

But I can't seem to embed the <?php echo $row["PicNumber"];?within
the PHP statement.

What am I doing wrong here? Any help would be much appreciated
Thanks

Oct 30 '06 #1
4 1588
On 30 Oct 2006 10:06:04 -0800, "bokke" <mi*****@gmail.comwrote:
><?php
if (<?php echo $row["PicNumber"];?== "2") {
echo "";
} else {
echo "<img src="Images/NewsPics/<?php echo $row["id"];?>.jpg"
border="1">";
}
?>

But I can't seem to embed the <?php echo $row["PicNumber"];?within
the PHP statement.

What am I doing wrong here? Any help would be much appreciated
You're already in PHP, so you don't need another <?php tag; you don't want to
be trying to print PHP code into other PHP code, it really just does not work
like that.

Surely you mean:

<?php
if ($row['PicNumber'] == '2')
{
echo '';
}
else
{
echo '<img src="Images/NewsPics/' . $row['id'] . '.jpg" border="1">';
}
?>

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Oct 30 '06 #2
Hi Andy,

I had tried that before without success - but it gave me another idea -
and it worked ...

<?php
if ($row['picture'] == '1')
{
echo '<img src="Images/NewsPics/' . $row['id'] . '.jpg"
border="1">';
}

else
{
echo '';

}

?>

for some reason the other way round fails ...

thanks a lot for the help

Oct 30 '06 #3
..oO(bokke)
>else
{
echo '';

}
You can remove this.

Micha
Oct 30 '06 #4
["Followup-To:" header set to comp.lang.php.]
bokke wrote:
I have a page that has several stories that run on it from a mysql
database. Right now I use this code:
<img src="Images/NewsPics/<?php echo $row["id"];?>.jpg" border="1">
|-------- HTML --------||------- PHP --------||--- HTML ----|

to display the image.

BUT I have added a column to the database with 1 or 2 (1=has pic, 2=no
pic). I would like to use an IF STATEMENT
The only part of your code above that is PHP if the bit with the
filename. You need to make the PHP bigger.

<?php
echo '<img src="Images/NewsPics/'; // previous HTML
echo $row["id"]; // previous PHP
echo '.jpg" border="1">'; // previous HTML
?>
<?php
if (<?php echo $row["PicNumber"];?== "2") {
echo "";
} else {
echo "<img src="Images/NewsPics/<?php echo $row["id"];?>.jpg"
border="1">";
}
?>
and make your IF STATEMENT encompass all of the image

<?php // This snippet is incomplete. It does not 'work'

if ( /* something here */ ) {

echo '<img src="Images/NewsPics/';
echo $row["id"];
echo '.jpg" border="1">';

}
?>
But I can't seem to embed the <?php echo $row["PicNumber"];?within
the PHP statement.
You can't embed PHP within PHP. All the code above is PHP right now.
There is no need to "reenter" PHP mode.

<?php

if ($row["PicNumber"] == 1) {

echo '<img src="Images/NewsPics/';
echo $row["id"];
echo '.jpg" border="1">';

} else {
// no <img ...written to the browser
}
?>
Thanks
You're very welcome. Hope this helps.

--
I (almost) never check the dodgeit address.
If you *really* need to mail me, use the address in the Reply-To
header with a message in *plain* *text* *without* *attachments*.
Oct 30 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: DLP22192 | last post by:
I have the following single-line if statement that is evaluating true even though it shouldn't. I have never seen this before and I am concerned that this can happen in other areas of my code. ...
7
by: mark | last post by:
Access 2000: I creating a report that has a record source built by the user who selects the WHERE values. An example is: SELECT * FROM CHARGELOG WHERE STDATE Between #10/27/2003# And...
11
by: Colleyville Alan | last post by:
I posted that I was having trouble with a SQL statement that was working in the SQL window, but not in VBA. I have since discovered that when I create the string in VBA it is over 1023 characters...
3
by: Andy_Khosravi | last post by:
I have been trying to build a user friendly search engine for a small database I have created. I'm having some particular problems with one of my date fields. Here's the setup: I'm using...
9
by: Michael | last post by:
Hi all, I would like to get people's opinion about executing SQL statements in C# (or any other .NET language really). I used to create my SQL statement by building a string and replacing single...
5
by: | last post by:
I have a module that's processed as an include file in a tradtional asp application that I'm migrating to dotnet. In one of the modules, there's an if statement that's gotten appended to over...
3
by: Neil Zanella | last post by:
Hello, I am trying to execute ADO.NET INSERT statement where one of the fields is coming from a password HTML control. When I access the text with password.Value and print with Response.Write...
2
by: Rajat Katyal | last post by:
Hi: I prepare the statement for execution as follows: PREPARE query(text) as SELECT count(*) FROM transform_customer_billing where inv_no = $1; The problem is Iam not able to execute this...
6
by: Twobridge | last post by:
I hope someone can help me out with my problem. I have found a sql statement that basically pulls all bills filed within a certain time period and the payments made on those bills with in the...
3
by: Eric Davidson | last post by:
DB2 9.5 I keep geting the message. SQL0101N The statement is too long or too complex. SQLSTATE=54001 When one of my sql statements takes over 60 seconds to compile the sql statement. Is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.