Advertisement
Guest User

Untitled

a guest
Sep 18th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.10 KB | None | 0 0
  1. <html>
  2. <body style="color: #888888;font-size: 75%;">
  3. <?php
  4. $myServer = "localhost"; //sql server normally localhost
  5. $myUser = "radiodb"; //sql db user
  6. $myPass = "P0hv8jL2"; //sql db pass
  7. $myDB = "radiodbase"; //sql db name
  8.  
  9. #
  10.     $con = @mysql_connect($myServer, $myUser, $myPass) or die('mysql_connect: ' . mysql_error());
  11. #
  12.            @mysql_select_db($myDB) or die('mysql_select_db: ' . mysql_error());
  13. #
  14.    
  15. #
  16.     $result = array();
  17. #
  18.          
  19. #
  20.     $res = mysql_query("SELECT * FROM song ORDER BY id DESC LIMIT 10");
  21. #
  22.     while ($row = mysql_fetch_array($res))
  23. #
  24.         $result[] = $row;
  25. #
  26.        
  27. #
  28.     array_reverse($result);
  29. #
  30.     //print_r($result);
  31. #
  32.     foreach ($result as $request) {
  33. #
  34.         echo htmlspecialchars($request['song_?name']) . '<br />';
  35. #
  36.     }
  37. #
  38.  
  39. #
  40.     mysql_close();
  41. /*
  42. $con = mysql_connect("$myServer","$myUser","$myPass"); //connect to the db
  43. if (!$con) //if you cant connect then do this function
  44.   {
  45.     die('Could not connect: ' . mysql_error()); //say you cant connect and why
  46.   }
  47.  
  48. $db_selected = mysql_select_db($myDB, $con); //select the database you will be working with
  49. if (!$db_selected) { //if you cant select a db
  50.         die ('Can\'t use '+ $myDB + ':' . mysql_error()); //say you cant select it and why
  51.     }
  52.  
  53. $query="SELECT * FROM song ORDER by id DESC"; //assign the query that you want to be done from the table and fields and sorting
  54. $result=mysql_query($query); //do the query you assigned
  55.  
  56. $num=mysql_numrows($result); //calculate how many rows there are in the results you queried
  57.  
  58. //echo "<b>10 Latest Requests</b><br />"; //output the words 10 Latest Requests
  59.  
  60. $i=0; //assign 0 to variable i
  61. while ($i < $num) { //while i is less than the total number of rows run the function in the brackets
  62. $songname=mysql_result($result,$i,"song_name"); //assign songname to a variable named $songname from the results
  63. if ($i < 10) //if i is less than 10 since we only want the first 10 and the id starts at 0
  64.     {
  65.         $b = $i+1;
  66.         echo "$b. $songname<br />"; //output the song name
  67.     }  
  68.     $i++; //add 1 to i
  69. }
  70. */
  71. ?>
  72. </body>
  73. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement