Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    New Coder
    Join Date
    Nov 2013
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Exclamation Getting mysql result in php

    Hey guys,
    Im coding a system for unit management. Basically i have the form which allows me to insert their details i.e name, age, location etc. I then have a table which outputs and displays their name. What i want to be able to do is click their name and allow it to bring up all their other details. So for example; I insert 'Fred' and his details into the form which then gets inserted into the MySql db. Freds name then displays in the table. I then click Freds name and it takes me to a page in which all his details are visible. I dont want to have to have a separate page for each person. I want to add the person, they then display on the table and their name because clickable and the details are then displayed.

    Hope you get the jist of what im trying to create and can help.
    Any help appreciated.
    Thanks,
    Ashton

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Hope you do not take this wrong, but I am betting 5 to 1 odds that this homework. For which see rules @ codingforums.com/rules.htm
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Nov 2013
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Thumbs up

    Quote Originally Posted by Old Pedant View Post
    Hope you do not take this wrong, but I am betting 5 to 1 odds that this homework. For which see rules @ codingforums.com/rules.htm
    I left education 2 years ago. Its a project i started about a month ago actually. Keep your snide comments to yourself please.

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Have you made the page that displays the list ?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,086
    Thanks
    23
    Thanked 593 Times in 592 Posts
    ashton, look into ajax.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • Users who have thanked sunfighter for this post:

    ashton324 (11-29-2013)

  • #6
    New Coder
    Join Date
    Nov 2013
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Have you made the page that displays the list ?
    Right now i have the form that will input the details into the DB. A table which displays their name from the DB. For the life of me i cannot figure out how to make the name clickable and for it to display a page with the rest of their details on. I will have 40+ names so i dont want to have 40+ different pages just one page that displays the details of the name clicked on...

    Quote Originally Posted by sunfighter View Post
    ashton, look into ajax.
    I have looked into AJAX but i don't think it will fulfil what i'm looking for.. If you can point me into some kind of direction with AJAX it will be helpful and appreciated.

    Thanks for the help guys.

  • #7
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    A table which displays their name from the DB. For the life of me i cannot figure out how to make the name clickable and for it to display a page with the rest of their details on.
    Please post your current PHP/HTML for this.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Snide comment??? Because I said this reads like a first or second assignment in a PHP class?

    Sorry, but it does. The fact that you don't know how to make a name clickable also means that you apparently need to learn HTML.

    There are *MANY* ways to do this. Examples:

    Using a drop down list, where choosing a name automatically brings up the details of that name:
    Code:
    <form. action="showDetails.php">
    <select name="nameToShow" onchange="this.form.submit();">
    <option>--choose a name--</option>
    <option>Adams, Ann</option>
    <option>Barnes, Bob</option>
    <option>Coleman, Carl</option>
    ... any number of such names ..
    </select>
    </form>
    Using individual links to bring up the details, using the id instead of the name to specify which person:
    Code:
    <a href="showDetails.php?id=3">Adams, Ann</a><br/>
    <a href="showDetails.php?id=5">Barnes, Bob</a><br/>
    <a href="showDetails.php?id=713">Coleman, Carl</a><br/>
    ...
    And there are any number of variations on that possible. You choose one and then we can help you implement it.

    Note that the choice of selecting via id or actual name is not terribly important. Typically you'll get better performance using the id, but if you don't have thousands and thousands of names to worry about you'll never see the difference.
    Last edited by Old Pedant; 11-29-2013 at 08:15 PM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    And by the way, either of those basic name selectors can easily be converted to use AJAX instead of doing full page replacement as they do as written.

    I would tend to agree with you that if you use the <a> method of displaying 40+ names then the page would be too crowded to also display the details about a single one of the names. (Though there's no technical reason it couldn't be done...just a matter of esthetics.) But clearly if you used a dropdown to choose the one name then it would be trivial and work well esthetically to use the 90% or so space still on the page to display the details of one person, so then AJAX would work quite well.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #10
    New Coder
    Join Date
    Nov 2013
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    Snide comment??? Because I said this reads like a first or second assignment in a PHP class?

    Sorry, but it does. The fact that you don't know how to make a name clickable also means that you apparently need to learn HTML.

    There are *MANY* ways to do this. Examples:

    Using a drop down list, where choosing a name automatically brings up the details of that name:
    Code:
    <form. action="showDetails.php">
    <select name="nameToShow" onchange="this.form.submit();">
    <option>--choose a name--</option>
    <option>Adams, Ann</option>
    <option>Barnes, Bob</option>
    <option>Coleman, Carl</option>
    ... any number of such names ..
    </select>
    </form>
    Using individual links to bring up the details, using the id instead of the name to specify which person:
    Code:
    <a href="showDetails.php?id=3">Adams, Ann</a><br/>
    <a href="showDetails.php?id=5">Barnes, Bob</a><br/>
    <a href="showDetails.php?id=713">Coleman, Carl</a><br/>
    ...
    And there are any number of variations on that possible. You choose one and then we can help you implement it.

    Note that the choice of selecting via id or actual name is not terribly important. Typically you'll get better performance using the id, but if you don't have thousands and thousands of names to worry about you'll never see the difference.
    I know how to make things clickable in HTML. My question is how do i make a result clickable in a table where the data is grabbed from a MySql db? Say for instance i have 4 names already in the DB and they are displayed in the table. I then add another one. The new name is automatically grabbed from the DB and displayed in the table at that point what is the best way to get that name to be clickable without adding separate code for every new name?
    Like you said in a later post about using the <a> method would be crowded and aesthetically ****e.

    Im guessing using ID would be the best option, but getting the name to be automatically clickable and then displaying the other data of the name, in either a separate page or using some form of AJAX method as you stated is new grounds for me...

    Here is the current code for the table which displays the newly added names.

    Code:
    <?php
    $mysql_host = 'localhost';
    $mysql_user = 'rro_tools';
    $mysql_password = '*******';
    $mysql_database = 'rro_tools';
    $mysql_table = 'interviews';
    $db = mysql_connect($mysql_host, $mysql_user, $mysql_password);
    mysql_select_db($mysql_database, $db);
    $sql = "SELECT Time_Of_Submission, cn, nint, Age, wya FROM ".$mysql_table;
    $result = mysql_query($sql, $db);
    ?>
    <table cellpadding="0" cellspacing="1" width="100%" class="sortable paginated">
    <thead>
       <tr>
          <th>Date</th>
          <th>Candidate Name</th>
          <th>Interviewer Name</th>
          <th>Age</th>
          <th>Possible Outcome</th>
       </tr>
    </thead>
    <tbody>
    <?php
    while ($row = mysql_fetch_row($result))
    {
       echo "   <tr>\n";
       foreach ($row as $cell)
       {
          echo "      <td>" . $cell . "</td>\n";
       }
       echo "   </tr>\n";
    }
    ?>
    There's a lot more code in the page but that is the main bit that displays the table etc.. If you need anymore just ask.

    Thanks,
    Ashton.

  • #11
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    But I *did* show you the answer, already. Here it is in SPECIFIC detail for your web page, starting at the $sql line:
    Code:
    $sql = "SELECT Time_Of_Submission AS tos, cn, nint, Age, wya FROM ".$mysql_table;
    $result = mysql_query($sql, $db);
    ?>
    <table cellpadding="0" cellspacing="1" width="100%" class="sortable paginated">
    <thead>
       <tr>
          <th>Date</th>
          <th>Candidate Name</th>
          <th>Interviewer Name</th>
          <th>Age</th>
          <th>Possible Outcome</th>
       </tr>
    </thead>
    <tbody>
    <?php
    while ($row = mysql_fetch_assoc($result))
    {
        $tos = $row["tos"]; // and then you could use PHP to format this as desired
        $cname = $row["cn"];
        $iname = $row["nint"];
        $age = $row["Age"];
        $wya = $row["wya"];
    
        echo "<tr>\n"
        . "    <td>$tos</td>\n"
        . "    <td><a href=\"showCandidate.php?name=$cname\">$cname</a></td>\n"
        . "    <td>$iname</td>\n"
        . "    <td>$age</td>\n"
        . "    <td>$wya</td>\n"
        . "</tr>\n";
    } // end of while loop
    ?>
    </tbody>
    </table>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    ashton324 (12-06-2013)

  • #12
    New Coder
    Join Date
    Nov 2013
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    But I *did* show you the answer, already. Here it is in SPECIFIC detail for your web page, starting at the $sql line:
    Code:
    $sql = "SELECT Time_Of_Submission AS tos, cn, nint, Age, wya FROM ".$mysql_table;
    $result = mysql_query($sql, $db);
    ?>
    <table cellpadding="0" cellspacing="1" width="100%" class="sortable paginated">
    <thead>
       <tr>
          <th>Date</th>
          <th>Candidate Name</th>
          <th>Interviewer Name</th>
          <th>Age</th>
          <th>Possible Outcome</th>
       </tr>
    </thead>
    <tbody>
    <?php
    while ($row = mysql_fetch_assoc($result))
    {
        $tos = $row["tos"]; // and then you could use PHP to format this as desired
        $cname = $row["cn"];
        $iname = $row["nint"];
        $age = $row["Age"];
        $wya = $row["wya"];
    
        echo "<tr>\n"
        . "    <td>$tos</td>\n"
        . "    <td><a href=\"showCandidate.php?name=$cname\">$cname</a></td>\n"
        . "    <td>$iname</td>\n"
        . "    <td>$age</td>\n"
        . "    <td>$wya</td>\n"
        . "</tr>\n";
    } // end of while loop
    ?>
    </tbody>
    </table>
    Brilliant! Thankyou! It's Working as expected, now what do i put in the 'showCandidate.php'? I guess its just a case of grabbing what the link posted and displaying it as a result?

    I modified the code abit to use ID instead of Name and actually noticed a difference in the query time.

    Thanks,
    Ashton

  • #13
    New Coder
    Join Date
    Nov 2013
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Dis-regard the part of what to put in the 'showcandidate.php' I had a mind block. So what i have done is changed the 'showcandidate.php' to the page name which has the table on it which is 'rro.php' i have one problem though. When i click the link on the table it does nothing. It just changes the link color from active to viewed but i dont see any result appear. I guess i am just missing something considering it is 2:00am. What am i missing?

    Thanks,
    Ashton

  • #14
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Bring up the page in your browser.

    Click on the browser's VIEW menu.

    Click on the SOURCE or PAGE SOURCE menu item of the view menu.

    Now you will be seeing the HTML source code AS THE BROWSER sees it.

    Copy/paste a few lines of the HTML <table> here so we can see what the browser is trying to handle.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #15
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    One possibility I just thought of: If a $cname (candidate name) contains any special characters, it would need to be encoded. If that's the problem, we could change
    Code:
    <a href=\"showCandidate.php?name=$cname\">
    to
    Code:
    <a href=\"showCandidate.php?name={urlencode($cname)}\">
    I *THINK* that is proper syntax. I don't use PHP, so I'm just going with what's in the PHP documentation.

    Worst come to worst, I know you could write it as
    Code:
    <a href=\"showCandidate.php?name=' . urlencode($cname) . '\">
    Note that this is in the middle of that long echo '....', of course.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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