7 Replies - 1246 Views - Last Post: 16 May 2008 - 04:18 AM Rate Topic: -----

#1 J2kq  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 04-April 08

Slideshow from mysql in php with imageinfo

Post icon  Posted 12 May 2008 - 04:03 AM

//Hi, have made a list of paintings with their details listed on the side and it works Ok - however I would prefer to have this as a slideshow instead just showing one image at the time with their specific details - I hope to find an easy way to just adjust the code below..?? - or does anyone have some input where I can read up on this - thank you - (database is real simple with one table and all image details and path to image on one row)//



<?php

mysql_connect("xx);
mysql_select_db("xx");
$acrylics = mysql_query("SELECT `id`,`name`,`nudes`,`portraits`,`acrylics`,`size`,`canvas`,`paper`,`notes`,`path_img` FROM `Paintings` WHERE `acrylics` = 'y' ORDER BY `id` ASC");
$mainimage = mysql_query("SELECT `id`,`name`,`nudes`,`portraits`,`acrylics`,`size`,`canvas`,`paper`,`notes`,`path_img` FROM `Paintings` WHERE `acrylics` = 'y' ORDER BY `id` ASC");




echo "<table border='0' cellspacing='0' cellpadding='0'>\n<tr>";
$result = @mysql_query("SELECT `path_img`,`id`,`name`,`notes`,`size` FROM `Paintings` WHERE `acrylics` = 'y' ORDER BY `id` ASC");


while($row = mysql_fetch_row($result)) {


echo "<table width='600' border='0' cellspacing='0' cellpadding='4' ><tr><td rowspan='1' align='left' valign='top' bgcolor='#333333'><img src=" . $row[0] . " width='300' /> </td>".
"<td width='400' align='left' valign='top' bgcolor='#333333'><br>".$row[2]."<br>".$row[3]."<br> ".$row[4]." cm<br></td>\n";
}
echo "</tr></table></tr>\n</table><br><br><br>\n";

Is This A Good Question/Topic? 0
  • +

Replies To: Slideshow from mysql in php with imageinfo

#2 spearfish  Icon User is offline

  • Monkey in Training
  • member icon

Reputation: 10
  • View blog
  • Posts: 746
  • Joined: 10-March 08

Re: Slideshow from mysql in php with imageinfo

Posted 12 May 2008 - 06:50 AM

:code:

What are you trying to do / what's happening now?

btw supressing the error in the mysql query might not be the best idea.
Was This Post Helpful? 0
  • +
  • -

#3 JBrace1990  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 110
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: Slideshow from mysql in php with imageinfo

Posted 12 May 2008 - 01:26 PM

well, i'm not sure how to do what you're asking, but I do know there's a couple places you can optimize your code...

you have the same SQL statement operating twice, the only difference being the variable set to it...

and for the result, you have (almost) the same thing going on, the only difference being that less information is taken....

I would suggest a few things for you...

1. use only one query, there's no need to have more then one in this code...
2. When using the $row variable, i would suggest using the column name for several reasons, one of which being that it makes the code easier for people to see, as well as being more accurate, and staying the same, even if you change the SQL later on...

also, I think you need to look into Javascript or another client side scripting IF you want it to be automated, otherwise the current php script should be fine..

This post has been edited by JBrace1990: 12 May 2008 - 01:27 PM

Was This Post Helpful? 0
  • +
  • -

#4 J2kq  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 04-April 08

Re: Slideshow from mysql in php with imageinfo

Posted 12 May 2008 - 02:13 PM

hello again and thank you :-)

Ok got your first point with repetitive queries... bit overkill...

- for the column name I tried several variations using both mysql_fetch_array($acrylics) and mysql_fetch_row($result) - $row['id'], $row['name'] and all text replies are fine however it does not want to pick up the image when I do $row['path_img'] ..?

(apologies but I am new at this, normally just sticking to the graphics..)

- The list actually looks good but would prefer a slideshow instead of having to scroll so will keep on searching for some code that combines images and text changing together

This post has been edited by J2kq: 12 May 2008 - 02:31 PM

Was This Post Helpful? 0
  • +
  • -

#5 JBrace1990  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 110
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: Slideshow from mysql in php with imageinfo

Posted 12 May 2008 - 05:49 PM

lol.... I assume $row['path_img'] returns a url?

if it does, you would need to put it into some code like this:
<?php
echo "<img src=".$row['path_img'].">";
?>


the period represents (basically) another echo statement.... as for the JS, i found this on google.... it might be a little different then what you want for a final product, but i'm sure you could change the code slightly to suit your need =)
Was This Post Helpful? 0
  • +
  • -

#6 J2kq  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 04-April 08

Re: Slideshow from mysql in php with imageinfo

Posted 12 May 2008 - 11:15 PM

//Sii, did that.. after cleaning it up and adding column's names I have this... but it does not work, it wont pick the info up from the database.. whereas it does if I use number-in-line for the columns...??? - checking your link out just now for the JS - thank you//


<?php

mysql_connect("xx");
mysql_select_db("xx");


echo "<table border='0' cellspacing='0' cellpadding='0'><tr>";
$result = @mysql_query("SELECT `path_img`,`id`,`name`,`notes`,`size` FROM `Paintings` WHERE `acrylics` = 'y' ORDER BY `id` ASC");

while($row = mysql_fetch_row($result)) {

echo "<table width='500' border='0' cellspacing='1' cellpadding='10' ><tr><td rowspan='1' align='left' valign='top' bgcolor='#333333'><img src=" . $row['path_img'] . " width='200' /> </td>".
"<td width='400' align='left' valign='bottom' bgcolor='#333333'><br>".$row['name']."<br>".$row['notes']."<br> ".$row['size']." cm<br></td>";
}
echo "</tr></table></tr></table><br><br><br>";

mysql_close();
?>
Was This Post Helpful? 0
  • +
  • -

#7 mocker  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 50
  • View blog
  • Posts: 466
  • Joined: 14-October 07

Re: Slideshow from mysql in php with imageinfo

Posted 13 May 2008 - 01:54 PM

Please put your code in code tags so it is is more readable.

Your loop is off..

you have
while($row = mysql_fetch_row($result)) {


to start the loop.. then inside of the loop you do
echo "<table 



so for each iteration of the loop (each time it pulls a new row), you will output the beginning of a new table, but never close it. If you want to output one long row, move the table declaration to before the loop starts.
Was This Post Helpful? 0
  • +
  • -

#8 J2kq  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 04-April 08

Re: Slideshow from mysql in php with imageinfo

Posted 16 May 2008 - 04:18 AM

Actually want the "new table' so that is perfect - my q is really why this works

mysql_connect("xxx");
mysql_select_db("xx"); 
$acrylics = mysql_query("SELECT `id`,`name`,`nudes`,`portraits`,`acrylics`,`size`,`canvas`,`paper`,`notes`,`path_img` FROM `Paintings` WHERE `acrylics` = 'y' ORDER BY `id` ASC"); 
		 $mainimage = mysql_query("SELECT `id`,`name`,`nudes`,`portraits`,`acrylics`,`size`,`canvas`,`paper`,`notes`,`path_img` FROM `Paintings` WHERE `acrylics` = 'y' ORDER BY `id` ASC"); 
		 	
echo "<table  border='0' cellspacing='0' cellpadding='0'>\n<tr>";
$result = @mysql_query("SELECT `path_img`,`id`,`name`,`notes`,`size` FROM `Paintings` WHERE `acrylics` = 'y' ORDER BY `id` ASC");

while($row = mysql_fetch_row($result)) {
  
 echo "<table  width='500' border='0' cellspacing='1' cellpadding='10' ><tr><td rowspan='1' align='left' valign='top' bgcolor='#333333'><img src=" . $row[0] . " width='200' />	</td>". 
  "<td width='400' align='left' valign='bottom' bgcolor='#333333'><br>".$row[2]."<br>".$row[3]."<br> ".$row[4]." cm<br></td>\n";
}
echo "</tr></table></tr>\n</table><br><br>\n<br>";
			
	mysql_close();
?>
		



when it does not if I use the column names in the "while-loop" what am I missing here.. :-l

this does not work..> (all other exactly the same)



while($row = mysql_fetch_row($result)) {
  
echo "<table  width='500' border='0' cellspacing='1' cellpadding='10' ><tr><td rowspan='1' align='left' valign='top' bgcolor='#333333'><img src=" . $row['path_img'] . " width='200' />	</td>". 
  "<td width='400' align='left' valign='bottom' bgcolor='#333333'><br>".$row['name']."<br>".$row['size']."<br> ".$row['notes']." cm<br></td>\n";
}
echo "</tr></table></tr>\n</table><br><br>\n<br>";
			
	
	

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1