473,699 Members | 2,745 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 1504
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
108446
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
2630
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
5948
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
1896
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
1985
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
1792
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
1847
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
1517
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
1149
by: arunbojan | last post by:
Dear All, Please advice me some tips in ASP.NET to make tabel attractive..... Arun
0
8686
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
9033
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8882
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
7748
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...
0
5872
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
4375
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...
0
4627
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3057
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2345
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.