Forum Articles
  Welcome back Join CF
You are here You are here: Home | Forum | PHP Issues.

You are currently viewing our boards as a guest which gives you limited access to view most of the discussions, articles and other free features. By joining our Virgin Media community you will have full access to all discussions, be able to view and post threads, communicate privately with other members (PM), respond to polls, upload your own images/photos, and access many other special features. Registration is fast, simple and absolutely free so please join our community today.


Welcome to Cable Forum
Go Back   Cable Forum > Computers & IT > General IT Discussion

PHP Issues.
Reply
 
Thread Tools
Old 09-05-2009, 21:42   #1
Druchii
cf.mega poster
 
Druchii's Avatar
 
Join Date: Mar 2006
Location: Oslo, Norway.
Age: 37
Services: Canal Digital: 50/10
Posts: 7,577
Druchii has a nice shiny star
Druchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny star
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 is offline   Reply With Quote
Advertisement
Old 09-05-2009, 22:06   #2
Druchii
cf.mega poster
 
Druchii's Avatar
 
Join Date: Mar 2006
Location: Oslo, Norway.
Age: 37
Services: Canal Digital: 50/10
Posts: 7,577
Druchii has a nice shiny star
Druchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny star
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...

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...
Druchii is offline   Reply With Quote
Old 09-05-2009, 22:15   #3
punky
Inactive
 
Join Date: Jun 2003
Age: 44
Posts: 14,750
punky has a golden aurapunky has a golden aura
punky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aura
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.
punky is offline   Reply With Quote
Old 09-05-2009, 22:18   #4
Druchii
cf.mega poster
 
Druchii's Avatar
 
Join Date: Mar 2006
Location: Oslo, Norway.
Age: 37
Services: Canal Digital: 50/10
Posts: 7,577
Druchii has a nice shiny star
Druchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny star
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 View Post
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 is offline   Reply With Quote
Old 10-05-2009, 15:52   #5
Druchii
cf.mega poster
 
Druchii's Avatar
 
Join Date: Mar 2006
Location: Oslo, Norway.
Age: 37
Services: Canal Digital: 50/10
Posts: 7,577
Druchii has a nice shiny star
Druchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny star
Re: PHP Issues.

Can anyone just take a peek at it? So i can get some feedback...
http://revts.ath.cx
Password: Authentic8
Druchii is offline   Reply With Quote
Old 10-05-2009, 16:14   #6
Paul
Dr Pepper Addict
Cable Forum Admin
 
Paul's Avatar
 
Join Date: Oct 2003
Location: Nottingham
Age: 63
Services: IDNet FTTP (1000M), Sky Q TV, Sky Mobile, Flextel SIP
Posts: 30,583
Paul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered stars
Paul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered stars
Re: PHP Issues.

This makes no sense, what is it supposed to do ?

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

Baby, I was born this way.
Paul is offline   Reply With Quote
Old 10-05-2009, 16:15   #7
Druchii
cf.mega poster
 
Druchii's Avatar
 
Join Date: Mar 2006
Location: Oslo, Norway.
Age: 37
Services: Canal Digital: 50/10
Posts: 7,577
Druchii has a nice shiny star
Druchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny star
Re: PHP Issues.

Quote:
Originally Posted by Paul M View Post
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.
Druchii is offline   Reply With Quote
Old 10-05-2009, 16:19   #8
AbyssUnderground
Inactive
 
Join Date: Oct 2005
Location: Merseyside
Age: 37
Services: BT Infinity Option 2, HH5, synced at maximum 80Mbps/20Mbps.
Posts: 2,221
AbyssUnderground has reached the bronze age
AbyssUnderground has reached the bronze ageAbyssUnderground has reached the bronze ageAbyssUnderground has reached the bronze ageAbyssUnderground has reached the bronze ageAbyssUnderground has reached the bronze ageAbyssUnderground has reached the bronze ageAbyssUnderground has reached the bronze ageAbyssUnderground has reached the bronze ageAbyssUnderground has reached the bronze age
Send a message via MSN to AbyssUnderground
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.
AbyssUnderground is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 23:29.


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