SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    325
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    How to pass values from a PHP loop a to jQuery function

    Hello guy,

    I need help. I can't figure out how to pass these values from a PHP loop to a jQuery function.
    PHP: the playlist, psychically visual
    Code:
    if ($result = $mysqli->query("SELECT mp3_id, genre, mp3_title, mp3_path, mp3_duration FROM mp3 WHERE genre = 'pop' ORDER BY mp3_id DESC LIMIT 5")) {
    	while(($row = $result->fetch_object()) && ($i <= 5)) {
    		echo "<li>";
    		echo "<div id=mp3Item>";
    		echo "<div id=mp3Track>";
    		echo $i++;
    		echo "</div>";
    		echo "<div id=mp3Title>";
    		echo $row->mp3_title;
    		echo "</div>";
    		echo "<div id=mp3Lenght>";
    		echo $row->mp3_duration;
    		echo "</div>";
    		echo "</div>";
    		echo "</li>";
    
    		$mp3_files = $row->mp3_path;
    	}
    }
    Javascript (An example that works fine with manually added items, I can't figure out how to pass values from a PHP loop yet):
    Code:
    tracks = [
    	{"track":1,"name":"One More Night","length":"04:55","file":"01_One More Night.mp3"},
    	{"track":2,"name":"Some Nights","length":"03:37","file":"02_Some Nights.mp3"},
    	{"track":3,"name":"We Are Never Ever Getting Back Together","length":"04:05","file":"03_We Are Never Ever Getting Back Togethe.mp3"},
    	{"track":4,"name":"Too Close","length":"06:40","file":"04_Too Close.mp3"},
    	{"track":5,"name":"Die Young","length":"05:59","file":"05_Die Young.mp3"}
    ],
    I want something like this:
    Code:
    tracks = [
    	{"track":1,"name":"$row->mp3_title","length":"$row->mp3_duration","file":"$row->mp3_path"},
    	{"track":2,"name":"$row->mp3_title","length":"$row->mp3_duration","file":"$row->mp3_path"},
    	.
    	.
    	.
    ],
    Any suggestion would be greatly appreciated.
    Thanks

  2. #2
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    325
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •