eddie barzoon Posted November 7, 2006 Share Posted November 7, 2006 Can anybody point me to some PHP examples that do the following:How to create a list of data (aka a recordset) from a database table,How to populate a dropdown list from an array. Quote Link to comment Share on other sites More sharing options...
Skatecrazy1 Posted November 7, 2006 Share Posted November 7, 2006 list of data from db table:[code]<?php$conn = @mysql_connect("server", "username", "password") or die(mysql_error());$rs = @mysql_select_db("database_name") or die(mysql_error());$sql = "SELECT * FROM `table`";$rs = @mysql_query($sql, $conn) or die(mysql_error());while($row = mysql_fetch_array($rs)){ $list .= "List values as ".$row['column_name']." here";}echo $list;?>[/code]Populating Dropdown from array:[code]<?php$arr = array("Option 1", "option 2", "option 3");$sel = "<select name=\"dropdown\">";$sel .= "<option selected>Select An Option</option>";foreach($arr as $menu){ $sel .= "<option>$menu</option>";}$sel .= "</select>";echo $sel;?>[/code] Quote Link to comment Share on other sites More sharing options...
Orio Posted November 7, 2006 Share Posted November 7, 2006 1) [url=http://www.freewebmasterhelp.com/tutorials/phpmysql/4]Read tutorials :)[/url]2) You should look into [url=http://www.php.net/foreach]the foreach loop[/url].Orio. Quote Link to comment Share on other sites More sharing options...
eddie barzoon Posted November 7, 2006 Author Share Posted November 7, 2006 I have a PHP book. I am in a web development class but the problem is our professor is so smart that he doesn't know how to teach this stuff to beginners. Here is a little bit more info. We have a test coming up next week and this is what he gave us to try out in order to prepare us:HTML: Download ex2fa05.txt and open it in NotePad, not in a browser. On the attached sheets, write the code that is needed to complete this file so that it will result in the form page below; be sure to follow the guidelines given in class for writing source code. The file for this page is to be within your exercises directory. The photo (pets3.jpg) is to be in your images directory, and the background image, pets.gif, should also be in that directory. The "Flybai-Knight Industries Home" link should refer to the home page of your root directory.[img]http://img.photobucket.com/albums/v310/jakz34/Table.jpg[/img] Write a stylesheet specifying style rules for the <body> element, a class called "centered", a class named "footnote", and the mouseover behavior for hyperlinks. Style rules for the <body> element should dictate a default font of arial 10 point, as well as the background image. The "centered" class should simply center any text involved, while the "footnote" class should do the same plus also specify an 8 point font. On mouseover, any given hyperlink should loose its underline, display with a gray background and bold white font color, and have its font size reduced by 5%. This stylesheet is to be located in your exercises directory and is to be used by all pages in this exercise. You'll also need a header (fbk_header2.shtml) and a footer (fbk_footer2.shtml), which are already written. These are to be stored in your root directory, and you are to utilize these as server-side includes.[color=green][b]This I have no problem with. I can do the HTML part just fine.[/b][/color]PHP:On the attached sheets, write the code that will process the inputs from the above form and produce the confirmation page below as well as the email message indicated in the reply shown following the confirmation page. The form processor uses the pet name supplied by the form page to look up the appropriate record in the PetInfo table of the test database (available to everyone on the SuSE1 server; refer to the exhibit on the last page of these instructions). In addition, if the pet is a dog, the <style> element specifies the background image to be dog3.gif (in the images directory). If the pet is a cat, then the background image is to be cat3.gif, but, if the pet is neither dog nor cat, the background image is just the default image use on the form page.[img]http://img.photobucket.com/albums/v310/jakz34/Results.jpg[/img][img]http://img.photobucket.com/albums/v310/jakz34/Email.jpg[/img]Database used in the application:[img]http://img.photobucket.com/albums/v310/jakz34/Database.jpg[/img][color=red][b]See, I don't understand this php part. I know how to write in the results of the HTML page so that things entered a user are processed by the php page but I am very lost on database issues. The class has asked questions but what we got in response was what I first posted. Any help in this matter would be greatly appreciated.[/b] Quote Link to comment Share on other sites More sharing options...
trq Posted November 7, 2006 Share Posted November 7, 2006 We dont' do homework. Ask a secific question and you should get help, otherwise, Ide be hitting that book. Quote Link to comment Share on other sites More sharing options...
eddie barzoon Posted November 7, 2006 Author Share Posted November 7, 2006 [quote author=thorpe link=topic=114171.msg464484#msg464484 date=1162931919]We dont' do homework. Ask a secific question and you should get help, otherwise, Ide be hitting that book.[/quote]I am not asking for my homework to be done. Maybe some pointers. I have hit the book and still don't really understand it. I am by no means asking anybody to actually do this though, I want to learn this not just get the grade. Quote Link to comment Share on other sites More sharing options...
trq Posted November 7, 2006 Share Posted November 7, 2006 Well you aksed for examples, Skatecrazy1 posted some, and then you came back with what you need done. What dont you understand from the examples? Quote Link to comment Share on other sites More sharing options...
eddie barzoon Posted November 7, 2006 Author Share Posted November 7, 2006 [quote author=thorpe link=topic=114171.msg464498#msg464498 date=1162933829]Well you aksed for examples, Skatecrazy1 posted some, and then you came back with what you need done. What dont you understand from the examples?[/quote]Well, I am not sure how those examples work in accordance with what is shown? I would make a drop down list with < option > elements with HTML what does populating it do? Quote Link to comment Share on other sites More sharing options...
eddie barzoon Posted November 7, 2006 Author Share Posted November 7, 2006 Also, I remember some code from class that also had WHERE and ORDER BY as well as FROM and SELECT. What is this pointing to? Quote Link to comment Share on other sites More sharing options...
trq Posted November 7, 2006 Share Posted November 7, 2006 [quote]Also, I remember some code from class that also had WHERE and ORDER BY as well as FROM and SELECT. What is this pointing to?[/quote]Really, if that is all you can remember from class it sounds like a bit of a lost cause. The code you speak of is SQL, and it is another language which is often used within php to query a database.As for [i]populating[/i] a dropdown form an array. This simply meens to [i]fill in[/i] the <option> elements with data stored in an array. 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.