Amiga.org

The "Not Quite Amiga but still computer related category" => Alternative Operating Systems => Topic started by: TheMagicM on July 12, 2005, 04:39:37 AM

Title: PHP question..
Post by: TheMagicM 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?
Title: Re: PHP question..
Post by: Karlos on July 12, 2005, 04:53:48 AM
That would be

"> .....
Title: Re: PHP question..
Post by: TheMagicM 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!!
Title: Re: PHP question..
Post by: ExtremeWays on July 12, 2005, 05:08:19 AM
Or to be even cooler..


"> .....

:)
Title: Re: PHP question..
Post by: Karlos 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.
Title: Re: PHP question..
Post by: Karlos 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 ;-)
Title: Re: PHP question..
Post by: Waccoon 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.
Title: Re: PHP question..
Post by: Karlos 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 ;-)
Title: Re: PHP question..
Post by: TheMagicM on July 12, 2005, 03:42:24 PM
Quote
print(" .... ");


ok, that worked..

now to format my output.. LOL... thanks for the help..
Title: Re: PHP question..
Post by: Karlos 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);
Title: Re: PHP question..
Post by: TheMagicM 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.
Title: Re: PHP question..
Post by: Karlos 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)
Title: Re: PHP question..
Post by: TheMagicM 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..
Title: Re: PHP question..
Post by: 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
Title: Re: PHP question..
Post by: TheMagicM on July 12, 2005, 06:48:22 PM
good suggestion!  that will probably fix the bug I cannot seem to find.