Jump to content

Need Help With Array


BrandonGoins

Recommended Posts

I am using the following code to export all items in a database file, which are all numbered 0 through whatever. It works great...

 

<?

 

@include($document . "destination-data.php");

$limit = count($offroad);

for ( $destination = 0; $destination < $limit; $destination += 1) {

echo "<TR><TD COLSPAN=2><TR><TD ALIGN=LEFT VALIGN=TOP WIDTH=180><A HREF=" . $offroad[$destination]['url'] . "><IMG SRC=" . $offroad[$destination]['image'] . " BORDER=0></A></TD><TD VALIGN=TOP STYLE=PADDING-LEFT:10><B><SPAN STYLE=font-size:14>" . $offroad[$destination]['name'] . "</B></SPAN><BR><BR>" . $offroad[$destination]['amenities'] . "<BR><P ALIGN=JUSTIFY>" . $offroad[$destination]['abstract'] . "</P></TD></TR><TR><TD COLSPAN=2><BR><HR SIZE=1 COLOR=c4940f></TD></TR>";

}

 

?>

Now I would like to change the code to allow me to specify certain numbers in array to load... like 0,6,8, etc.

 

I tried to set an array and then use the next function but I get no results.Nothing at all is output no matter what I seem to do. Can anyone throw me a bone? It should be simple but my php knowledge is crap.

 

 

 

Link to comment
Share on other sites

<?php

function showSelectedRecords($dataAry, $selectionAry)
{
    foreach ($selectionAry as $dataIdx)
    {
        echo "<tr><td colspan=\"2\"> </td></tr>\n";
        echo "<tr>\n";
        echo   "<td align=left valign=top width=180>";
        echo     "<a href=\"{$dataAry[$dataIdx]['url']}\"><img src=\"{$dataAry[$dataIdx]['image']}\" border=\"0\"></a>";
        echo   "</td>\n";
        echo   "<td valign=\"top\" style=\"padding-left:10; font-size:14;font-weight:bold;\">";
        echo     "{$dataAry[$dataIdx]['name']}<br /><br />{$dataAry[$dataIdx]['amenities']}<br />";
        echo     "<p align=\"justify\">{$dataAry[$dataIdx]['abstract']}</p>";
        echo   "</td>\n";
        echo "</tr>\n";
        echo "<tr>\n";
        echo   "<td colspan=\"2\"><br /><hr size=\"1\" color=\"c4940f\"></td></tr>\n";
    }
}


@include($document . "destination-data.php"); 

//Create an array of the items to display
//from the $offroad array
$selected = array(1,3,4,7,9);

showSelectedRecords($offroad, $selected);

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.