Go to Post I heard that the only gift UFH wants on its birthday is an inbox full of nominations. :D - Brandon Martus [more]
Home
Go Back   Chief Delphi > Technical > IT / Communications > Website Design/Showcase
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 23-06-2007, 16:02
FRANK(WGH) FRANK(WGH) is offline
Webmaster - delphielite.com
AKA: Frank
FRC #0048 (Delphi E.L.I.T.E.)
Team Role: Webmaster
 
Join Date: Nov 2001
Rookie Year: 2001
Location: Warren, OHIO
Posts: 88
FRANK(WGH) will become famous soon enough
Send a message via AIM to FRANK(WGH)
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:
$show = array ( "TSO" => array(    "title" => "Trans-Siberian Orchestra",
                                        
"folder" => "TSO/",
                                        
"date" => "11/13/05",
                                        
"img1" => "PB130055.jpg",
                                        
"img2" => "PB130069.jpg",
                                        
"img3" => "PB130124.jpg",
                                        
"img4" => "PB133303.jpg",
                                        ), 
); 
Then I create a static table with 4 columns and call it a day. I'd like the ability specify the number of images I have and let php create the table.

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.
__________________
Frank Bosak
Collegiate Mentor Association
Team 48 - Delphi E.L.I.T.E.
  #2   Spotlight this post!  
Unread 23-06-2007, 16:12
SamC SamC is offline
.
AKA: Sam Couch
FRC #0103 (Cybersonics)
Team Role: Programmer
 
Join Date: Mar 2006
Rookie Year: 2006
Location: Philadelphia, PA
Posts: 583
SamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond repute
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:
<table>
<tr> 
<?php
//config section
$column_limit 5//change to howver many columns you want
//MySQL information
$server "[insert here]"//url for the mysql server
$DBuser "[insert here]"//database username
$DBpass "[insert here]"//database password
$DB "[insert here]"//actual database name
//column counter
$column_counter 0;

$conn mysql_connect($server,$DBuser,$DBpass); //connect to server
mysql_select_db($DB); //select database
        
$query "SELECT * FROM PICTURES"//select items from column PICTURES
        
$results mysql_query($query);

while(
$row mysql_fetch_assoc($results)) 
        {
        if(
$column_counter == $column_limit)    
        {
        echo 
'</tr><tr>'//End current row, and start a new row
                
$column_counter 0//reset the column counter
        
}
        else {
        echo 
'<td><a href="' .$row[PICTURE_URL]. '" ><img src="' .$row[PICTURE_URL]. '" /></a><br>'//Echo a link to the image, and display the image as well
        
echo 'Added to gallery:' .$row[PICTURE_DATE]. '</td>'//display the dat it was added
        
$column_counter++; //Add one to the counter
        
}
        }
?>
</tr>
    </table>

Last edited by SamC : 24-06-2007 at 02:25.
  #3   Spotlight this post!  
Unread 25-06-2007, 10:56
FRANK(WGH) FRANK(WGH) is offline
Webmaster - delphielite.com
AKA: Frank
FRC #0048 (Delphi E.L.I.T.E.)
Team Role: Webmaster
 
Join Date: Nov 2001
Rookie Year: 2001
Location: Warren, OHIO
Posts: 88
FRANK(WGH) will become famous soon enough
Send a message via AIM to FRANK(WGH)
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
__________________
Frank Bosak
Collegiate Mentor Association
Team 48 - Delphi E.L.I.T.E.
  #4   Spotlight this post!  
Unread 25-06-2007, 11:44
Doliver's Avatar
Doliver Doliver is offline
Registered User
AKA: Douglas
FRC #1382 (Tribotec Team)
Team Role: Mentor
 
Join Date: Dec 2005
Rookie Year: 2006
Location: Brazil
Posts: 13
Doliver will become famous soon enough
Send a message via ICQ to Doliver Send a message via AIM to Doliver Send a message via MSN to Doliver
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.
__________________
Douglas
Junior Java Programmer
Yay! Just got hired!

Proud member of ETEP Team #1382

2007 seems to be a nice year, huh?
Regional Winners
Chairman's Award
Best Website
Judges Award at Championship


Team's Website: http://www.team1382.com

--
Contact Info
E-mail / Msn Messenger / AIM: dolliver@gmail.com
ICQ: 138190550
  #5   Spotlight this post!  
Unread 25-06-2007, 14:44
SamC SamC is offline
.
AKA: Sam Couch
FRC #0103 (Cybersonics)
Team Role: Programmer
 
Join Date: Mar 2006
Rookie Year: 2006
Location: Philadelphia, PA
Posts: 583
SamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond repute
Re: Dynamic Tables in PHP

Quote:
Originally Posted by FRANK(WGH) View Post
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.
OK, so the connection configuration.
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:
$server "[insert here]"//url for the mysql server
$DBuser "[insert here]"//database username
$DBpass "[insert here]"//database password

$conn mysql_connect($server,$DBuser,$DBpass); //connect to server 
That part is pretty straightforward. For the sake of simplicity, I will show you how to setup the database structure as well.
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:
<table>
<tr> 
<?php
//config section
$column_limit 5//change to howver many columns you want
//MySQL information
$server "[insert here]"//url for the mysql server
$DBuser "[insert here]"//database username
$DBpass "[insert here]"//database password
$DB "FRC_0048_gallery"//actual database name
//column counter
$column_counter 0;

$conn mysql_connect($server,$DBuser,$DBpass); //connect to server
mysql_select_db($DB); //select database
        
$query "SELECT * FROM PICTURES"//select items from column PICTURES
        
$results mysql_query($query);

while(
$row mysql_fetch_assoc($results)) 
        {
        if(
$column_counter == $column_limit)    
        {
        echo 
'</tr><tr>'//End current row, and start a new row
                
$column_counter 0//reset the column counter
        
}
        else {
        echo 
'<td><a href="' .$row[PICTURE_URL]. '" ><img src="' .$row[PICTURE_URL]. '" /></a><br>'//Echo a link to the image, and display the image as well
        
echo 'Added to gallery:' .$row[PICTURE_DATE]. '</td>'//display the dat it was added
        
$column_counter++; //Add one to the counter
        
}
        }
?>
</tr>
    </table>
  #6   Spotlight this post!  
Unread 26-06-2007, 00:20
artdutra04's Avatar
artdutra04 artdutra04 is offline
VEX Robotics Engineer
AKA: Arthur Dutra IV; NERD #18
FRC #0148 (Robowranglers)
Team Role: Engineer
 
Join Date: Mar 2005
Rookie Year: 2002
Location: Greenville, TX
Posts: 3,078
artdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond repute
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.
__________________
Art Dutra IV
Robotics Engineer, VEX Robotics, Inc., a subsidiary of Innovation First International (IFI)
Robowranglers Team 148 | GUS Robotics Team 228 (Alumni) | Rho Beta Epsilon (Alumni) | @arthurdutra

世上无难事,只怕有心人.
  #7   Spotlight this post!  
Unread 27-06-2007, 08:20
FRANK(WGH) FRANK(WGH) is offline
Webmaster - delphielite.com
AKA: Frank
FRC #0048 (Delphi E.L.I.T.E.)
Team Role: Webmaster
 
Join Date: Nov 2001
Rookie Year: 2001
Location: Warren, OHIO
Posts: 88
FRANK(WGH) will become famous soon enough
Send a message via AIM to FRANK(WGH)
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.
__________________
Frank Bosak
Collegiate Mentor Association
Team 48 - Delphi E.L.I.T.E.
  #8   Spotlight this post!  
Unread 27-06-2007, 11:17
Uberbots's Avatar
Uberbots Uberbots is offline
Mad Programmer
AKA: Billy Sisson
FRC #1124 (ÜberBots)
Team Role: College Student
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Avon
Posts: 739
Uberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond repute
Re: Dynamic Tables in PHP

PHP Code:
echo "<table>";
foreach(
$show as $i => $d) {
  echo 
"<tr>";
  foreach(
$show[$i] as $j => $jd) {
    echo 
"<td>" $jd "</td>";
  }
  echo 
"</tr>";
}
echo 
"</table>"
with your array, that is the easiest way to do it.
(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).
__________________
A few of my favorite numbers:
175 176 177 195 230 558 716 1024 1071 1592 1784 1816
RPI 2012
BREAKAWAY

Last edited by Uberbots : 27-06-2007 at 11:22. Reason: sql
  #9   Spotlight this post!  
Unread 27-06-2007, 13:39
SamC SamC is offline
.
AKA: Sam Couch
FRC #0103 (Cybersonics)
Team Role: Programmer
 
Join Date: Mar 2006
Rookie Year: 2006
Location: Philadelphia, PA
Posts: 583
SamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond reputeSamC has a reputation beyond repute
Re: Dynamic Tables in PHP

Quote:
Originally Posted by Uberbots View Post
[php]
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).
I was going to add the LIMIT in the query, but I figured since he was just learning about MySQL and PHP, just give him little chunks at a time. Thanks for pointing that out though.

With the database limit it would be,

PHP Code:
[...CODE CUT...]
$image_limit 20//change to any number.
[...CODE CUT...]
mysql_select_db($DB); //select database
        
$query '"SELECT * FROM `PICTURES` LIMIT 0,' .$image_limit'"'//select items from column PICTURES
        
$results mysql_query($query); 
Here is a quick definition of the LIMIT command. LIMIT is used to limit the number of results returned by MySQL. It requires 2 values, X and Y. X being the first result you want (The starting position) Y being the number of results you want. I said LIMIT 0, [20] because 0 is always the lowest result in the database, so the output would be the first 20 results in your database.
  #10   Spotlight this post!  
Unread 04-07-2007, 12:20
FRANK(WGH) FRANK(WGH) is offline
Webmaster - delphielite.com
AKA: Frank
FRC #0048 (Delphi E.L.I.T.E.)
Team Role: Webmaster
 
Join Date: Nov 2001
Rookie Year: 2001
Location: Warren, OHIO
Posts: 88
FRANK(WGH) will become famous soon enough
Send a message via AIM to FRANK(WGH)
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:
$column_limit 5//change to however many columns you want
$column_counter 0;//column counter

if($column_counter == $column_limit
         {
    echo 
'</tr><tr>'//End current row, and start a new row. 
        
$column_counter 0//reset the column counter
      

Also,
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
__________________
Frank Bosak
Collegiate Mentor Association
Team 48 - Delphi E.L.I.T.E.

Last edited by FRANK(WGH) : 04-07-2007 at 12:23. Reason: Screwed up the code and want to add something.
  #11   Spotlight this post!  
Unread 05-07-2007, 10:13
FRANK(WGH) FRANK(WGH) is offline
Webmaster - delphielite.com
AKA: Frank
FRC #0048 (Delphi E.L.I.T.E.)
Team Role: Webmaster
 
Join Date: Nov 2001
Rookie Year: 2001
Location: Warren, OHIO
Posts: 88
FRANK(WGH) will become famous soon enough
Send a message via AIM to FRANK(WGH)
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:
$query  "SELECT id, title, description, path, image, date FROM photos WHERE id = $photo"
That allowed me to view the picture with id = 5.

I'm still stumped on the first part of my last post though.
__________________
Frank Bosak
Collegiate Mentor Association
Team 48 - Delphi E.L.I.T.E.
  #12   Spotlight this post!  
Unread 09-07-2007, 13:52
FRANK(WGH) FRANK(WGH) is offline
Webmaster - delphielite.com
AKA: Frank
FRC #0048 (Delphi E.L.I.T.E.)
Team Role: Webmaster
 
Join Date: Nov 2001
Rookie Year: 2001
Location: Warren, OHIO
Posts: 88
FRANK(WGH) will become famous soon enough
Send a message via AIM to FRANK(WGH)
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.
__________________
Frank Bosak
Collegiate Mentor Association
Team 48 - Delphi E.L.I.T.E.
  #13   Spotlight this post!  
Unread 09-07-2007, 16:07
Travis Hoffman's Avatar Unsung FIRST Hero
Travis Hoffman Travis Hoffman is offline
O-H
FRC #0048 (Delphi E.L.I.T.E.)
Team Role: Engineer
 
Join Date: Sep 2001
Rookie Year: 2001
Location: Warren, Ohio USA
Posts: 4,045
Travis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond repute
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:
while($row mysql_fetch_assoc($results))  

        echo 
'<td><a href="' .$row[PICTURE_URL]. '" ><img src="' .$row[PICTURE_URL]. '" /></a><br>'//Echo a link to the image, and display the image as well 
 
        
echo 'Added to gallery:' .$row[PICTURE_DATE]. '</td>'//display the dat it was added 
 
        
$column_counter++; //Add one to the counter 
 
        
if($column_counter == $column_limit)     
        { 
 
                echo 
'</tr><tr>'//End current row, and start a new row 
                
                
$column_counter 0//reset the column counter 
        
        
}
 

I believe the code will produce the desired results. Please, all html/php junkies, confirm this.
__________________

Travis Hoffman, Enginerd, FRC Team 48 Delphi E.L.I.T.E.
Encouraging Learning in Technology and Engineering - www.delphielite.com
NEOFRA - Northeast Ohio FIRST Robotics Alliance - www.neofra.com
NEOFRA / Delphi E.L.I.T.E. FLL Regional Partner

Last edited by Travis Hoffman : 09-07-2007 at 16:10.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT -5. The time now is 01:59.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi