|
Posted by linda on 11/01/06 18:31
"Martin Mouritzen" <martin@siteloom.dk> wrote in message
news:1vlhk291pog2fhhlcaubo32melehhhmud1@4ax.com...
> On Wed, 1 Nov 2006 15:41:42 -0000, "linda" <n0spamF0rme@tiscali.co.uk>
> wrote:
>
>>It does remove the null value, but it also removes every thing associated
>>with this entry. The name, info, id etc..
>
> Hi Linda,
>
> First of all, your problem is because you don't do anything in the if
> statement, you have to have the IF statement where you write out the
> amount or assign the value to a variable which you then use when
> printing the price.
>
> It also seems like your code is a bit unstructured, I've tab-indented
> some of the code.
>
> try to replace your code with the code I've written below and it
> should work as you want.
>
>
> [php]
> // Fetch and print all the records.
> while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
> $price = ($row['price']);
>
> print "<tr>";
> print "<td align=\"center\" valign=\"middle\">";
> print "<a
> href=\"image_window.php?id=".$row['id']."\"
> onclick=\"window.open(this.href, 'child','height=300,width=431');
> return false;\">";
> print "<img
> src=\"img/".$row['sm_pic']."\" class=\"imageborder\" />";
> print "</a>";
> print "</td>";
> print "<td>";
> print "<b>".$row['name']."</b>";
> print "<br><br>";
> print stripslashes($row['info']);
> print "<br><br>";
> print "<div class=\"".$row['name']."\">";
> if ($price) {
> print "£";
> print number_format($price,2);
> }
> print "</div>";
> print "<br><br><hr>";
> print "</td>";
> print "</tr>";
> }
> mysql_free_result($result); // Free up the resources.
> mysql_close(); // Close the database connection.
> ?>
> [/php]
>
> --
> best regards,
> Martin Mouritzen.
> http://www.siteloom.dk
Hi Martin,
Thank you for your reply, I've solved it now with a suggestion from Steve,
but thank you anyway for replying, I am very grateful. Re: the structure,
I've never been able to decide since starting to learn php whether it is
better to print the html or break out of php into html then back in again, I
do know what you mean though it does look a little messy and unstructured.
Your example definitely makes it easier to read. Point taken, and noted.
Though with that said, I'd be interested to here others views on this,
because as I've stated, I've been on the fence in deciding. And it's always
useful to know the pros and con's for both, and how others feel. This way
it will give me a better understanding of which is best. I realise that
when you need to print large amounts of html it's better to break out of php
to do it, but when it comes to the odd table I don't know which is best.
Best wishes, and warmest regards,
Linda
P.S I like your website!
[Back to original message]
|