I have 2 separate arrays being pulled from MYSQL database, and want to combine both arrays on the key, so I can use a php foreach statement.
*I tried doing 1 query with both, but could not figure out how to get my foreach $video[0] to work.*
match_descr = video code
m_date = date
SQL
$query = "SELECT match_descr FROM #__bl_match WHERE match_descr != '' ORDER BY m_date DESC";
$db->setQuery($query);
$videomatch = $db->loadResultArray();
$query = "SELECT m_date FROM #__bl_match WHERE match_descr != '' ORDER BY m_date DESC";
$db->setQuery($query);
$videomatch2 = $db->loadResultArray();
PHP
$video = $this->videomatch;
for ($i=1;$i<=1;$i++){
echo '<div id="videoFrame" align="left"><iframe name="videoFrame" title="YouTube video
player" width="560" height="315" src="http://www.youtube.com/embed/' . $video[0] . '" frameborder="0" allowfullscreen=""></iframe></div>';
echo '<br />';
echo '<br />';
echo '<div id="videoThumbnails" align="left">';
echo '<table>';
foreach ($video as $value)
{
echo '<tr>';
echo '<td>';
echo '<a href="http://www.youtube.com/embed/' . $value . '" target="videoFrame"><img height="75px" width="123px" src="http://img.youtube.com/vi/' . $value. '/2.jpg" alt="' . $value . '" /> </a>';
echo '</td>';
echo '<td>';
echo (THIS IS WHERE I WOULD LIKE TO PUT THIS VIDEOS DATE);
echo '<br />';
echo 'California';
echo '<br />';
echo '1-19-2012';
echo '</td>';
echo '</tr>';
}
echo '</div>';}
You are (usually) better off selecting both rows in the same query:
It appears that you are using Joomla. If this is the case, I don’t think you can use
loadResultArray()to iterate multiple columns (you can give it an index to get one of the columns, but that’s not helpful in this case). Instead, you can useloadRowListto get an index array of the columns, orloadAssocListto get an associative array of the columns.They can be used as follows (without all the html for brevity):
loadRowList:
loadAssocList:
Reference: http://docs.joomla.org/How_to_use_the_database_classes_in_your_script