473,382 Members | 1,396 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,382 software developers and data experts.

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 1493
In article <11**********************@m73g2000cwd.googlegroups .com>,
"elia" <jo****@pcl.chwrote:
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$montant1 </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\">$quantite1</td>
<td align=\"right\">$m</td>
</tr>");
}
--
PETER FOX Not the same since the e-commerce business came to a .
pe******@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Oct 9 '06 #4
In article <11*********************@c28g2000cwb.googlegroups. com>,
"elia" <jo****@pcl.chwrote:
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('display_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\">$quantite1</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\">$quantite1</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*******@attglobal.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
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....
15
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
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
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...
3
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...
1
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...
7
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 =...
0
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
by: arunbojan | last post by:
Dear All, Please advice me some tips in ASP.NET to make tabel attractive..... Arun
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.