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:

<h1>Search Results</h1>
<?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

  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

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:

<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

@kyankli

from the sitepoint reference http://reference.sitepoint.com/css/pseudoclass-nthchild:
[TABLE=“class: browsers, width: 312”]
[TR]
[/TR]
[/TABLE]

CSS3: nth-child support:
[TABLE=“class: grid, width: 40”]
[TR]
[TD]IE8[/TD]
[TD]FF3.5+[/TD]
[TD]SA3.1+[/TD]
[TD]OP9.5+[/TD]
[TD]CH2+[/TD]
[/TR]
[TR]
[TD]none[/TD]
[TD]Full[/TD]
[TD]Full[/TD]
[TD]Full[/TD]
[TD]Full[/TD]
[/TR]
[/TABLE]

CSS3 styles for modern browsers. Using a table as an example


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:


if($.browser.msie && $.browser.version < 9) {
  $('tr:odd').addClass('odd');
  $('tr:even').addClass('even');
}

Not PHP but works.

Regards,
Steve

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