SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    enhancing hacking to Kevin Yank's "Joke Database"

    dear all,
    trying to hack the joke database from K. Yank's immortal "Build Your Own Database..." to more cranky needs of my own, I want Search Results display not only the joke text as programmed by Kevin in Chapter 7:
    HTML Code:
    <h1>Search Results</h1>
    Code:
    <?php if(isset($jokes)):?>
    <table><tr><th> Joke Text</th><th>Options</th></tr>
    <?php foreach ($jokes as $joke):?>
    <tr valign="top">
    <td> <?php print($joke['text']);?></td>
    
    <td>
    <form action="" method="post">
    <div>
    <input type="hidden" name="id" value="<?php print($joke['id']);?>">
    <input type="submit" name="action" value="Edit">
    <input type="submit" name="action" value="Delete">
    </div></form>
    </td>
    </tr>
    <?php endforeach;?>
    </table>
    <?php endif;?>
    but also add values from the columns inserted by me to the table: comment_pro and comment_con.
    How to do it? Help! Please.

    yours` sehrguey

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    1) If needed, edit the query so it will return the new columns as well.
    2) If needed, edit the code where the query result set is loaded in the $jokes array, so the new columns are loaded as well.
    3) Edit the code you posted so the new columns will be displayed.

  3. #3
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thank you, sir Adviser

    Quote Originally Posted by guido2004 View Post
    1) If needed, edit the query so it will return the new columns as well.
    2) If needed, edit the code where the query result set is loaded in the $jokes array, so the new columns are loaded as well.
    3) Edit the code you posted so the new columns will be displayed.
    dear guido2004,
    I really liked your brilliant plan, faith I do, and I even implemented your #1 suggestion before pleading for help. Unfortunately, I have no idea how to realize #2 & #3 (the latter sounds rather close to the country music) otherwise I wouldn't bother the glorious geeks and other kinds of wise guys, would I?

    humbly yours`
    sehrguey

  4. #4
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    dear all,
    No matter how dearly love I "Build Your Own Database Driven Web Site Using PHP & MySQL" I still hezitate to come to a forum and say: Hey guys, go and read Kevin Yank's book and see if you can help me.
    But I don't have to!
    The instructions I got in this here forum were so clear-cut that the problem was solved:

    Code:
    <table border="1"> /*a wrapper table to keep additional columns on the same line with the initial one*/
    <tr><td>
    /*starts snippet from the book*/
    <?php if(isset($jokes)):?>
    <table><tr><th> Joke Text</th><th>Options</th></tr>
    <?php foreach ($jokes as $joke):?>
    <tr valign="top">
    <td> <?php print($joke['text']);?></td>
    
    <td>
    <form action="" method="post">
    <div>
    <input type="hidden" name="id" value="<?php print($joke['id']);?>">
    <input type="submit" name="action" value="Edit">
    <input type="submit" name="action" value="Delete">
    </div></form>
    </td>
    </tr>
    <?php endforeach;?>
    </table>
    <?php endif;?>
    </td>
    /* the snippet ends and is followed by 2 additional td containing the values in db*/
    <td>
    <?php if(isset($jokes)):?>
    <table>
    <?php foreach ($jokes as $comment_pro):?>
    <tr valign="top">
    <td> <?php print($comment_pro['comment_pro']);?></td>
    </tr>
    <?php endforeach;?>
    </table>
    <?php endif;?>
    </td>
    
    <td>
    <?php if(isset($jokes)):?>
    <table>
    <?php foreach ($jokes as $comment_con):?>
    <tr valign="top">
    <td> <?php print($comment_con['comment_con']);?></td>
    </tr>
    <?php endforeach;?>
    </table>
    <?php endif;?>
    </td></tr></table>
    Thank you guido2004!
    But...
    Well, it works ok, just as I wanted when starting this thread but now I wanna more!

    What can I do to have the rows in the table retrived from database be easily distinguished by their background-color (stripes of white and gray, you know).
    That trick was not covered in Kevin's book and I don't know where to look for the answer.

    yours`
    sehrguey

  5. #5
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    @kyankli

    from the sitepoint reference http://reference.sitepoint.com/css/pseudoclass-nthchild:


    CSS3: nth-child support:
    IE8 FF3.5+ SA3.1+ OP9.5+ CH2+
    none Full Full Full Full

    CSS3 styles for modern browsers. Using a table as an example
    HTML Code:
    tr:nth-child(odd) {
      background-color: #Some_Color;
    }
    tr:nth-child(even) {
      background-color: #Some_Other_Color;
    }
    To deal with older browsers jQuery also has a way to handle it. Using a table as an example:
    Code:
    if($.browser.msie && $.browser.version < 9) {
      $('tr:odd').addClass('odd');
      $('tr:even').addClass('even');
    }
    Not PHP but works.

    Regards,
    Steve
    ictus==""

  6. #6
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Steve,
    thank you ever so much for your kind attention and help.
    Actually, css3 didn't work for my case or maybe I didn't implement it the right way in my tries.
    The good news is I finally found a working PHP solution. Here is the link
    'http://www.phpro.org/examples/Alternating-Row-Colors.html'
    The solution turned out to be so elegant and simple - here's my hat to the programmer-guy.
    All's well that end's well.
    Good luck.
    yours`
    sehrguey


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
  •