TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-15-2011, 03:23 PM   #1 (permalink)
The Visitor
 
Join Date: Dec 2011
Posts: 1
Thanks: 0
Lacrimosa is on a distinguished road
Default jquery gallery

Hey all,

I really need some help with my coding since i'm stuck with a problem I can't seem to solve.

I am currently working with a jquery gallery plugin, but instead of having the images in a folder on the server, I'd like to link to a database, and get them from a php script.
So far I've got this:

<?php

$dblink = mysql_connect("localhost", "mmd4a201105", "*******");
if (!$dblink)
{
echo "Forbindelse til database kunne ikke etableres".mysql_error();
exit;
}

$db = mysql_select_db ("mmd4a201105");
if (!$db)
{
echo "Databasen kunne ikke vælges".mysql_error();
exit;
}


$sql_streng = "select titel, navn, mail, tekst, fotonavn from foto";

$resultat = mysql_query ($sql_streng, $dblink);
$antal_raekker = mysql_num_rows($resultat);

if ($antal_raekker == 0)
{
echo "Der er ingen fotos at vise!";
}
else
{
while ($raekke = mysql_fetch_assoc($resultat))
{
echo "<img src=\"fotos/$raekke[fotonavn]\" alt=\"fotos/$raekke[fotonavn]\" width=\"75px\" height=\"75px\" title=\"$raekke[titel] /><br><br>";

}
}

mysql_close ($dblink);
?>

The gallery currently only displays the first image in the database table but I like it to display all images on the database... loop function perhaps, I'm not sure that's what the term is called?

Appreciate any help, and sorry if it's a bit confusing. I'll gladly specify anything required. :)
Lacrimosa is offline  
Reply With Quote
Old 02-18-2012, 08:33 PM   #2 (permalink)
The Wanderer
 
AxelG's Avatar
 
Join Date: Feb 2012
Posts: 16
Thanks: 0
AxelG is on a distinguished road
Default

Replace the en of your script by that :

$resultat = mysql_query ($sql_streng, $dblink);
$antal_raekker = mysql_num_rows($resultat);

if ($antal_raekker == 0)
{
echo "Der er ingen fotos at vise!";
}
else
{
while ($raekke = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "<img src=\"fotos/$raekke[fotonavn]\" alt=\"fotos/$raekke[fotonavn]\" width=\"75px\" height=\"75px\" title=\"$raekke[titel] /><br><br>";

}
}


It should work
AxelG is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a gallery class Tanax Advanced PHP Programming 25 02-19-2013 04:25 AM
Jquery ajax forms in PHP MVC app Killswitch Javascript, AJAX, E4X 0 01-11-2010 05:50 PM
Basics or jQuery? devnull Javascript, AJAX, E4X 20 08-12-2009 03:12 PM
Lets get the Image gallery started! Aaron TalkPHP Developer Team 16 12-27-2008 03:41 PM


All times are GMT. The time now is 12:21 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design