Link to home
Start Free TrialLog in
Avatar of John Grosshans
John GrosshansFlag for United States of America

asked on

Loop thru MySQL and add values to PHP array

I have a audio file page on my website and I want to make it as easy as possible to update this so I made a php array so that all I have to do is add a new array into the script with the title, speaker, date, and file url in it and the script will automatically add the new player and text and file to the top of the list.

Now this works for me cause I don't mind typing in an array but to make it easier I was thinking of making a simple form with fields for those values and have it just insert into a table on my MySQL database. I have the form working great.

The problem is I do not know how to pass that data from the table to create a new array for my php script I attached my original script but need to make it work with MySQL database

I am a big newbie when it comes to MySQL and a novice with PHP so if you can explain your code it will help me learn, THANKS EXPERTS!
//this is my array script audio.php

<?php
$sermons = array(
	array('If He owns "The Cattle on  a Thousand Hills", What does he need my Money For?', "Tim Grosshans", "02-20-11", "file1.php"),
	array("The Power of Love", "Tim Grosshans", "02-13-11", "file2.php"),
	array("The Lord's Supper", "Tim Grosshans", "02-06-11", "file3.php"),
	array("The Big Picture", "Roger Palmer", "01-30-11", "file4.php"),
	array("I Just Forgot", "Tim Grosshans", "01-23-11", "file5.php"),
	array("Possible Gifts--Celibacy, Hospitality, Voluntary Poverty, Martyrdom", "Tim Grosshans", "01-16-11", "file6.php"),
);
?>

//then I have the php script that makes the looped list archive.php

<?php
include ('audio.php');
$size = count($sermons);
for ($message = 0; $message < $size; $message++)
{
	if($message % 2 == 0)
		{
	echo '<div style="background-color: #ffffff;">
<img class="alignleft" style="margin-top: 30px; margin-bottom: 10px;" title="Audio Message" src="http://XXXXXX/wp-content/uploads/2010/01/audio-message-image.png" alt="" width="90" height="90" />
<table style="width: 440px; height: 20px;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td colspan="2">
<h2 style="text-align: center;">'.$sermons[$message][0].'</h2>
</td>
</tr>
<tr>
<td><strong>'.$sermons[$message][1].'</strong></td>
<td>'.$sermons[$message][2].'</td>
</tr>
<tr>
<td><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="200" height="20" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://flash-mp3-player.net/medias/player_mp3.swf" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="mp3='.$sermons[$message][3].'&amp;bgcolor1=0b3975&amp;bgcolor2=072245&amp;buttoncolor=ffffff&amp;buttonovercolor=ffffff&amp;slidercolor1=ffffff&amp;slidercolor2=ffffff&amp;sliderovercolor=ffffff" /><param name="data" value="http://flash-mp3-player.net/medias/player_mp3.swf" /><embed type="application/x-shockwave-flash" width="200" height="20" src="http://flash-mp3-player.net/medias/player_mp3.swf" data="http://flash-mp3-player.net/medias/player_mp3.swf" flashvars="mp3='.$sermons[$message][3].'&amp;bgcolor1=0b3975&amp;bgcolor2=072245&amp;buttoncolor=ffffff&amp;buttonovercolor=ffffff&amp;slidercolor1=ffffff&amp;slidercolor2=ffffff&amp;sliderovercolor=ffffff" bgcolor="#ffffff"> </embed></object></td>
<td><a href="'.$sermons[$message][3].'" target="_blank">DOWNLOAD</a></td>
</tr>
</tbody>
</table>
</div>
<br />
<hr />';
}
	else {
echo '<div style="background-color: #ececec;">
<img class="alignleft" style="margin-top: 30px; margin-bottom: 10px;" title="Audio Message" src="http://XXXXXX/wp-content/uploads/2010/01/audio-message-image.png" alt="" width="90" height="90" />
<table style="width: 440px; height: 150px;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td colspan="2">
<h2 style="text-align: center;">'.$sermons[$message][0].'</h2>
</td>
</tr>
<tr>
<td><strong>'.$sermons[$message][1].'</strong></td>
<td>'.$sermons[$message][2].'</td>
</tr>
<tr>
<td><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="200" height="20" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://flash-mp3-player.net/medias/player_mp3.swf" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="mp3='.$sermons[$message][3].'&amp;bgcolor1=0b3975&amp;bgcolor2=072245&amp;buttoncolor=ffffff&amp;buttonovercolor=ffffff&amp;slidercolor1=ffffff&amp;slidercolor2=ffffff&amp;sliderovercolor=ffffff" /><param name="data" value="http://flash-mp3-player.net/medias/player_mp3.swf" /><embed type="application/x-shockwave-flash" width="200" height="20" src="http://flash-mp3-player.net/medias/player_mp3.swf" data="http://flash-mp3-player.net/medias/player_mp3.swf" flashvars="mp3='.$sermons[$message][3].'&amp;bgcolor1=0b3975&amp;bgcolor2=072245&amp;buttoncolor=ffffff&amp;buttonovercolor=ffffff&amp;slidercolor1=ffffff&amp;slidercolor2=ffffff&amp;sliderovercolor=ffffff" bgcolor="#ffffff"> </embed></object><br /></td>
<td><a href="'.$sermons[$message][3].'" target="_blank">DOWNLOAD</a></td>
</tr>
</tbody>
</table>
<br />
</div>
<hr />';
}
}
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of TimBare
TimBare
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
btw, it's using a prepared statement for MySQL, which isn't really needed in this example, but is recommended when there's a possibility for user entry... If you want more info on that, let me know. I'd be happy share some more info on it...
also, if you need help looping the multi-dimensional array, let me know...
Avatar of John Grosshans

ASKER

AWESOME!!!!