Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > Putting it Together > Databases

Reply
 
LinkBack Thread Tools
Old May 2nd, 2009, 02:47 PM   #1
WebForumz Member
 

Join Date: Mar 2008
Location: South Africa
Posts: 58
Thanks: 2
Thanked 1 Time in 1 Post
Rep Altering Power: 0 donovan is on a distinguished road
explode query

Hi
I have a small problem, which I cant seem to figure out.
I have an array of images in a column called "images" in my database.

How can I display the images from the DB into my web page

Any help would be greatly appreciated.
Donovan
donovan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 2nd, 2009, 03:08 PM   #2
WebForumz Admin Badge
SuperMember
 
Marc's Avatar
 

Join Date: Apr 2007
Location: Scotland, UK
Posts: 2,086
Thanks: 2
Thanked 23 Times in 23 Posts
Rep Altering Power: 89 Marc is just really nice Marc is just really nice Marc is just really nice Marc is just really nice
Re: explode query

What is the image stored like in your database like? The path to the image file?
__________________
Regards
Marc
Administrator - Webforumz.com

Web Design and Development Blog - Marc Fraser
Marc is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 3rd, 2009, 02:12 AM   #3
WebForumz Member
 

Join Date: Mar 2008
Location: South Africa
Posts: 58
Thanks: 2
Thanked 1 Time in 1 Post
Rep Altering Power: 0 donovan is on a distinguished road
Re: explode query

I saved the images in a folder and stored their references in the database
donovan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 3rd, 2009, 04:35 AM   #4
WebForumz Admin Badge
SuperMember
 
Marc's Avatar
 

Join Date: Apr 2007
Location: Scotland, UK
Posts: 2,086
Thanks: 2
Thanked 23 Times in 23 Posts
Rep Altering Power: 89 Marc is just really nice Marc is just really nice Marc is just really nice Marc is just really nice
Re: explode query

If thats the case, you can just use a programming language (such as PHP) to extract the data from the database -- using a query, then you just use the variable to display the image like:

HTML Code:
<img src="<?php $row['imgsrc']; ?>" alt="" />
What programming language are you looking to use?
__________________
Regards
Marc
Administrator - Webforumz.com

Web Design and Development Blog - Marc Fraser
Marc is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 3rd, 2009, 04:57 AM   #5
WebForumz Member
 

Join Date: Mar 2008
Location: South Africa
Posts: 58
Thanks: 2
Thanked 1 Time in 1 Post
Rep Altering Power: 0 donovan is on a distinguished road
Re: explode query

Sorry about the entry before this, I pressed the submit button before I was finished

This goes above the DOCTYPE
Code:
// Get the name and the caption for the main image
$mainImage = $row_propProfile['image'];
// Get the dimensions of the main image
$imageSize = getimagesize('upload/'.$mainImage);
This goes in the body
Code:
<?php do { ?>
  <td>
    <a href="<?php echo $_SERVER['PHP_SELF']; ?>?image=<?php echo $row_propProfile['image']; ?>">image3</a>
  </td>
<?php
  $row_propProfile = mysql_fetch_assoc($propProfile);
  } while ($row_propProfile);
?>
</tr>
</table>
<div id="main_image">
<img src="upload/<?php echo $mainImage; ?>" alt="" width="350" height="237" <?php echo $imageSize[3]; ?> />
</div>
This is for an image gallery which recieves image references from the DB. Their gallery gets the references from a DB called images and the column is called image(where the image ref. is stored). So each image that goes in, is a new record.
In my situation, each record has 12 images.
I dont know how to get my images from the column that they are in, to display in my page

Hope this make sense, as Im fairly new to php.

Last edited by donovan; May 3rd, 2009 at 05:13 AM.. Reason: pressed the wrong button
donovan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 3rd, 2009, 05:05 AM   #6
WebForumz Admin Badge
SuperMember
 
Marc's Avatar
 

Join Date: Apr 2007
Location: Scotland, UK
Posts: 2,086
Thanks: 2
Thanked 23 Times in 23 Posts
Rep Altering Power: 89 Marc is just really nice Marc is just really nice Marc is just really nice Marc is just really nice
Re: explode query

Quote:
Originally Posted by donovan View Post
// Get the name and the caption for the main image
$mainImage = $row_propProfile['image'];
// Get the dimensions of the main image
$imageSize = getimagesize('upload/'.$mainImage);

<?php do { ?>
<td>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?image=<?php echo $row_propProfile['image']; ?>">bob</a>
</td>
<?php
$row_propProfile = mysql_fetch_assoc($propProfile);
} while ($row_propProfile);
?>

Is that code working, or?
__________________
Regards
Marc
Administrator - Webforumz.com

Web Design and Development Blog - Marc Fraser
Marc is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 3rd, 2009, 05:44 AM   #7
WebForumz Member
 

Join Date: Mar 2008
Location: South Africa
Posts: 58
Thanks: 2
Thanked 1 Time in 1 Post
Rep Altering Power: 0 donovan is on a distinguished road
Re: explode query

I made some edits to the post earlier. Just check above your last response for the proper entry
donovan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 3rd, 2009, 05:52 AM   #8
WebForumz Admin Badge
SuperMember
 
Marc's Avatar
 

Join Date: Apr 2007
Location: Scotland, UK
Posts: 2,086
Thanks: 2
Thanked 23 Times in 23 Posts
Rep Altering Power: 89 Marc is just really nice Marc is just really nice Marc is just really nice Marc is just really nice
Re: explode query

I suggest you use something similar to:

Code:

<?php 

$query 
mysql_query(""); // Remember to insert your query

while($row mysql_fetch_array($query) {
$imageurl $row['image'];

print 
"<td><img src="'. $imageurl .'" alt="" /></td>;
}
Sorry I don't have any more time to go into more detail at the moment as I have to go out. This should however give you a start, and I'll look back here when I get back in.
__________________
Regards
Marc
Administrator - Webforumz.com

Web Design and Development Blog - Marc Fraser
Marc is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 3rd, 2009, 05:54 AM   #9
WebForumz Member
 

Join Date: Mar 2008
Location: South Africa
Posts: 58
Thanks: 2
Thanked 1 Time in 1 Post
Rep Altering Power: 0 donovan is on a distinguished road
Re: explode query

thanks, Ill give it a go now
donovan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 3rd, 2009, 06:50 AM   #10
WebForumz Member
 

Join Date: Mar 2008
Location: South Africa
Posts: 58
Thanks: 2
Thanked 1 Time in 1 Post
Rep Altering Power: 0 donovan is on a distinguished road
Re: explode query

I just checked it out now, but it doesnt seem to have worked.
I think I might not be explaining myself correctly, so Im going to give it another go.
I have a form which uploads 12 images along with other relevant info to a DB.
All the images go into one column as a comma seperated string.
Then I have another page, which I would like to reflect the images that i put into the DB.
Im not sure how to call those images, change them from a comma seperated string into an array and then loop through them to show an image gallery.
donovan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 3rd, 2009, 07:53 AM   #11
WebForumz Admin Badge
SuperMember
 
Marc's Avatar
 

Join Date: Apr 2007
Location: Scotland, UK
Posts: 2,086
Thanks: 2
Thanked 23 Times in 23 Posts
Rep Altering Power: 89 Marc is just really nice Marc is just really nice Marc is just really nice Marc is just really nice
Re: explode query

Quote:
Originally Posted by donovan View Post
I just checked it out now, but it doesnt seem to have worked.
I think I might not be explaining myself correctly, so Im going to give it another go.
I have a form which uploads 12 images along with other relevant info to a DB.
All the images go into one column as a comma seperated string.
Then I have another page, which I would like to reflect the images that i put into the DB.
Im not sure how to call those images, change them from a comma seperated string into an array and then loop through them to show an image gallery.
Is there a reason why your storing it as CSV?

You can explode the string using http://uk3.php.net/explode.... If thats what your looking for - I dont see that used anywhere in your code just now...
__________________
Regards
Marc
Administrator - Webforumz.com

Web Design and Development Blog - Marc Fraser
Marc is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 3rd, 2009, 08:00 AM   #12
WebForumz Member
 

Join Date: Mar 2008
Location: South Africa
Posts: 58
Thanks: 2
Thanked 1 Time in 1 Post
Rep Altering Power: 0 donovan is on a distinguished road
Re: explode query

Im not sure how else to store it. I have just read in alot of sites that images shouldnt be stored in a database, but rather just their references should be stored
donovan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 4th, 2009, 08:44 AM   #13
Reputable Member
 

Join Date: Nov 2008
Location: Lexington, KY
Posts: 243
Thanks: 0
Thanked 1 Time in 1 Post
Rep Altering Power: 0 Dubbs is on a distinguished road
Re: explode query

Donovan, you can use PHP's Explode function to break a string into multiple parts, you can also use a regular expression also.

The explode would be:
Code:
$images explode', ',$image_variable);. 
This function will take a string like:

image1, image2, image4

Then turn it into an array. To call any of the images, you would use $images[0] (would display image1).
Dubbs is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 4th, 2009, 09:55 AM   #14
WebForumz Member
 

Join Date: Mar 2008
Location: South Africa
Posts: 58
Thanks: 2
Thanked 1 Time in 1 Post
Rep Altering Power: 0 donovan is on a distinguished road
Re: explode query

Please excuse my ignorance, but how would I incorporate that into the code that you initially gave me.
Can you give another example.
donovan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 4th, 2009, 05:02 PM   #15
Reputable Member
 

Join Date: Nov 2008
Location: Lexington, KY
Posts: 243
Thanks: 0
Thanked 1 Time in 1 Post
Rep Altering Power: 0 Dubbs is on a distinguished road
Re: explode query

Here is an edit to the code that Marc posted. I added the explode that we both suggested. You will need to change the delimiter (right now it is a pipe) with the delimeter that the database is using.
Code:
<?php 

$query 
mysql_query(""); // Remember to insert your query



while($row mysql_fetch_array($query) {
$imageurl $row['image'];
}

//Exploding the images remember to change the pipe (|) character to the delimiter you need.
$images explode('|',$imageurl);
$num_images count($images);


//Loop to display the images.
while ($num_images >=0){
print 
'<td><img src="'$images[$num_images] .'" alt="" /></td>';
$num_images --;
}
Dubbs is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 5th, 2009, 02:21 AM   #16
WebForumz Member
 

Join Date: Mar 2008
Location: South Africa
Posts: 58
Thanks: 2
Thanked 1 Time in 1 Post
Rep Altering Power: 0 donovan is on a distinguished road
Re: explode query

What exactly is a delimiter?
donovan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 5th, 2009, 11:41 AM   #17
WebForumz Admin Badge
SuperMember
 
Marc's Avatar
 

Join Date: Apr 2007
Location: Scotland, UK
Posts: 2,086
Thanks: 2
Thanked 23 Times in 23 Posts
Rep Altering Power: 89 Marc is just really nice Marc is just really nice Marc is just really nice Marc is just really nice
Re: explode query

The dividing value - in your case a comma (going on what one of your above posts said).

So,
Code:
$images explode(',',$imageurl); 
</span></span>
__________________
Regards
Marc
Administrator - Webforumz.com

Web Design and Development Blog - Marc Fraser
Marc is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 6th, 2009, 01:45 AM   #18
Reputable Member
 

Join Date: Apr 2009
Location: The Toon
Posts: 134
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 davidj is on a distinguished road
Re: explode query

Quote:
What exactly is a delimiter?
i think your running before you've learnt to walk
davidj is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 6th, 2009, 11:03 AM   #19
WebForumz Member
 

Join Date: Mar 2008
Location: South Africa
Posts: 58
Thanks: 2
Thanked 1 Time in 1 Post
Rep Altering Power: 0 donovan is on a distinguished road
Re: explode query

I'd say. Our developer left recently and I was thrown in the deep end.
Ha ha.. You must have had a chuckle.
donovan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 6th, 2009, 04:05 PM   #20
Reputable Member
 

Join Date: Nov 2008
Location: Lexington, KY
Posts: 243
Thanks: 0
Thanked 1 Time in 1 Post
Rep Altering Power: 0 Dubbs is on a distinguished road
Re: explode query

A quick Google search returns these meaning for delimiter.

A delimiter is basically a character or group of charcters which divide something.

This | sentence | has | a | delimiter.

In the sentence above | is the delimiter. In the code that I posted I used | as a delimiter since it stood out in the code, and would be easy to find when you changed it. If your database has the images divided by commas (,) then replace the | with a ,.
Dubbs is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB 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
A query delboy1875 Your Design and Layout 1 December 11th, 2008 03:38 PM
MySQL query query dangergeek Databases 3 April 12th, 2007 08:45 AM
Query accessman Databases 0 September 22nd, 2005 03:48 PM
Explode Anchor Sheepymot PHP 2 July 23rd, 2005 09:24 AM
ASP ADO SQL Query TheShadow Classic ASP 10 June 18th, 2005 11:12 AM


Search Engine Optimization by vBSEO 3.2.0 RC8