hand-coded, works but not how i want it 2-full code & my

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

hand-coded, works but not how i want it 2-full code & my

Post by malcolmboston »

ok, i started developing a gallery system today that basically could be done in html but i dont want my server having 30000000 useless pages, so i started developing a PHP/MySQL gallery and its nearly finished heres all the code

MySQL Infrastructure

Code: Select all

CREATE TABLE details (
  filepath varchar(100) NOT NULL default '',
  filename varchar(30) default NULL,
  person varchar(30) NOT NULL default '',
  resolution varchar(12) default NULL,
  pictureID varchar(4) NOT NULL default '',
  rating varchar(5) default NULL,
  thumbnail varchar(100) NOT NULL default '',
  status varchar(100) NOT NULL default '',
  filesize smallint(5) unsigned NOT NULL default '0',
  UNIQUE KEY filename (filename,filepath)
) TYPE=MyISAM;
PHP Code

Code: Select all

<?php session_start();
?>
<html>
<head>
<title>Personal Gallery</title>
</head>
<body>
<?php
// database variables for connections 
$host = "localhost"; 
$user = "malcolmboston"; 
$password = "xxxxxxx"; 
$DBname = "gallery"; 
$tablename = "details"; 
//connection variables completed 
// establishing connections 
$link = mysql_connect ($host, $user, $password); 
//connection established 
//the query defined 
$query = "SELECT * FROM details"; 
// select the database 
mysql_select_db($DBname); 
// query the database 
$result = mysql_query($query); 
$data = mysql_fetch_array($result, MYSQL_ASSOC);
while ($row = mysql_fetch_assoc($result))
print "
<table width=100% border=0 cellspacing=0 cellpadding=0>
  <tr>
    <td><img src=$row[thumbnail]></td>
    <td><img src=$row[thumbnail]></td>
    <td><img src=$row[thumbnail]></td>
    <td><img src=$row[thumbnail]></td>
  </tr>
  <tr>
    <td><strong><div align=center>$row[person]</div><strong></td>
    <td><strong><div align=center>$row[person]</div><strong></td>
    <td><strong><div align=center>$row[person]</div><strong></td>
    <td><strong><div align=center>$row[person]</div><strong></td>
  </tr>
  <tr>
    <td>resolution - $row[resolution]</td>
    <td>resolution - $row[resolution]</td>
    <td>resolution - $row[resolution]</td>
    <td>resolution - $row[resolution]</td>
  </tr>
  <tr>
    <td>file size - $row[filesize]kb</td>
    <td>file size - $row[filesize]kb</td>
    <td>file size - $row[filesize]kb</td>
    <td>file size - $row[filesize]kb</td>
  </tr>
</table>";
?> 
</body>
</html>
now as you can see from the HTML the site should look like this

PICTURE 1 PICTURE 2 ----------> picture 4
name name
resolution resolution
file size file size

PICTURE 5 --------------------------> PICTURE 8 etc

but it all appears the same like this:
PICTURE 1 PICTURE 1 PICTURE PICTURE 1
name etc etc
PICTURE 2 PICTURE 2 PICTURE 2

so basically it is only repeating on the next row, i have tried various HTML setups but cannot get this effect however i know it can be done because google does it (not with PHP but nevertheless)

any ideas guys?
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

can it be done?
User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

Post by phpcoder »

try this one

Code: Select all

<table width=100% border=0 cellspacing=0 cellpadding=0> 
while ($row = mysql_fetch_assoc($result)) 

&#123;?>
  <tr> 
    <td> 
       <img src=$row&#1111;thumbnail]><br>
        <strong><div align=center>$row&#1111;person]</div><strong><br>
        resolution - $row&#1111;resolution] <br>
        file size - $row&#1111;filesize]kb
</td> 

 </tr> 
<? &#125; ?>
</table>
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

somehow you have to increment the query, so it returns
thumbnail1, thumbnail2, thumbnail3, ect....
and so on.....

but i'm not sure how you would do it the way yuo have it set up, but then you have the obstacal of splitting them up into rows of four
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

hmmm sounds quite complex

still not entirely sure how to do it

my books say nothing about it either, neither does PHP manual
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

is there anything that could rip rows out like row[0] row[1] etc

cant remember what the hell it is called though

how could i use that? or just tell me what its called any ill go find out
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

Is there any reason why you can't process each row before moving onto the next one and using <br> instead of having individual table cells?

e.g. Your HTML output for each image would look something like this...

Code: Select all

<td>
    <img src="whatever.jpg">
    <br>
    Person
    <br>
    Resolution
    <br>
    Filesize
</td>
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

dull1554 wrote:somehow you have to increment the query, so it returns
thumbnail1, thumbnail2, thumbnail3, ect....
and so on.....

but i'm not sure how you would do it the way yuo have it set up, but then you have the obstacal of splitting them up into rows of four
ok then, how would you recommend i do it?
User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

Post by phpcoder »

buddy try this one

Code: Select all

i=0
j=1
while ($row = mysql_fetch_array($result) ) 
 &#123;
 
      $my_arr&#1111;i]&#1111;1]=$row&#1111;0]
      $my_arr&#1111;i]&#1111;2]=$row&#1111;1]

      $my_arr&#1111;i]&#1111;3]=$row&#1111;2]

      $my_arr&#1111;i]&#1111;4]=$row&#1111;3]

      $i++;
            

  
&#125;



//Now to display 

for($k=0;k<=$i;$k+4)
  &#123;?>
       <table width=100% border=0 cellspacing=0 cellpadding=0> 
  <tr> 
    <td><img src=my_arr&#1111;$k]&#1111;1]></td> 
    <td><img src=my_arr&#1111;$k+1]&#1111;1]></td> 
    <td><img src=my_arr&#1111;$k+2]&#1111;1]></td> 
    <td><img src=my_arr&#1111;$k+3]&#1111;1]></td> 
  </tr> 
  <tr> 
    <td><strong><div align=center>my_arr&#1111;$k]&#1111;2]</div><strong></td> 
    <td><strong><div align=center>my_arr&#1111;$k+1]&#1111;2]/div><strong></td> 
    <td><strong><div align=center>$my_arr&#1111;$k+2]&#1111;2]</div><strong></td> 
    <td><strong><div align=center>my_arr&#1111;$k+3]&#1111;2]</div><strong></td> 
  </tr> 
  <tr> 
    <td>resolution - my_arr&#1111;$k]&#1111;3]</td> 
    <td>resolution - my_arr&#1111;$k+1]&#1111;3]</td> 
    <td>resolution - my_arr&#1111;$k+2]&#1111;3]</td> 
    <td>resolution - my_arr&#1111;$k+3]&#1111;3]</td> 
  </tr> 
  <tr> 
    <td>file size - my_arr&#1111;$k]&#1111;4]kb</td> 
    <td>file size - my_arr&#1111;$k+1]&#1111;4]kb</td> 
    <td>file size - my_arr&#1111;$k+2]&#1111;4]kb</td> 
    <td>file size - my_arr&#1111;$k+3]&#1111;4]kb</td> 
  </tr> 
</table> 


   &#125;
hoooooooooooooooooooooo 8O
Post Reply