Welcome, Guest. Please login or register.

Author Topic: PHP question..  (Read 3115 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline TheMagicMTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2857
    • Show only replies by TheMagicM
    • http://www.BartonekDragRacing.com
PHP question..
« on: July 12, 2005, 04:39:37 AM »
I'm reading a database and retrieving info.. one piece of info is a name of a file, a picture if you may.

so in html its title

I'm storing the filename in a variable in php called $picture and I will build the url (static url, only filename changes).

How would I display this as a link in PHP?
PowerMac G5 dual 2.0ghz/128meg Radeon/500gb HD/2GB RAM, MorphOS 3.9 registered, user #1900
Powerbook G4 5,6 1.67ghz/2gb RAM, Radeon 9700/250gb hd, MorphOS 3.9 registered #3143
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: PHP question..
« Reply #1 on: July 12, 2005, 04:53:48 AM »
That would be

"> .....
int p; // A
 

Offline TheMagicMTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2857
    • Show only replies by TheMagicM
    • http://www.BartonekDragRacing.com
Re: PHP question..
« Reply #2 on: July 12, 2005, 05:02:24 AM »
doh!  I knew it had to be simple.. I was trying to embed html into PHP and tha wouldnt work.. but php in html... (and I'm already doing that in the submit button..geez.. its getting late)  ... Thanks!!
PowerMac G5 dual 2.0ghz/128meg Radeon/500gb HD/2GB RAM, MorphOS 3.9 registered, user #1900
Powerbook G4 5,6 1.67ghz/2gb RAM, Radeon 9700/250gb hd, MorphOS 3.9 registered #3143
 

Offline ExtremeWays

  • Jr. Member
  • **
  • Join Date: Nov 2003
  • Posts: 81
    • Show only replies by ExtremeWays
Re: PHP question..
« Reply #3 on: July 12, 2005, 05:08:19 AM »
Or to be even cooler..


"> .....

:)
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: PHP question..
« Reply #4 on: July 12, 2005, 06:10:55 AM »
Quote

TheMagicM wrote:
doh!  I knew it had to be simple.. I was trying to embed html into PHP and tha wouldnt work.. but php in html... (and I'm already doing that in the submit button..geez.. its getting late)  ... Thanks!!


Actually the following

print(" .... ");

would be fine too. I seem to recall, however, that the first method is supposed to be slightly faster.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: PHP question..
« Reply #5 on: July 12, 2005, 08:29:57 AM »
Quote

ExtremeWays wrote:
Or to be even cooler..


"> .....

:)


True, but I prefer readability over terseness. Unless it's C of course ;-)
int p; // A
 

Offline Waccoon

  • Hero Member
  • *****
  • Join Date: Apr 2002
  • Posts: 1057
    • Show only replies by Waccoon
Re: PHP question..
« Reply #6 on: July 12, 2005, 10:13:25 AM »
Not all installs of PHP support the short tags, so you may have to use "" anyway.

Also, the "echo" command is faster than "print" for some reason.
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: PHP question..
« Reply #7 on: July 12, 2005, 10:18:41 AM »
Quote

Waccoon wrote:

Also, the "echo" command is faster than "print" for some reason.


Can't say I've ever noticed. I'd expect it to be a bit faster than printf() maybe :-)

Either way I don't imagine the difference would be something you'd need to worry about unless printing thousands of items ;-)
int p; // A
 

Offline TheMagicMTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2857
    • Show only replies by TheMagicM
    • http://www.BartonekDragRacing.com
Re: PHP question..
« Reply #8 on: July 12, 2005, 03:42:24 PM »
Quote
print(" .... ");


ok, that worked..

now to format my output.. LOL... thanks for the help..
PowerMac G5 dual 2.0ghz/128meg Radeon/500gb HD/2GB RAM, MorphOS 3.9 registered, user #1900
Powerbook G4 5,6 1.67ghz/2gb RAM, Radeon 9700/250gb hd, MorphOS 3.9 registered #3143
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: PHP question..
« Reply #9 on: July 12, 2005, 04:00:04 PM »
You can use a C style printf() in PHP too, if that helps ;-)

eg

printf("%s", $filename, $title);
int p; // A
 

Offline TheMagicMTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2857
    • Show only replies by TheMagicM
    • http://www.BartonekDragRacing.com
Re: PHP question..
« Reply #10 on: July 12, 2005, 04:32:27 PM »
yea I did that but its not formatting it like I want.. lets say for example I have a list of magazines by year, month, publisher etc.. well the months are not the same length. so I want to allocate the same amount of space for each month that way it aligns.. I know i can do str_len and figure it out and pad it but I was wondering if there was a simpler way with HTML to format output.. if no I'll do it the longer way in PHP.
PowerMac G5 dual 2.0ghz/128meg Radeon/500gb HD/2GB RAM, MorphOS 3.9 registered, user #1900
Powerbook G4 5,6 1.67ghz/2gb RAM, Radeon 9700/250gb hd, MorphOS 3.9 registered #3143
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: PHP question..
« Reply #11 on: July 12, 2005, 04:39:15 PM »
Why not use a table with as many columns as you need and align the cells, creating a row for each record?

That's pretty much the normal way of doing these things (or you could use div based spacing if you don't like tables)
int p; // A
 

Offline TheMagicMTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2857
    • Show only replies by TheMagicM
    • http://www.BartonekDragRacing.com
Re: PHP question..
« Reply #12 on: July 12, 2005, 04:47:02 PM »
thats what I was doing and it wasnt working..

just found the bug.. I was building a new table for each record read in..instead of defining it before my loop..
PowerMac G5 dual 2.0ghz/128meg Radeon/500gb HD/2GB RAM, MorphOS 3.9 registered, user #1900
Powerbook G4 5,6 1.67ghz/2gb RAM, Radeon 9700/250gb hd, MorphOS 3.9 registered #3143
 

  • Guest
Re: PHP question..
« Reply #13 on: July 12, 2005, 05:21:03 PM »
I have an idea that might help if you're interested.

Build all the data into an array, then create a loop which dumps each line into a display template to display it all.

That seperates data from formatting and makes it easier to change how you display things by just changing the HTML template rather than the PHP Code itself.

This is completely non-working code, but something such as;

Code: [Select]

while $array
{
   showitem($array[line]);
}


My big problem with Xoops is the fact that it's truly obfuscated now.  1/2 of it uses template, the other half is hard-coded HTML inside of classes of PHP code. (which sucks).

Wayne
 

Offline TheMagicMTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2857
    • Show only replies by TheMagicM
    • http://www.BartonekDragRacing.com
Re: PHP question..
« Reply #14 on: July 12, 2005, 06:48:22 PM »
good suggestion!  that will probably fix the bug I cannot seem to find.
PowerMac G5 dual 2.0ghz/128meg Radeon/500gb HD/2GB RAM, MorphOS 3.9 registered, user #1900
Powerbook G4 5,6 1.67ghz/2gb RAM, Radeon 9700/250gb hd, MorphOS 3.9 registered #3143