Cable Forum

Cable Forum (https://www.cableforum.uk/board/index.php)
-   General IT Discussion (https://www.cableforum.uk/board/forumdisplay.php?f=19)
-   -   PHP Issues. (https://www.cableforum.uk/board/showthread.php?t=33649814)

Druchii 09-05-2009 21:42

PHP Issues.
 
I'm having some issues using PHP to dynamically create a table...
Basically it reads imagenames from a folder, then creates a table and has 3 items per row. It creates a new row every 3 items, or should... That's the problem, the "<tr>"'s and "</tr>"'s never get printed...

Here's the code:
PHP Code:

<?php
$i 
"0";
$Folder "./Photos/";
$DirHandle = @opendir($Folder) or die($Folder." could not be opened.");
print (
"<table width=40% align=center valign=center>");
while (
$Filename readdir($DirHandle))
{
if (
== 2) print ("<tr>");
if ((
$Filename != ".") AND ($Filename != "..")) print ("<td width=200 height=200><img src=\"$Folder$Filename\" height=95% width=95%>$i</img></td>");
if (
== 2) print ("<\tr>");
if ((
$Filename != ".") AND ($Filename != "..")) ++$i;;
}
closedir($DirHandle);
print (
"</table>");
?>

Any ideas?

Also, sorry for any particularly bad code, i'm just learning ;)

Also, this can be tested at: http://revts.ath.cx while i am online (Pass: Password)

EDIT: Also, the 0 never shows beneath the first image...
EDIT2: Fixed the 0 never being shown... Code above amended (used i == instead of i =)

Druchii 09-05-2009 22:06

Re: PHP Issues.
 
if (($Filename != ".") AND ($Filename != "..")) ++$i;;
I do in that line, it works fine, and the numbers do count up, yet the html doesn't get written... :erm:

Fixed declaring as a string now too, thanks :)
EDIT: Could have sworn i saw a post by punky above this...


---------- Post added at 00:06 ---------- Previous post was yesterday at 23:54 ----------

Ah man i'm a dunce... Forgot to use the dollar sign $ before the i in the if statments to print the html...

Think i'm too tired...

punky 09-05-2009 22:15

Re: PHP Issues.
 
Yeah, I did post, but I spotted the ++$i after mine and before yours, so I deleted it. Alas too late.

The <tr>s don't get printer is because you have i instead of $i

The code is really weird though.

---------- Post added at 23:15 ---------- Previous post was at 23:13 ----------

Also, another prob I spotted... your <tr> closing tag should be </tr> not <\tr>.

A backslash within a string is a special character. In this case \t = tab.

Druchii 09-05-2009 22:18

Re: PHP Issues.
 
Fully functional (abeit badly written) code:
Code:

<?php
$i = 0;
$Folder = "./Photos/";
$DirHandle = @opendir($Folder) or die($Folder." could not be opened.");
print ("<table width=40% align=center valign=center>");
while ($Filename = readdir($DirHandle))
{
if ($i == 2) print ("<tr>");
if (($Filename != ".") AND ($Filename != "..")) print ("<td width=200 height=200><img src=\"$Folder$Filename\" height=95% width=95%>$i</img></td>");
if ($i == 2) print ("<//\tr>");
if (($Filename != ".") AND ($Filename != "..")) ++$i;;
}
closedir($DirHandle);
print ("</table>");
?>

Cheers for the pointers :)

---------- Post added at 00:18 ---------- Previous post was at 00:15 ----------

Quote:

Originally Posted by punky (Post 34792413)
Also, another prob I spotted... your <tr> closing tag should be </tr> not <\tr>.

A backslash within a string is a special character. In this case \t = tab.

That causes a problem, it seems to then spit out a </tr> tag every iteration, rather then when it should be (every 2nd).

EDIT:
Also changed the closing TR tag code to:
Code:

if ($i == 4) print ("<//\tr>") AND $i = 0;
(And modified the opening tags, it now is every 4 rather than just the first 4)

Druchii 10-05-2009 15:52

Re: PHP Issues.
 
Can anyone just take a peek at it? So i can get some feedback...
http://revts.ath.cx
Password: Authentic8

Paul 10-05-2009 16:14

Re: PHP Issues.
 
This makes no sense, what is it supposed to do ?

Quote:

if ($i == 4) print ("<//\tr>") AND $i = 0;

Druchii 10-05-2009 16:15

Re: PHP Issues.
 
Quote:

Originally Posted by Paul M (Post 34792669)
This makes no sense, what is it supposed to do ?

If the i is equal to 4 (it's looping through, increasing by 1 each time) print the tag <\tr> and reset i to 0.
Works fine, though it looks odd.

AbyssUnderground 10-05-2009 16:19

Re: PHP Issues.
 
Your coding of PHP is far different to mine thats for sure... Its not structured like I structure PHP at all. No wonder you're finding it difficult. Each function should be on its own line ideally. It makes it easy to troubleshoot.


All times are GMT. The time now is 21:52.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum