PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Oct 15, 2018 9:04 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Mon Aug 16, 2004 5:26 pm 
Offline
Forum Newbie

Joined: Mon Aug 16, 2004 5:26 pm
Posts: 1
Hello there,

I dont know if i am posting in the correct section of this forum because i am new here and in a bit of a rush to solve my problem. So if i am in the wrong section feel free to curse at me all you want, but just please help me with my problem.

The problem that i am having is trying format the display of a page that is pulling information from a MySQL database. I am creating a online photo album and i require the pictures to be displayed across the screen in rows of three instead of directly under one another (because of rows created from using html tables).

Is there any suggestions on different format options in HTML and PHP, any links to online sources would be of great help.

If my problem has not been explained well please let me know also, so that i can try explaining it more better.

Thankyou to anyone taking the time to read this.

I Reh


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 16, 2004 5:39 pm 
Offline
DevNet Resident
User avatar

Joined: Thu Feb 12, 2004 8:19 pm
Posts: 1165
Location: ohio
seems like this is not a php issue

an html issue. read up on creating tables

<tr> and <td>, consider <tr> as the columns, <td> as the seats in the columns.

Mess around, make a test table, you can do this w/o even being online.

Syntax: [ Download ] [ Hide ]
&lt;table&gt;&lt;tr&gt;&lt;td&gt;hi&lt;/td&gt;&lt;td&gt;hi&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;hi&lt;/tr&gt;&lt;/td&gt;&lt;/table&gt;


mess around with that, add pieces to it, remove pieces to it. see what does what

let us know if u have any other issues tieing it into your SQL.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 17, 2004 10:35 am 
Offline
Forum Newbie

Joined: Tue Aug 17, 2004 10:35 am
Posts: 9
Hello there Tim, or anybody else reading this post,

Its me irfreh, this forum was not letting me login with my regular username so i had to register again and login under another identitiy. Proper secret spy stuff huh.

Anyway i have tried to mess around with the table tags but i think that my problem needs to be tackled via a different route. The reason being is that as you already know, when using a table to display information pulled from a database the rows are created depending on the amount of information being pulled from the database. So when my table is creating rows it is (as it is supposed to) posting them directly under one another. This would be fine if i was displaying text information. But because i am creating an online portfolio i need images to be displayed in three's on each row.

As used in the getty images website:
link
(i gave the full link so that you dont have to mess with the search)

the code i used for my tables (just incase it is a HTML problem) is posted below.


Syntax: [ Download ] [ Hide ]
echo (\"<table>

<tr><td><img src ='pics/$img_name'></td></tr>

</table>\");

         }


Thankyou again to whoever takes the time to read this post.

I Reh


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 17, 2004 4:50 pm 
Offline
DevNet Resident
User avatar

Joined: Thu Feb 12, 2004 8:19 pm
Posts: 1165
Location: ohio
Could you post the code you use for your SQL side of things?

the table code should be placed inside a while loop, or some sort of loop. you should also be using mysql_fetch_array or something similar.

post the rest of your code.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 18, 2004 3:48 am 
Offline
Forum Newbie

Joined: Tue Aug 17, 2004 10:35 am
Posts: 9
Hello there Tim,

I am posting the code for the dispaly page only, but if you require the code for the other pages as well please let me know. I have taken out the password and username just incase of some shady forum surfers using the details for mischievous use.

Syntax: [ Download ] [ Hide ]
<?

    $usr = "****";

    $pwd = "*****";

    $db = "******";

    $host = "localhost";



    # connect to database

    $cid = mysql_connect($host,$usr,$pwd);

    if (!$cid) { echo("ERROR: " . mysql_error() . "\n");    }



?>

<HTML>

<HEAD>

  <TITLE>Test</TITLE>

</HEAD>





<?

 



    # setup SQL statement

    $SQL = " SELECT * FROM portfolio ";

    $SQL = $SQL .



    # execute SQL statement

    $retid = mysql_db_query($db, $SQL, $cid);



    # check for errors

    if (!$retid) { echo( mysql_error()); }

    else {



        # display results

        echo ("<P><DT><B>$category</B><BR>\n\n");

        while ($row = mysql_fetch_array($retid)) {

            $pic_ref = $row["pic_ref"];

            $pic_name = $row["pic_name"];

$img_name = $row["img_name"];

$pic_desc = $row["pic_desc"];

$sub_date = $row["sub_date"];

$photographer = $row["photographer"];





            echo ("<table>

</tr><td><img src ='pics/$img_name'>&nbsp;$pic_name</td></tr>

</table>"
);

         }

        echo ("</DT></P>");

    }

?>



</BODY>

</HTML>


Thanks again,
I Reh


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 18, 2004 4:07 am 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
looks like you are outputting a new table for each row returned from the query, why not make the whole thing a larger table, and stack every 3 or whatever images in <td>'s then a new <tr> if needed..

then, using the number of records found add (one less than the total images per table row you want) and use the modulo to retrieve the remainder of dividing by the total number of images per table you want.. this will give you the number to use in a colspan for the filling in the last row (if needed).. if the number is zero, you're done..


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 18, 2004 5:39 am 
Offline
Forum Newbie

Joined: Tue Aug 17, 2004 10:35 am
Posts: 9
Thanks feyd,

I was thinking that i needed to put put the images in &lt;TD&gt; tags depending on how many i needed.(in my case three), But what i am having trouble trying to get my head around is say that i used a bigger table eg.
Syntax: [ Download ] [ Hide ]
echo ("<table>

<tr><td><img src ='pics/$img_name'></td><td><img src ='pics/$img_name'></td><td><img src ='pics/$img_name'></td></tr>

</table>"
);

How will the different images being pulled from the database be posted in the relevant &lt;td&gt; columns. Because what i have done above will just display the same images in the &lt;td&gt; columns.

(apologies for the newbie question replies)

Thanks again
I Reh


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 18, 2004 11:10 am 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
JAM | changed to code instead of php tags.
feyd | changed back to php tags now that they are working again.

Syntax: [ Download ] [ Hide ]
<?php

$usr = "****"

$pwd = "*****";

$db = "******";

$host = "localhost";



# connect to database

$cid = mysql_connect($host,$usr,$pwd);

if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); }



$output = '<HTML>

<HEAD>

<TITLE>Test</TITLE>

</HEAD>'
;



# setup SQL statement

$SQL = " SELECT * FROM portfolio ";

$SQL = $SQL .



# execute SQL statement

$retid = mysql_db_query($db, $SQL, $cid) or die(mysql_error());



# display results

$output .= "<P><DT><B>$category</B><BR>\n\n";

$output .= "<table>\n\n";

$howmany = mysql_num_rows($retid);

$rowmax = 3;

for($x = 0; $row = mysql_fetch_array($retid); $x++)

{

if($x % $rowmax == 0)

$output .= "<tr>\n";

$pic_ref = $row["pic_ref"];

$pic_name = $row["pic_name"];

$img_name = $row["img_name"];

$pic_desc = $row["pic_desc"];

$sub_date = $row["sub_date"];

$photographer = $row["photographer"];



$output .= "<td><img src =\"pics/$img_name\">$pic_name</td>";

if($x % $rowmax == $rowmax - 1)

$output .= "\r</tr>\n\n";

}



if($left = (($howmany + $rowmax - 1) % $rowmax))

$output .= '<td colspan="' . $left . '">&amp;nbsp' . ";</td>\n</tr>\n\n";



$output .= "</table>\n\n";



$output .= "</DT></P>";



$output .= '</BODY>

</HTML>'
;



echo $output;

?>


Last edited by feyd on Sat Apr 02, 2005 9:46 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 19, 2004 8:34 am 
Offline
Forum Newbie

Joined: Tue Aug 17, 2004 10:35 am
Posts: 9
Thank you soooo much for doin the code for us, just trying to understand it now, but it works and it is exactly what i needed.

thanks again

I Reh


Top
 Profile  
 
PostPosted: Tue Sep 16, 2008 2:18 pm 
Offline
Forum Commoner
User avatar

Joined: Tue Sep 16, 2008 6:58 am
Posts: 37
wow, very very similar to a situation im in myself !

cheers bro !! this is great (although i dont fully understand how it all works... yet) :D


Top
 Profile  
 
PostPosted: Wed Nov 11, 2009 6:44 pm 
Offline
Forum Commoner
User avatar

Joined: Thu Apr 10, 2008 1:27 am
Posts: 58
Location: India
Hello feyd

I have choosed following line from the code you wrote.

I am not able to understand how this line will behave?

" for($x = 0; $row = mysql_fetch_array($retid); $x++) "

Or is it incorrect?

Please update.
Regards
Ram


Top
 Profile  
 
PostPosted: Thu Dec 02, 2010 1:25 am 
Offline
Forum Newbie

Joined: Thu Dec 02, 2010 1:09 am
Posts: 1
<?php $sql="select id from table_name where id=$_GET['id']";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result)){
?><tr><td><img scr="images/<?php echo $row['image']?>"></td></tr><?php } ?>


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Exabot [Bot] and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group