Jump to content

Example PHP Code


eddie barzoon

Recommended Posts

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]
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

[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?






Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.