473,748 Members | 3,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

php condition in a tabel with html and php

Hello,

I would like to show a line in a tabel in html if there is quantity of
article choosed.

My code is:

<? if ($quantite1 0) {
echo('
<tr>
<td align="left" nowrap="nowrap" >Article 1</td>
<td align="center"> <? echo $quantite1 ?</td>
<td align="center"> 20 &euro;</td>
<td align="center"< ? echo $montant1 ?&euro;</td>
</tr>');
}
else{
echo("");
}
?>

If there is no article >no line
If there is article >show the line

Problem: I can have the variable $quantite1 and $montant1 en php

Oct 9 '06 #1
9 1506
In article <11************ **********@m73g 2000cwd.googleg roups.com>,
"elia" <jo****@pcl.chw rote:
Hello,

I would like to show a line in a tabel in html if there is quantity of
article choosed.

My code is:

<? if ($quantite1 0) {
echo('
<tr>
<td align="left" nowrap="nowrap" >Article 1</td>
<td align="center"> <? echo $quantite1 ?</td>
<td align="center"> 20 &euro;</td>
<td align="center"< ? echo $montant1 ?&euro;</td>
</tr>');
}
else{
echo("");
}
?>

If there is no article >no line
If there is article >show the line

Problem: I can have the variable $quantite1 and $montant1 en php
You can't break into php code inside a echo.

Try:

echo "<td$montan t1 </td>";

And not:

echo('<td<? echo $montant1 ?</td>');
^ ^
1 2
1. Using ' means that variables won't be parsed, but printed.
2. <? ... ?is for the parsing engine, not to be used within PHP code.

--
Sandman[.net]
Oct 9 '06 #2
Thanks, but so it's my problem! If I write ...

<? if ($quantite1 0) {
echo('
<tr>
<td article1 </td>
<td $quantite1</td>
<td 20 &euro;</td>
<td $montant1 &euro;</td>
</tr>');
}
else{
echo("");
}
?>

...."$quantite1 " and "$montant1" is not take as variable php.
Until "4" ou "7" or "10" it's write "$quantite1 "
Pascal

Oct 9 '06 #3
Following on from elia's message. . .
>Hello,

I would like to show a line in a tabel in html if there is quantity of
article choosed.

My code is:
broken.
* use _double_ quotes to get $-variables rendered.
* to escape double quotes use \"
* nowrap html syntax!
* print() is same as echo()
* Euro combined with montant
* I've modified your table format to remove redundant and space
consuming bits.
// print column headings before loop
print("<tr><th> Article</th><th>Montant</th></tr>\n");
// inside the loop
if ($quantite1 0) { // ignore if no quantity
// tidy up montant for pretty printing
if(!$montant==0 ){ // assuming $montant is numeric
$m = sprintf('&euro; %6.2f",$montant ); // to nice currency string
}else{
$m='';
}
print("<tr>
<td align=\"center\ ">$quantite 1</td>
<td align=\"right\" >$m</td>
</tr>");
}
--
PETER FOX Not the same since the e-commerce business came to a .
pe******@eminen t.demon.co.uk.n ot.this.bit.no. html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.dem on.co.uk>
Oct 9 '06 #4
In article <11************ *********@c28g2 000cwb.googlegr oups.com>,
"elia" <jo****@pcl.chw rote:
Thanks, but so it's my problem! If I write ...

<? if ($quantite1 0) {
echo('
<tr>
<td article1 </td>
<td $quantite1</td>
<td 20 &euro;</td>
<td $montant1 &euro;</td>
</tr>');
}
else{
echo("");
}
?>

..."$quantite1 " and "$montant1" is not take as variable php.
Until "4" ou "7" or "10" it's write "$quantite1 "
Pascal
Read my reply again. If you use

echo('$foobar') ;

it till print a dollar sign and then foobar. If you use

echo("$foobar") ;

it will print the content of the variable $foobar. Not the difference.
--
Sandman[.net]
Oct 9 '06 #5
elia wrote:
I would like to show a line in a tabel in html if there is quantity of
article choosed.

My code is:
<? if ($quantite1 0) {
echo <<<LINE
<tr>
<td align="left" nowrap="nowrap" >Article 1</td>
<td align="center"> $quantite1</td>
<td align="center"> 20 &euro;</td>
<td align="center"> $montant1 &euro;</td>
</tr>
LINE;
//}
//else{
//echo("");
}
?>

--
File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot
Oct 9 '06 #6
Thanks but it doesn't work! Pascal

Oct 9 '06 #7
elia wrote:
Thanks but it doesn't work! Pascal
Why? What happens? What did you expect? *How* does it not work?
See http://www.php.net/string

<?php
error_reporting (E_ALL);
ini_set('displa y_errors', '1');

$quantite1 = 6;
$montant1 = 42;

### Method 1: double quote delimited string with embedded double quotes
if ($quantite1 0) {
echo "<tr>
<td align=\"left\" nowrap=\"nowrap \">Article 1</td>
<td align=\"center\ ">$quantite 1</td>
<td align=\"center\ ">20 &euro;</td>
<td align=\"center\ ">$montant1 &euro;</td>
</tr>";
}

### Method 1: double quote delimited string with embedded single quotes
if ($quantite1 0) {
echo "<tr>
<td align='left' nowrap='nowrap' >Article 1</td>
<td align='center'> $quantite1</td>
<td align='center'> 20 &euro;</td>
<td align='center'> $montant1 &euro;</td>
</tr>";
}

### Method 3: single quote delimited string with embedded double quotes
if ($quantite1 0) {
echo '<tr>
<td align="left" nowrap="nowrap" >Article 1</td>
<td align="center"> ', $quantite1, '</td>
<td align="center"> 20 &euro;</td>
<td align="center"> ', $montant1, ' &euro;</td>
</tr>';
}

### Method 4: heredoc syntax with embedded double quotes
if ($quantite1 0) {
echo <<<LINE
<tr>
<td align="left" nowrap="nowrap" >Article 1</td>
<td align="center"> $quantite1</td>
<td align="center"> 20 &euro;</td>
<td align="center"> $montant1 &euro;</td>
</tr>
LINE;
}
?>

--
File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot
Oct 9 '06 #8
elia wrote:
Hello,

I would like to show a line in a tabel in html if there is quantity of
article choosed.

My code is:

<? if ($quantite1 0) {
echo('
<tr>
<td align="left" nowrap="nowrap" >Article 1</td>
<td align="center"> <? echo $quantite1 ?</td>
<td align="center"> 20 &euro;</td>
<td align="center"< ? echo $montant1 ?&euro;</td>
</tr>');
}
else{
echo("");
}
?>

If there is no article >no line
If there is article >show the line

Problem: I can have the variable $quantite1 and $montant1 en php
Two options:

<? if ($quantite1 0) {
echo('
<tr>
<td align="left" nowrap="nowrap" >Article 1</td>
<td align="center"> ' .$ quantite1 . '</td>
<td align="center"> 20 &euro;</td>
<td align="center"> ' . $montant1 . ' &euro;</td>
</tr>');
}
else{
echo("");
}
?>

Or

<? if ($quantite1 0) {
echo("
<tr>
<td align=\"left\" nowrap=\"nowrap \">Article 1</td>
<td align=\"center\ ">$quantite 1</td>
<td align=\"center\ ">20 &euro;</td>
<td align=\"center\ ">$montant1 &euro;</td>
</tr>');
}
else{
echo("");
}
?>

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Oct 9 '06 #9
Fantastic!! It's works with the first solution. ' . $quantite1 . '
marvelous, thanks to you!! Pascal

Oct 9 '06 #10

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

Similar topics

4
108448
by: Tristan | last post by:
Is there any support for a negative condition in If statements in PHP. Some tutorials ive found say that you can use the if!(condition)cmd; syntax. however i always get an error when i use that. "Parse error: parse error, unexpected '!', expecting '(' in TMP5rsqwh3ag.php on line 13" I am runing PHP 4.3.2.
15
2632
by: Geagleeye | last post by:
Hi. I need to interpolate som data i have in my tabel. my tabel looks like this. Y X 0 0 0,026 0,037 0,003 0,038 0,005 0,064
2
5949
by: Geagleeye | last post by:
hi. im trying to interpolate som data i got in my tabel. Does any one got any code or example i could use.. hope somone want to help
4
1898
by: joh12005 | last post by:
Hello, i posted for suggestions a little idea even if it still needs further thoughts but as i'm sure you could help :) if would like to implement some kind of Condition class which i coud use to build bricks of more complex condition, conditions are based on fields by using regexp class Condition:
3
1987
by: Eus | last post by:
Ik wil uit een tabel het gehele getal halen, de waarde staat als 05612123 maar wanneer ik dit opvraag in bv. de Query Analyzer wordt de waarde gegeven als 5612123. De 0 welke ervoor staat wordt dus niet afgebeeld. De tabel in de kolom heeft als Data Type char, de Length staat op 10 en Allow Nulls staat aangevinkt. Wie kan mij helpen? Dank.
1
1794
by: Ronsol | last post by:
Hi, I want to import a XML file into SQL. But i can't find a good example to create an unique id from an higer element. I can create different tables, but a link between them not. I want to create an ID of the parent. Can somebody help me with a correct mapping schema? The xml file is : <?xml version="1.0" encoding="ISO-8859-1" ?>
7
1853
by: Kristiansj | last post by:
Hey, I am a fairly novice coder and I am having some trouble making an elegant solution to the following problem: (pseudocode) ------------ switch (something) { case (something1) tabel = tabel_1 case (something2) tabel = tabel_2 etc....
0
1522
by: Steve Kirby | last post by:
You can't ... What you might try is: desc tabe1 This will list the columns in that table. You can select what you want to pull from that way.
1
1152
by: arunbojan | last post by:
Dear All, Please advice me some tips in ASP.NET to make tabel attractive..... Arun
0
8989
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9537
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9319
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9243
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8241
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6795
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4599
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2213
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.