PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Jul 22, 2019 5:47 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


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


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:

(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


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: No registered users and 4 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