SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Aug 2000
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i think i understand what you are getting at.

    i need to have something like:

    $eid = mysql_quey("SELECT Name FROM Employee");

    i will give this a try...



    ------------------
    bl@cky

  2. #2
    SitePoint Member
    Join Date
    Aug 2000
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    first off i am a newbie, second i ain't the sharpest knife in the kitchen.

    here is what i have done. i have done and completed the mysql/php tutorial about making a joke database.
    well now i want to customize it. I want to create an employee directory. i think i have done pretty good up until now.

    1st problem:
    i have created(or i should say, i am trying to) a page that lets you select the employee you want to get info. about and then sends you to a page that displays this info. the problem is that no matter what name i select it pulls up everyone in the database.

    2nd problem: i have created a page that inputs data into the database. but it only inputs the name of the employee and no other info.

    i will post the pages in the following post.






    ------------------
    bl@cky

  3. #3
    SitePoint Member
    Join Date
    Aug 2000
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1st problem:<!-- employeeprofiles.php -->
    <HTML>
    <HEAD>
    <TITLE> Employee Profiles </TITLE>
    </HEAD>
    <BODY>
    <H1> Employee Profiles </H1>

    <?php

    $dbcnx = @mysql_connect("localhost", "root", "password");
    mysql_select_db("EmployeeProfiles");

    $employees = mysql_query("SELECT ID, Name FROM Employee");
    $bizs = mysql_query("SELECT ID, Name FROM BusinessGroup");
    ?>

    <FORM ACTION="jokelist.php" METHOD=POST>
    <P>View Employees:<BR>
    By Employee:
    <SELECT NAME="aid" SIZE=1>
    <OPTION SELECTED VALUE="">Any Employee
    <?php
    while ($employee = mysql_fetch_array($employees)) {
    $eid = $employee["ID"];
    $ename = $employee["Name"];
    echo("<OPTION VALUE='$eid'>$ename\n");
    }
    ?>
    </SELECT><BR>
    By Business Group:
    <SELECT NAME="bid" SIZE=1>
    <OPTION SELECTED VALUE="">Any Business Group
    <?php
    while ($biz = mysql_fetch_array($bizs)) {
    $bid = $biz["ID"];
    $bname = $biz["Name"];
    echo("<OPTION VALUE='$bid'>$bname\n");
    }
    ?>
    </SELECT><BR>
    <!-- Containing Text: <INPUT TYPE=TEXT NAME="searchtext"> --><BR>
    <INPUT TYPE=SUBMIT NAME="submit" VALUE="View">
    </FORM>
    <BR>
    <P ALIGN=CENTER><A HREF="newjoke.php">Create New Employee Profile</A></P>
    <P ALIGN=CENTER><A HREF="admin.html">Return to Front Page</A></P>
    </BODY>

    <!-- employeeinfo.php -->
    <HTML>
    <HEAD>
    <TITLE> employee information</TITLE>
    </HEAD>
    <BODY>
    <H1>Manage Jokes</H1>
    <P><A HREF="jokes.php">New Search</A></P>
    <?php

    $dbcnx = @mysql_connect("localhost", "root", "password");
    mysql_select_db("EmployeeProfiles");

    // The basic SELECT statement
    $select = "SELECT DISTINCT ID, Name";
    $from = " FROM employee";
    $where = " WHERE ID > 0";

    if ($bgid != "") { // An author is selected
    $from .= ", businessgroup";
    $where .= " AND name=$bgid";
    }
    ?>

    <TABLE BORDER=1>
    <TR><TH>Name</TH><TH>Position</TH><TH>Extention</TH><TH>Birthday</TH><TH>Home Address</TH><TH>Home Phone</TH></TR>

    <?php
    $employees = mysql_query($select . $from . $where);
    if (!$employees) {
    echo("</TABLE>");
    echo("<P>Error retrieving employees from database!<BR>".
    "Error: " . mysql_error());
    exit();
    }

    while ($employee = mysql_fetch_array($employees)) {
    echo("<TR>\n");
    $name = $employee["Name"];
    $postition = $employee["Position"];
    $extention = $employee["Extention"];
    $birthday = $employee["Birthday"];
    $homeaddress = $employee["HomeAddress"];
    $homephone = $employee["HomePhone"];
    $bgid = $empployee["bgid"];
    echo("<TD>$name</TD>\n");
    echo("<TD>$position</TD>\n");
    echo("<TD>$extention</TD>\n");
    echo("<TD>$birthday</TD>\n");
    echo("<TD>$homeaddress</TD>\n");
    echo("<TD>$homephone</TD>\n");
    echo("<TD>$bgid</TD>\n");

    }
    ?>

    </TABLE>
    </BODY>


    2nd problem:


    <!-- addnewemployee.php -->
    <HTML>
    <HEAD>
    <TITLE> Add New Employee </TITLE>
    </HEAD>
    <BODY>
    <?php

    if ($submit): // A new employee has been entered
    // using the form below.

    $dbcnx = @mysql_connect("localhost", "root", "password");
    mysql_select_db("EmployeeProfiles");

    $sql = "INSERT INTO employee SET " .
    "Name='$name', " .
    "Position='$poistion', " .
    "Extention='$extention', " .
    "Birthday='$birthday', " .
    "HomeAddress='$homeaddress', " .
    "HomePhone='$homephone', " .
    "bgid='$bgid'";
    if (mysql_query($sql)) {
    echo("<P>New employee added</P>");
    } else {
    echo("<P>Error adding new employee: " .
    mysql_error() . "</P>");
    }

    ?>

    <P><A HREF="<?php echo($PHP_SELF); ?>">Add another Employee</A></P>
    <P><A HREF="authors.php">Return to Employee Profile list</A></P>

    <?php
    else: // Allow the user to enter a new employee
    ?>

    <FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST>
    <P>Enter the new employee:<BR>
    Name: <INPUT TYPE=TEXT NAME="name" SIZE=20 MAXLENGTH=100><BR>
    Position: <INPUT TYPE=TEXT NAME="position" SIZE=20 MAXLENGTH=100><BR>
    Extention: <INPUT TYPE=TEXT NAME="extention" SIZE=20 MAXLENGTH=100><BR>
    Birthday: <INPUT TYPE=TEXT NAME="birthday" SIZE=20 MAXLENGTH=100><BR>
    Home Address: <INPUT TYPE=TEXT NAME="homeaddress" SIZE=20 MAXLENGTH=100><BR>
    Home Phone: <INPUT TYPE=TEXT NAME="homephone" SIZE=20 MAXLENGTH=100><BR>
    By Business Group:
    <SELECT NAME="bgid" SIZE=1>
    <OPTION SELECTED VALUE="">Any Business Group
    <?php

    $dbcnx = @mysql_connect("localhost", "root", "password");
    mysql_select_db("EmployeeProfiles");

    $employees = mysql_query("SELECT ID, Name FROM Employee");
    $bizs = mysql_query("SELECT ID, Name FROM BusinessGroup");

    while ($biz = mysql_fetch_array($bizs)) {
    $bid = $biz["ID"];
    $bname = $biz["Name"];
    echo("<OPTION VALUE='$bid'>$bname\n");
    }
    ?>
    </SELECT><BR>

    <INPUT TYPE=SUBMIT NAME="submit" VALUE="SUBMIT"></P>
    </FORM>

    <?php endif; ?>

    </BODY>

    I am sorry for making such a long post, but i
    have become rather lost. anyone have any clue
    as to what i need to fix ?


    ------------------
    bl@cky

  4. #4
    SitePoint Member
    Join Date
    Aug 2000
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    me again

    well i have fixed the input data problem,
    but still it is not pulling only the data about name i select.....

    ------------------
    bl@cky

    [This message has been edited by blacky (edited August 11, 2000).]

  5. #5
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,939
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I've done very little PHP but I think I can still help you out.

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>
    // The basic SELECT statement
    $select = "SELECT DISTINCT ID, Name";
    $from = " FROM employee";
    $where = " WHERE ID &gt; 0";
    [/code]

    You need to put something more in your Where criteria.

    SQL is a very logical language think of this example "Select name from elephants where color like pink"

    That would give you a list of the names of pink elephants, get it?

    So what you need is


    <BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>
    // The basic SELECT statement
    $select = "SELECT DISTINCT ID, Name";
    $from = " FROM employee";
    $where = " WHERE ID = $eid";
    [/code]

    Chris

  6. #6
    is very happy now :) Itay Neeman's Avatar
    Join Date
    Jun 2000
    Location
    Israel
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HI Blacky,

    I think your employeeinfo.php file should include mainly a select statement which includes the variable for employeeprofile.php which will select this specific employee, and then the same code but without the while function... Just use If or anything else... but while just keeps getting everyone until its false...

    ------------------
    Best Regards,
    Itay Neeman

  7. #7
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,939
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No blacky you misunderstood me I think.

    Your where statement before said "where id &gt; 0"

    that will return every instance where an ID is greater than 0.

    What you need to do is pass a variable to it, so you can get something like this:

    "where id = 7596"

    so the statement would look like this

    where id = $variablename

    Chris


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •