SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict
    Join Date
    Nov 2006
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb Selecting Records after output (PHP Oriented)

    I'm not sure whether this is more qualified in the PHP section or the MySQL section but I kind of want to hear what SQL people have to say first.

    I want the user to be able to select a specific record after it has been rendered to edit it. For example

    Consider the following html/php document
    PHP Code:
    <p>Contacts</p>
      <table>
        <tr>
          <th>FirstName</th>
          <th>LastName</th>
          <th>Phone</th>
          <th>Email</th>
        </tr>

      <?php while($contact_result_row mysql_fetch_array($contact_resultMYSQL_BOTH)){ ?>
         <tr>
        <td> <?php echo $contact_result_row['FirstName']; ?> </td>
        <td> <?php echo $contact_result_row['LastName']; ?> </td>
        <td> <?php echo $contact_result_row['Phone']; ?> </td>
        <td> <?php echo $contact_result_row['EmailAddress']; ?> </td>
          </tr>
      <?php  ?>
      </table>
    This simply displays a table of all the data within a query.
    So let say I wanted to select the third record from the table maybe I could add a button to edit each record for each row.
    My question is, once the user clicks this button how does the program know which record to jump to.

    Do I make a variable array where each time the while loop initiates it saves the row id into a variable called $contact[$i]? Or what other methods could I use because I have one big query, and then two sub queries on the same page to display data for each individual row of the first query.

    (Kind of like a subform within a form like in MSAccess)

    Thank you for replies.
    Please...Never describe anything to me using foo and bar.

  2. #2
    SitePoint Addict
    Join Date
    Nov 2006
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess this is the best answer, I was hoping for something more creative:
    http://www.phpeasystep.com/mysql/9.html
    Please...Never describe anything to me using foo and bar.

  3. #3
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by prince_mallow View Post
    ..., I was hoping for something more creative:
    Interesting choice of phrase, what would you describe as a 'creative' solution?
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,194
    Mentioned
    17 Post(s)
    Tagged
    4 Thread(s)
    You can achieve this only using PHP but it is going to make for a very static and unfriendly user experience. The best solution would be to use JavaScript in addition to PHP to support a persistent interface for modifying the data.

  5. #5
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Another option is to add an edit button next to each user record in the html table.

    The edit button has an onclick even handler which points to a url with a query string attached containing the userID (from the database) for that user.

    The url points to a web page containing a form with inputs to edit the database table the original user data came from.

    The inputs in the form are then updated as required and submitted to a server side script to update the database record for that userID.

  6. #6
    SitePoint Addict
    Join Date
    Nov 2006
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Very good comments,

    @AnthonySterling by creative solutions, I guess I would say a modular design would be creative, nothing like calling a chunk of code repeatedly and getting different results based on results.

    @oddz I was hoping to avoid javascript for now and make version 2.0 AJAX (after I learn it...) Javascript is not my forte
    albeit though
    @Kalon solutions seems to be a good temporary solution, despite my anxiety about javascript.
    Please...Never describe anything to me using foo and bar.

  7. #7
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by prince_mallow View Post
    I was hoping to avoid javascript for now and make version 2.0 AJAX (after I learn it...) Javascript is not my forte
    I assume you are aware that AJAX is javascript.

    AJAX is not a different language. It is just a particular technique in using javascript.

  8. #8
    SitePoint Addict
    Join Date
    Nov 2006
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kalon View Post
    I assume you are aware that AJAX is javascript.

    AJAX is not a different language. It is just a particular technique in using javascript.
    Lol yes I did know. It's funny actually I am afraid of javascript because I don't want to write code that can be altered to do things I don't want it to do. And today our ad server (which uses javascript) just got hacked and is serving malware [don't worry i am not deterred me from learning it]
    Please...Never describe anything to me using foo and bar.


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
  •