|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Dynamic Tables in PHP
This may seem elementary to some, but I'm just learning php and I need some help.
I'm creating a Photo Gallery for a website and I want to be able to make a standard template and let php handle the rest. Right now, I'm using an array to hold all of the information needed for the gallery including the filenames of the images. PHP Code:
Here's an example of what I've got so far. http://www.rockshotzinc.com/gallery-...k=TSO&pic=img1 Can anyone help me out. |
|
#2
|
||||
|
||||
|
Re: Dynamic Tables in PHP
Instead of using an array to hold all of the information, why not use a MySQL (or some other) database? It would be much easier I think, for when you have many more photos to organize in your photo gallery.
Once you have a database setup, just setup the tables in HTML and have PHP code within the table to echo the <a href=" "><img /></a> code and setup a config section that will define how many images you want per page. If I have some time later I will edit this post with an example of what I mean. It is slightly more complex than what you are looking at right now, but in the long run, once you get into more advanced PHP it ill be much more simpler. EDIT: Ok, here is some basic code. Anything that is in CAPS would be a MySQL column or row. PHP Code:
Last edited by SamC : 24-06-2007 at 02:25. |
|
#3
|
|||
|
|||
|
Re: Dynamic Tables in PHP
Thanks for the fast reply.
I decided not to use a database quite yet because I haven't learned a lot about them, and every time I try to use databases, I end up failing for some reason and I can't troubleshoot because I have no idea what I'm looking at. I've run into some trouble again with databases. Could you show me a sample of the connection configuration you would use. I specified localhost as my server and then 127.0.0.1 and neither worked. Also, What does the database structure look like. I created a database with a table called picture. what columns do I need to have for your script to work. I do want to learn from this, so I'm not asking you to write this all for me, but I need some examples to learn from. Thanks again |
|
#4
|
||||
|
||||
|
Re: Dynamic Tables in PHP
First of all, you gotta make sure you have MySQL running on your server.
If you have it in a hosted server, prolly MySQL is already OK. All you have to do is get the required info, like the server Addres, user, and password. (normally they are available when you log into a CP or something) If you are trying to run your application on your own computer, things get a little bit more difficult. You must do all the instalation and configuration steps and make sure it's working. I don't remember all the steps now, but its not hard to google tutorials with this kind of info. I'll wait for you to answer and explain a little better how you are running your system and then I'll help. |
|
#5
|
||||
|
||||
|
Re: Dynamic Tables in PHP
Quote:
First of all, PHP has a bunch of built in functions that allow for many things to happen with MySQL. You can see all of those here scroll towards the botton for all of the function or search for "Innehållsförteckning". The way I setup the MySQL connect in the script above is this. PHP Code:
First, create a MySQL database and call is 'FRC_0048_gallery' (I used FRC_0048 because you need a unique name since you are most likely on a shared server) Then within the database 'FRC_0048_gallery' create a column with the name of 'PICTURES' Then create 2 rows called 'PICTURE_URL' and 'PICTURE_DATE' Then using all of that, it comes together to make a PHP script that looks like this PHP Code:
|
|
#6
|
|||||
|
|||||
|
Re: Dynamic Tables in PHP
If you want to get serious with PHP and MySQL, install Apache on your computer, and then install PHP, MySQL, and PHPmyAdmin. I'd suggest XAMPP, since it's an all-in-one package.
Once you get going, you should be able to fire up your browser (Firefox of course! ) and type in http://localhost/ or http://localhost:8080/ into the address bar and see what the server on your computer is doing. Next, use PHPmyAdmin (through your web browser) to set up some test MySQL database tables.Once these are created, you can write and execute PHP files on your own computer, and test all your database scripts on your computer instead of having to FTP every file to a remote server to test it. It looks like Sam has the actual coding-end pretty much wrapped up for a simple demo, so I'll leave that to them. ![]() |
|
#7
|
|||
|
|||
|
Re: Dynamic Tables in PHP
Thanks for all your help guys. I've gotten really far with what you've given me.
I'll post a link once I get something assembled. ![]() |
|
#8
|
||||
|
||||
|
Re: Dynamic Tables in PHP
PHP Code:
(i love arrays <3) and sam, it would be more efficient to use a LIMIT statement in your SQL query to limit the rows listed (and you can do pages with that too). Last edited by Uberbots : 27-06-2007 at 11:22. Reason: sql |
|
#9
|
||||
|
||||
|
Re: Dynamic Tables in PHP
Quote:
With the database limit it would be, PHP Code:
|
|
#10
|
|||
|
|||
|
Re: Dynamic Tables in PHP
Seems I've run into a small snag. The counter for the gallery view leaves out a photo. It counts 1 to 5 then skips 6 and goes to 7. Any ideas on why or how I can fix that.
PHP Code:
I want to create a page that shows only one picture. How do I call that one picture with a URL string. Ex. index.php?photo=25 I've tried to think that out all night, and I've gotten nowhere Last edited by FRANK(WGH) : 04-07-2007 at 12:23. Reason: Screwed up the code and want to add something. |
|
#11
|
|||
|
|||
|
Re: Dynamic Tables in PHP
I figured out the second part of my last post.
I added where id = $photo into the query. $photo is defined in the URL. index-test.php?link=web&photo=5 PHP Code:
I'm still stumped on the first part of my last post though. |
|
#12
|
|||
|
|||
|
Re: Dynamic Tables in PHP
Any ideas on why the math is off by one?? I've really been getting frustrated with it. I've tried a few different things, and nothing seems to be fixing my problem.
|
|
#13
|
||||||
|
||||||
|
Re: Dynamic Tables in PHP
F, I'm just a dumb C-programmer (emphasis on dumb), but I think you are "wasting" a fetch of the Picture 6 data at the entry to the while loop before your final end of row check (if counter == limit) takes place within the loop. You read the data but then your limit check kicks in, starts a new row, and resets the counter before anything is done with that data. You then exit the while loop and reenter it, fetching Pic 7 data, which becomes the first entry in your new row.
If you change your loop to look like this....... PHP Code:
Last edited by Travis Hoffman : 09-07-2007 at 16:10. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Online Engineering Tables | SuperJake | Math and Science | 4 | 07-04-2005 14:07 |
| Look Up Tables | amateurrobotguy | Programming | 7 | 09-03-2005 00:14 |
| Dynamic Linking with PHP | plutonium83 | Website Design/Showcase | 6 | 12-01-2005 19:41 |
| Large Lookup Tables | Mr. Lim | Programming | 5 | 16-02-2004 21:30 |
| Tables in pits? | Rickertsen2 | Regional Competitions | 2 | 23-03-2003 12:42 |