mark110384 Posted September 4, 2008 Share Posted September 4, 2008 Hey guys, I have an item slider created using Javascript, at the moment I have had to create individual tables as shown below that contains the item data, does anyone know how, if is at all posible to incorporate a PHP while loop that drops in data brought back from a database, I just don't hava a clue on how to use the 2 langauges together. Any help would be appreciated. sts_ai("i0", [1,"<table border =\"0\" width=\"210\" height=\"150\" cellpadding=\"0\" cellspacing=\"0\" style=\"font-size:11px; font-family:Verdana; margin:5px;\">\r\n <tr>\r\n <td width=\"91\" rowspan=\"12\" class=\"STYLE10\"><img src=\"../images/mk2002_thumbnail.bmp\" alt=\"\" name=\"p\" width=\"81\" height=\"73\" id=\"p\" /></td>\r\n <td width=\"300\" class=\"STYLE10\"> </td>\r\n </tr>\r\n <tr>\r\n <td><a href=\"#\" style=\"color:#000000\"><strong style=\"color:#0000FF\"><u>Item Title </u></strong></a></td>\r\n </tr>\r\n \r\n <tr>\r\n <td>Space</td>\r\n </tr>\r\n <tr>\r\n <td>Content - Expand to fit whole area</td>\r\n </tr>\r\n <tr>\r\n <td>more content info</td>\r\n </tr>\r\n <tr>\r\n <td> </td>\r\n </tr>\r\n \r\n</table>"],[],"i0","i0"); sts_es(); Quote Link to comment Share on other sites More sharing options...
ScotDiddle Posted September 4, 2008 Share Posted September 4, 2008 mark110384, The thing to remember is that PHP has the first crack at the rendering of the html page. You can do anything you want with PHP, including writing JS code. Cut-n-paste the following into a PHP-ready server and you will see. Good luck. Scot L. Diddle, Richmond VA <?php /** * * Hard-coded PHP value assignment in JS * */ $image = '../images/mk2002_thumbnail.bmp'; $sp = ' '; $content = array(); $content[0] = 'Space'; $content[1] = 'Content - Expand to fit whole area'; $content[2] = 'more content info'; ?> <script type="text/javascript"> sts_ai("i0",[1,"<table border =\"1\" width=\"210\" height=\"150\" cellpadding=\"0\" cellspacing=\"0\" style=\"font-size:11px; font-family:Verdana; margin:5px;\">\r\n <tr>\r\n <td width=\"91\" rowspan=\"12\" class=\"STYLE10\"> <img src=\" <?php echo $image; ?> \" alt=\"\" name=\"p\" width=\"81\" height=\"73\" id=\"p\" /></td>\r\n <td width=\"300\" class=\"STYLE10\"> <?php echo $sp; ?> </td>\r\n </tr>\r\n <tr>\r\n <td><a href=\"#\" style=\"color:#000000\"><strong style=\"color:#0000FF\">Item Title </strong>[/url] </td>\r\n </tr>\r\n \r\n <tr>\r\n <td> <?php echo $content[0]; ?> </td>\r\n </tr>\r\n <tr>\r\n <td> <?php echo $content[1]; ?> </td>\r\n </tr>\r\n <tr>\r\n <td> <?php echo $content[2]; ?> </td>\r\n </tr>\r\n <tr>\r\n <td> <?php echo $sp; ?> </td>\r\n </tr>\r\n \r\n</table>"],[],"i0","i0"); </script> <?php /** * * PHP from Loop: JS Example... * */ $somePHPArray = array(); $somePHPArray = range(1,12); echo "<script type=\"text/javascript\"> \n"; for ($i = 0; $i < count($somePHPArray); $i++) { echo "alert('Array Item Value for IDX : ' + '$i' + ' = ' + '" . $somePHPArray[$i] . "'); \n "; } echo "</script> \n"; /** * * PHP from Loop: HTML Example... * */ /* Output: row 1 1 2 3 row 2 4 5 6 row 3 7 8 9 row 4 10 11 12 */ $somePHPArray = array(); $somePHPArray = range(1,12); $rowCount = 1; echo "\t<table border =\"1\" width=\"210\" height=\"150\" cellpadding=\"0\" cellspacing=\"0\" style=\"font-size:11px; font-family:Verdana; margin:5px;\">\r\n \n"; foreach($somePHPArray as $IDX => $arrayItemValue) { $modulo = $IDX % 3; if ($modulo === 0) { // Only 3 items per row ( besides the "Row Count" Identifier ) if ($IDX > 0) { // don't write closeing </tr> on first pass... echo "\t\t</tr> \n"; } echo "\t\t<tr> \n"; echo "\t\t\t<td style=\"padding: 5,5,5,5;\"> \n"; echo "\t\t\t\trow " . $rowCount . " \n"; // Once per row $rowCount++; } echo "\t\t\t<td style=\"padding: 5,5,5,5;\"> \n"; echo "\t\t\t\t$arrayItemValue \n"; echo "\t\t\t</td> \n"; } echo "\t</table> "; ?> Quote Link to comment Share on other sites More sharing options...
mark110384 Posted September 5, 2008 Author Share Posted September 5, 2008 Awesome, Thanks ScotDiddle that totally put me in the right direction I ended up with the following coding if its any help to anyone else. Looks sleek and easy to manage incorporating a database to hold the data. <script type="text/javascript"> sts_bs("jwscroller2e8e",[20080623,"images/","","blank.gif",6,0,0,5,"100%","center",3,3,150,150,1,0,0,0,0,2000,1,12,2,"stEffect(\"scroll(Rate=24,enabled=0,Duration=0.80)\")",-2,30],["solid",1,"#999999","#FFFFFF","","repeat"]); sts_sca(["center","middle","center","middle"],["arrow03_lt.gif","arrow03_lt.gif","arrow03_ld.gif",22,18,"arrow03_rt.gif","arrow03_rt.gif","arrow03_rd.gif",22,18]); sts_tbd([0], ["solid",1,"#E6EFF9"]); </script> <?php include("../functions.php"); //Get a connection to the database $connect = @ConnectToProducts($dbhost, $dbuser, $dbname); $sql = "SELECT * FROM item_details ORDER BY sts_id"; $result = mysql_query($sql) or die ("Data not found"); while ($myrow = mysql_fetch_array($result)) { $image = $myrow['item_thumb_url']; $stsid = $myrow['sts_id']; $item_no = $myrow['item_no']; $item_name = $myrow['item_short_name']; $item_desc = $myrow['item_desc']; $item_url = $myrow['item_url']; $space = ' '; ?> <script type="text/javascript"> sts_ai("i<?php $stsid; ?>",[1,"<p align=\"center\"><a class=\"other_news\" href=\"<?php echo $item_url; ?>\"><?php echo $item_no; ?> - <?php echo $item_name; ?></a></p>","","_self","<?php echo $image; ?>",130,130,"center"],["transparent","8pt Arial","#000000","none","8pt Arial","#000000","none"]); sts_tip("i<?php $stsid; ?>",[1,"<table border = \"0\" width=\"188\" height=\"172\" cellspacing=\"7\" cellpadding=\"0\" style=\"font-size:11px; font-family:Verdana; margin:10px;\">\r\n <tr>\r\n <td width=\"188\" class=\"STYLE10\"><strong style=\"color:#0000FF\"><a href=\"#\"><?php echo $item_name; ?></a></strong></td>\r\n </tr>\r\n <tr>\r\n <td><?php echo $space; ?></td>\r\n </tr>\r\n <tr>\r\n <td><?php echo "$item_desc";?>... <b>More</b></td>\r\n </tr>\r\n </table>","stEffect(\"rect\")","",80,0,0,0,"middle","left",50,50],["8pt Arial","#006699","none","#EBEBEB","","repeat"]); </script> <? } ?> <script type="text/javascript"> sts_es(); </script> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.