Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] Multidimensional array


[SOLVED] Multidimensional array

Reply
  #1 (permalink)  
Old 10-30-08, 12:06 PM
dmartinka dmartinka is offline
New Member
 
Join Date: Oct 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Multidimensional array

Problem: I have a multidimenional array where I would like to extract the values into a looping html div layout.

ARRAY:
PHP Code:

$project = array (

    array(
        
'img' => 'img-jobster',
        
'date' => 'January 2007'
    
),
    array(
        
'img' => 'img-fleeq',
        
'date' => 'February 2007'
    
),
    array(
        
'img' => 'img-divvy',
        
'date' => 'March 2007'
    

Loop goes here

DIV: (this repeats)
HTML Code:
<div class="project">
        <img src="<?php echo"$image"; ?>" width="451" height="262" />
	<ul class="details">
		<li><?php echo"$date" ?></li>
	</ul>
</div>
The piece I'm missing here is I don't know what kind of loop to use and how to convert the values it gives me to variables. Examples would help.
Reply With Quote
  #2 (permalink)  
Old 10-30-08, 01:39 PM
phpdoctor's Avatar
phpdoctor phpdoctor is offline
Code Guru
 
Join Date: Feb 2007
Location: New Zealand
Posts: 767
Thanks: 4
Thanked 2 Times in 2 Posts
This is where the foreach loop comes in handy:
PHP Code:



foreach($project as $row)
{
    echo 
'<div class="project">
        <img src="'
.$row['img'].'" width="451" height="262" />
    <ul class="details">
        <li>'
.$row['date'].'</li>
    </ul>
      </div>' 
;

You need to put the full path of the images in... and the extensions (.jpg, .png ect)

Good Luck,
Lex
__________________
01010000 01001000 01010000
Reply With Quote
  #3 (permalink)  
Old 10-30-08, 04:45 PM
dmartinka dmartinka is offline
New Member
 
Join Date: Oct 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Perfect. Thanks Doctor
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' Dr. Forensics PHP 3 07-15-06 03:54 PM
Multidimensional Array Sorting Kage PHP 6 12-12-05 04:19 PM
Sorting a massive multidimensional array dave111 PHP 1 12-12-05 04:09 PM
Multidimensional Array as Session Object emily13 ASP.NET 1 11-29-05 06:54 AM
linking to iframe not working :( j0d JavaScript 5 01-19-04 08:14 PM


All times are GMT -5. The time now is 08:21 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.