473,388 Members | 1,600 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

I need my php to call certain parts of a table from mysql

I have a html code writtin which calls a php page.(this much works perfectly).

In the html the user has a choice of 5 artists from a drop down menu.
When the choose the artist I want it to call the details for that artist from mysql.

In mysql:
Table name in database:Tracks.
Column 1 in table: album_number
Column 2 in table: track number
column 3 in table: track_title

So if no 1 (james taylor) is called it should choose album no 1, all track numbers and all titles for album no 1.

How do I do this.
I have posted as far as i have gotten but I am stuck at this stage and going round in circles

I am begging for your help.
Thanks.

Here is the php code.I have made so many changes I am lost now!

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  2. <html xmlns="http://www.w3.org/1999/xhtml"> 
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> 
  5. <title>Album</title> 
  6. <link rel="stylesheet" type="text/css" href="homework.css"> 
  7. </head> 
  8. <body>  
  9. <?php  
  10. // get form selection  
  11. $day = $_GET['day']; 
  12.       // check value and select appropriate item 
  13.       if ($day == 1) { 
  14. $album = 'James Taylor'; 
  15. ?> 
  16. <?php 
  17.       // set database server access variables: 
  18.       $host = "testweb2.csis.ul.ie"; //localhost on your home PC/laptop
  19.       $user = "XXXXXX"; //your ID number here
  20.       $pass = "XXXXXX"; //your password here
  21.       $db = "XXXXXX"; //your ID number here
  22.  
  23.       // open connection 
  24.       $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); 
  25.  
  26.       // select database 
  27.       mysql_select_db($db) or die ("Unable to select database!"); 
  28.  
  29.       // create query 
  30.       $query = "SELECT * FROM Tracks"; 
  31.  
  32.       // execute query 
  33.       $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 
  34.  
  35.       // see if any rows were returned 
  36.       if (mysql_num_rows($result) > 0) { 
  37.         // yes 
  38.         // print them one after another 
  39.         echo('<table class="query_result">'); 
  40.         while($row = mysql_fetch_row($result)) { 
  41.           echo('<tr>');
  42.           for($c=0; $c<sizeof($row); $c++) {
  43.             echo('<td>'.$row[$c].'</td>');
  44.           } 
  45.           echo('</tr>');
  46.         } 
  47.         echo('</table>');
  48.       } 
  49.       else { 
  50.         // no 
  51.         // print status message 
  52.         echo('No rows found!');
  53.       }
  54.  
  55.       // free result set memory 
  56.       mysql_free_result($result); 
  57.  
  58.       // close connection 
  59.       mysql_close($connection);
  60.  
  61.  
  62.  
  63.  
  64.  
  65. }  
  66. elseif ($day == 2) { 
  67. $album = 'The Rolling Stones';  
  68. ?> 
  69. <table> 
  70. <tr> 
  71. <td> 
  72. <a href = index1.html>Back</a><br> 
  73. <h1>The Rolling Stones </h1> 
  74. <h2>'Symphany For The devil'</h2> 
  75. <img src="images/stones.jpg" alt="beggars banquet - rolling stones" width="100" height="100"/> 
  76. <p><span class="style1">Track Titles:<br /> 
  77. <h3> 
  78. <ol>1. Sympathy for the Devil</ol> 
  79. <ol>2. No Expectations</ol> 
  80. <ol>3. Parachute Woman</ol> 
  81. <ol>4. Jigsaw Puzzle</ol> 
  82. <ol>5. Street Fighting Man</ol>  
  83. <ol>6. Prodigal Son</ol> 
  84. <ol>7. Stray Cat Blues</ol>  
  85. <ol>8. Factory Girl</ol> 
  86. <ol>9. Salt of the Earth</ol> 
  87. </h3> 
  88. </span> 
  89. <br /> 
  90. <iframe title="YouTube video player" width="480" height="290" src="http://www.youtube.com/embed/iLddJ1WceHQ" frameborder="0" allowfullscreen></iframe> 
  91. </p> 
  92. </td> 
  93. </tr> 
  94. </table> 
  95.  
  96. <?php  
  97. }  
  98. elseif ($day == 3) {  
  99.  $album = 'Sting';  
  100. ?> 
  101. <table> 
  102. <tr> 
  103. <td> 
  104. <a href = index1.html>Back</a><br> 
  105. <h1>Sting</h1> 
  106. <h2>'All This Time'</h2> 
  107. <img src="images/allthistime.jpg" alt="All This Time - Sting" width="100" height="100"/> 
  108. <p><span class="style1">Track Titles:<br /> 
  109. <h3> 
  110. <ol>1. A Thousand Years</ol>
  111. <ol>2. If You Love Somebody Set Them Free</ol> 
  112. <ol>3. Perfect Love...Gone Wrong</ol>  
  113. <ol>4. All This Time</ol>  
  114. <ol>5. Seven Days</ol> 
  115. <ol>6. The Hounds of Winter</ol> 
  116. <ol>7. Dont Stand So Close to Me</ol>  
  117. <ol>8. When We Dance</ol>  
  118. <ol>9. Dienda</ol> 
  119. <ol>10. Roxanne</ol> 
  120. <ol>11. Every Breath You Take</ol> 
  121. </h3> 
  122. </span><br /> 
  123. </span><br /> 
  124. <iframe title="YouTube video player" width="480" height="290" src="http://www.youtube.com/embed/MsLzdYR_MaQ" frameborder="0" allowfullscreen></iframe> 
  125. </p> 
  126. </td> 
  127.  </tr> 
  128. </table> 
  129.  
  130. <?php  
  131.  }  
  132. elseif ($day == 4) {  
  133. $album = 'Bob Dylan'; 
  134. ?> 
  135. <table> 
  136. <tr> 
  137. <td> 
  138. <a href = index1.html>Back</a><br> 
  139. <h1>'Bob Dylan'</h1> 
  140. <h2>'Hurricane'</h2> 
  141. <img src="images/dylan.jpg" alt="Bob Dylan Desire" width="100" height="100"/> 
  142. <p><span class="style1">Track Titles:<br /> 
  143. <h3> 
  144. <ol>1. Hurricane</ol>  
  145. <ol>2. Isis</ol> 
  146. <ol>3. Mozambique</ol> 
  147. <ol>4. One More Cup of Coffee (Valley Below)</ol> 
  148. <ol>5. Oh, Sister</ol> 
  149. <ol>6. Joey</ol> 
  150. <ol>7. Romance in Durango</ol> 
  151. <ol>8. Black Diamond Bay</ol> 
  152. <ol>9. Sara</ol> 
  153. </h3> 
  154. </span><br /> 
  155. <iframe title="YouTube video player" width="480" height="290" src="http://www.youtube.com/embed/OLDSdnHWaSU" frameborder="0" allowfullscreen></iframe> 
  156. </p> 
  157. </td> 
  158. </tr> 
  159. </table> 
  160. <?php  
  161. }  
  162. elseif ($day == 5) {  
  163. $album = 'Robert Plant and Jimmy Page';  
  164. ?> 
  165.             <table> 
  166.               <tr> 
  167.             <td> 
  168.             <a href = index1.html>Back</a><br> 
  169.             <h1>Jimmy Page & Robert Plant </h1> 
  170.             <h2>'Houses Of Holy'</h2> 
  171.             <img src="images/housesofholy.jpg" alt="House of holy" width="100" height="100"/> 
  172.             <p><span class="style1">Track Titles:<br /> 
  173.             <h3> 
  174.             <ol>1 - The Song Remains The Same</ol>  
  175.             <ol>2 - The Rain Song</ol> 
  176.             <ol>3 - Over The Hills And Far Away</ol>  
  177.             <ol>4 - The Crunge</ol>  
  178.             <ol>5 - Dancing Daysv</ol>
  179.             <ol>6 - D yer Mak er</ol>  
  180.             <ol>7 - No Quarter</ol>  
  181.             <ol>8 - The Ocean</ol> 
  182.             </h3> 
  183.             <br /><iframe title="YouTube video player" width="480" height="290" src="http://www.youtube.com/embed/D3vs9y6CMrM" frameborder="0" allowfullscreen></iframe> 
  184.             </p> 
  185.             </td> 
  186.           </tr> 
  187.         </table> 
  188.         <?php  
  189.  
  190.           }  
  191.     elseif ($day == 6) {  
  192.             $album = 'Eric Clapton'; 
  193.             ?>
  194.             <table> 
  195.               <tr> 
  196.             <td> 
  197.             <a href = index1.html>Back</a><br> 
  198.             <h1>Eric Clapton,Jeff Beck,Jimmy Page</h1> 
  199.             <h2>"Layla"</h2> 
  200.             <img src="images/clapton.jpg" alt="Eric Clapton" width="100" height="100"/> 
  201.             <p><span class="style1">Track Titles:<br /> 
  202.                <h3> 
  203.                 <ol>1. Signe</ol> 
  204.                  <ol>2. Before You Accuse Me</ol>  
  205.                  <ol>3. Hey Hey</ol> 
  206.                 <ol>4. Tears in Heaven</ol>  
  207.                 <ol>5. Lonely Stranger</ol> 
  208.                 <ol>6. Nobody Knows You When Youre Down and Out</ol>  
  209.                 <ol>7. Layla</ol> 
  210.                 <ol>8. Running on Faith</ol>  
  211.                 <ol>9. Walkin Blues</ol> 
  212.                 <ol>10. Alberta</ol> 
  213.                 <ol>11. San Francisco Bay Blues</ol>  
  214.                 <ol>12. Malted Milk</ol> 
  215.                 <ol>13. Old Love</ol> 
  216.                 <ol>14. Rollin and Tumblin</ol> 
  217.             </h3> 
  218.     <br /> 
  219.     <iframe title="YouTube video player" width="480" height="290" src="http://www.youtube.com/embed/ICpxgxThG7s" frameborder="0" allowfullscreen></iframe> 
  220.             </span> 
  221.             <br /> 
  222.             </p> 
  223.             </td> 
  224.               </tr> 
  225.             </table>
  226.             <?php   
  227.           }
  228.           ?>   
  229.       </body>  
  230.     </html>  
  231.  
Apr 12 '11 #1
3 1914
Aimee Bailey
197 Expert 100+
Instead of giving you the answer which wouldnt really teach you much, here is a link to a very popular tutorial on the matter:

http://www.tizag.com/mysqlTutorial/

I encourage you to read it, as it will show you everything you need to know.

Aimee.
Apr 12 '11 #2
Thanks Aimee.
I have looked at this and started over again using code.
Still having some problems although smaller now!

Here is my new code. If it is something small I am doing can you let me know? Really appreciate your help.
Expand|Select|Wrap|Line Numbers
  1.  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  3. <html xmlns="http://www.w3.org/1999/xhtml"> 
  4. <head> 
  5. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> 
  6. <title>Album</title> 
  7. <link rel="stylesheet" type="text/css" href="homework.css"> 
  8. </head> 
  9. <body>  
  10. <?php  
  11. // get form selection  
  12. $day = $_GET['day']; 
  13.       // check value and select appropriate item 
  14.       if ($day == 1) { 
  15. $album = 'James Taylor'; 
  16.  
  17. // set database server access variables: 
  18.       $host = "testweb2.csis.ul.ie"; //localhost on your home PC/laptop
  19.       $user = "xxxxx"; //your ID number here
  20.       $pass = "xxxx"; //your password here
  21.       $db = "xxxxx"; //your ID number here
  22.  
  23.       // open connection 
  24.       $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); 
  25.  
  26.  
  27. // Get a specific result from the "Tracks" table
  28. $result = mysql_query("SELECT * FROM Tracks
  29.  WHERE album_number='1'") or die(mysql_error());  
  30.  
  31. // get the first (and hopefully only) entry from the result
  32. $row = mysql_fetch_array( $result );
  33. // Print out the contents of each row into a table 
  34. echo $row['track_number']." - ".$row['track_title'];
  35. ?>
  36.  
  37. <?php 
  38. }  
  39. elseif ($day == 2) { 
  40. $album = 'The Rolling Stones';  
  41.  
  42. // set database server access variables: 
  43.       $host = "testweb2.csis.ul.ie"; //localhost on your home PC/laptop
  44.       $user = "xxxxxxx"; //your ID number here
  45.       $pass = "xxxxxx"; //your password here
  46.       $db = "xxxxxx"; //your ID number here
  47.  
  48.       // open connection 
  49.       $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); 
  50.  
  51.  
  52. // Get a specific result from the "Tracks" table
  53. $result = mysql_query("SELECT * FROM Tracks
  54.  WHERE album_number='2'") or die(mysql_error());  
  55.  
  56. // get the first (and hopefully only) entry from the result
  57. $row = mysql_fetch_array( $result );
  58. // Print out the contents of each row into a table 
  59. echo $row['track_number']." - ".$row['track_title'];
  60. ?>
  61.  
  62.  
  63. <?php  
  64. }  
  65. elseif ($day == 3) {  
  66.  $album = 'Sting';  
  67.  
  68. // set database server access variables: 
  69.       $host = "testweb2.csis.ul.ie"; //localhost on your home PC/laptop
  70.       $user = "xxxxxxx"; //your ID number here
  71.       $pass = "xxxxxxx"; //your password here
  72.       $db = "xxxxxx"; //your ID number here
  73.  
  74.       // open connection 
  75.       $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); 
  76.  
  77.  
  78. // Get a specific result from the "Tracks" table
  79. $result = mysql_query("SELECT * FROM Tracks
  80.  WHERE album_number='3'") or die(mysql_error());  
  81.  
  82. // get the first (and hopefully only) entry from the result
  83. $row = mysql_fetch_array( $result );
  84. // Print out the contents of each row into a table 
  85. echo $row['track_number']." - ".$row['track_title'];
  86. ?>
  87.  
  88. <?php  
  89.  }  
  90. elseif ($day == 4) {  
  91. $album = 'Bob Dylan'; 
  92.  
  93. // set database server access variables: 
  94.       $host = "testweb2.csis.ul.ie"; //localhost on your home PC/laptop
  95.       $user = "xxxxxx"; //your ID number here
  96.       $pass = "xxxxx"; //your password here
  97.       $db = "xxxxxxx"; //your ID number here
  98.  
  99.       // open connection 
  100.       $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); 
  101.  
  102.  
  103. // Get a specific result from the "Tracks" table
  104. $result = mysql_query("SELECT * FROM Tracks
  105.  WHERE album_number='4'") or die(mysql_error());  
  106.  
  107. // get the first (and hopefully only) entry from the result
  108. $row = mysql_fetch_array( $result );
  109. // Print out the contents of each row into a table 
  110. echo $row['track_number']." - ".$row['track_title'];
  111. ?>
  112.  
  113. <?php  
  114. }  
  115. elseif ($day == 5) {  
  116. $album = 'Robert Plant and Jimmy Page';  
  117.  
  118. // set database server access variables: 
  119.       $host = "testweb2.csis.ul.ie"; //localhost on your home PC/laptop
  120.       $user = "xxxxx"; //your ID number here
  121.       $pass = "xxxxxx"; //your password here
  122.       $db = "xxxxxx"; //your ID number here
  123.  
  124.       // open connection 
  125.       $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); 
  126.  
  127.  
  128. // Get a specific result from the "Tracks" table
  129. $result = mysql_query("SELECT * FROM Tracks
  130.  WHERE album_number='5'") or die(mysql_error());  
  131.  
  132. // get the first (and hopefully only) entry from the result
  133. $row = mysql_fetch_array( $result );
  134. // Print out the contents of each row into a table 
  135. echo $row['track_number']." - ".$row['track_title'];
  136. ?>
  137.  
  138.         <?php  
  139.  
  140.           }  
  141.     elseif ($day == 6) {  
  142.             $album = 'Eric Clapton'; 
  143.  
  144. // set database server access variables: 
  145.       $host = "testweb2.csis.ul.ie"; //localhost on your home PC/laptop
  146.       $user = "xxxxxx"; //your ID number here
  147.       $pass = "xxxxxx"; //your password here
  148.       $db = "xxxxxx"; //your ID number here
  149.  
  150.       // open connection 
  151.       $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); 
  152.  
  153.  
  154. // Get a specific result from the "Tracks" table
  155. $result = mysql_query("SELECT * FROM Tracks
  156.  WHERE album_number='6'") or die(mysql_error());  
  157.  
  158. // get the first (and hopefully only) entry from the result
  159. $row = mysql_fetch_array( $result );
  160. // Print out the contents of each row into a table 
  161. echo $row['track_number']." - ".$row['track_title'];
  162. ?>
  163.             <?php   
  164.           }
  165.          ?>   
  166.     </body>  
  167. </html>  
  168.  
Apr 12 '11 #3
Dormilich
8,658 Expert Mod 8TB
Still having some problems although smaller now!
what smaller problems do you have? from my personal point-of-view there is a lot to do (starting with not using the outdated mysql functions), but that’s not something to throw at you yet.
Apr 12 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Agathe | last post by:
Bonjour, Je souhaite insérer dans une table MySQL des données provenant d'un fichier texte grâce à un script PHP. Mon fichier porte l'extension "txt" et les données sont séparées par des ";'. ...
2
by: Rootshell | last post by:
I need to create the table and I want to edit its content from www level. Here is some example: http://www.rootshell.be/~flash44 There is a table. Is there possibilty to edit the content...
2
by: David Heller | last post by:
I have this schema I exported from a database running mysql version 4.01 I'm trying to create this table on a server running mysql 3.23 I keep getting a syntax error near line 11 (I added the line...
2
by: m.k.ball | last post by:
Thanks Rich - that's great. Before I found this group, I thought I had a reasonable understanding of SQL (well, MySQL's implementation of it, at least) but the truth is there are great chunks that...
0
by: tomzam | last post by:
I'm trying to get mysql working on Fedora Core 4. Actually trying to start the program mysqld without fatal errors. I posted this message first on the linux misc group - but no luck so far. Maybe...
0
by: ponvijaya | last post by:
Hi all, i have date format as dd/mm/yy in my table field. I need to convert it into MySql Format YYYY-MM-DD . For example i need to convert the date 09/05/07 to 2007-05-09. Can a any body...
2
by: mandor | last post by:
Hello, I need some advise in table design, and more specifically about table partitioning. I read some papers and there was mentioned that if a table is expected to hold millions of rows, it's a...
1
by: Computernut234 | last post by:
Hi, i'm doing a project for my Java class and I know how to add text to a .txt document and remove the entire text but I do not know how to only remove certain parts of text. My code is supposed to...
2
by: viki1967 | last post by:
Hi everyone. My table mysql is: ID Dist Date Hour 15 LT 22/10/2009 08:56:05 14 RM 22/10/2009 08:55:20 13 RM 22/10/2009 08:55:19 12 RM 22/10/2009 08:51:22
0
by: mstres | last post by:
How to call Stored Function in Mysql from Access 2003 Access 2003 I am using as Front End and Access DB have a link table to MySql DB with ODBC connection Thank you Mike
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.