SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    uganda
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help needed in creating views

    hello, am kind of new at php and i badly need assistance. i would to create a view where by some one can edit and delete whatever is in the database through the view. i have a page that lists the hostel name, location, email and contact address. i wanted it to be in such a way that if some one clicks on the hostel name it looks for the id of the hostel and lists details about that hostel and then from the view some one can then make deletions and modifications like updates.
    Last edited by aashaba; Jan 31, 2005 at 04:24.

  2. #2
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, you need to dynamically generate you're list of hostels from the DB. Each link should pass the hostel ID in the URL to a page where they can be edited.
    eg. if you're page to edit the the data is edit.php you would want your links to point to edit.php?id=1 to edit the first hostel.

    The edit.php page would need to get the id passed to it in the url (it would exist as $_GET['id']). Then you'd use that id to select all the information relating to that record from the DB.
    Run a select query, and populate your form with the resultant data.
    When the user submits that form you need to update the record with the new info.

    To delete I'd probably have a seperate button on the form.

    Its not especially complex, but there are a few different aspects to doing what you want.

    I had written some code for you, but I accidentally hit backspace and the browser went back a page and I lost it all. I don't have the patience to write it again

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    uganda
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually i generate a list of hostels in the database using the following code.

    <?php
    include ("../connection.php");

    $h0 = "select hostelName, hostelType, email, name from Hostel, Location where Hostel.locationId=Location.locationId order by hostelName";
    //$h0= "select hostelName, hostelType, email from Hostel order by hostelName";
    $h1=mysql_query($h0);
    ?>
    <html>
    <body>
    <h1> Hostel List</h1>
    <table border = "1" width ="50%"align ="center" bgcolor="#0000ff">
    <table border="2" width="100%" cellpadding="1">
    <tr>
    <tr><td width="25%"> Name </td><td width="25%">Location</td><td width="25%">Type</td><td width="25%">E-mail</td></tr>
    <?php
    while($h2=mysql_fetch_array($h1)){

    $h3 = $h2['hostelName'];
    // $h4 = $h2['name'];
    $h5 = $h2['hostelType'];
    $h6 = $h2['email'];
    ?>
    <tr><td width="25%"> <a href=<? "view.php?id=$h3"?>><? echo($h3) ;?></a> </td>
    <td width="25%" ><? echo($h4)
    ;?></td>
    <td width="25%"><? echo($h5);?></td>
    <td width="25%"><? echo($h6);?></td></tr>
    <? }?>
    </table>
    </body>
    </html>

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    uganda
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the problem am having is creating a view that can actually edit and delete.


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
  •