How to display db fields in a html table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
zplits
Forum Contributor
Posts: 158
Joined: Sun Aug 03, 2008 8:59 pm

How to display db fields in a html table

Post by zplits »

Hello everyone. good day, I'm wondering how am i be able to display all database fields except for the id field. I am creating a add ingredient form. When the user clicks the save button, it will display the newly save information just below the form, together with it in a row. So in one row, first a checkbox, then the code, description, quantity and unit of measure, and at the end of unit of measure there will be a button named Edit.

This is information will be just in a single row. By the way the purpose of the checkbox will be to enable the user to select many rows and delete it, because there will be a delete button, once the row is checked and the user clicked the delete button, it will delete the selected row. While when the user will click edit at the end of every row, it will enable the user to edit the information, the data of the clicked row will be loaded in the form and the user will be able to update it.

Any help is deeply appreciated.
Thanks in advance.
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: How to display db fields in a html table

Post by WebbieDave »

Seems pretty straight forward. There are plenty of tutorials online that show you how to do basic MySQL/PHP driven forms. You'll want to peruse these as well as a good book on the subject. Once you get some code together and you run into snags, we'll be able to help you untangle them here :)
User avatar
zplits
Forum Contributor
Posts: 158
Joined: Sun Aug 03, 2008 8:59 pm

Re: How to display db fields in a html table

Post by zplits »

Is it possible? checkbox,code,name,quantity,unit of measure, edit button in a single row in the table?
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: How to display db fields in a html table

Post by WebbieDave »

Yes and yes. Once the edit button is clicked, you can populate the form with Javascript or just do it server-side. It's up to you.
User avatar
zplits
Forum Contributor
Posts: 158
Joined: Sun Aug 03, 2008 8:59 pm

Re: How to display db fields in a html table

Post by zplits »

Wow, thanks for the response. I didn't think was possible, because my samples here are written in vb, so i there's no grid in html, so i have thought it was going to be that i should use table.

Do you know how to do it?
by the way thank you very much for the help. really appreciated
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: How to display db fields in a html table

Post by WebbieDave »

zplits wrote:Do you know how to do it?
I do. But which part exactly do you need help with?
User avatar
zplits
Forum Contributor
Posts: 158
Joined: Sun Aug 03, 2008 8:59 pm

Re: How to display db fields in a html table

Post by zplits »

After the user clicks the save button. The page refreshes then below the form, the newly stored values will be displayed in one row, together with a checkbox and the edit button.

Please help me, thank you very much. if you don't mind i have a screenshot here. http://img254.imageshack.us/img254/7103/ingreoy7.jpg
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: How to display db fields in a html table

Post by WebbieDave »

You're saying you need help with the entire thing? HTML, Javascript, PHP and MySQL?
User avatar
zplits
Forum Contributor
Posts: 158
Joined: Sun Aug 03, 2008 8:59 pm

Re: How to display db fields in a html table

Post by zplits »

If you can. I think it will be much better, i never tried to create form elements using php. I'm a total newbie. But i don't want to, well, it's still okay.

Thank you.
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: How to display db fields in a html table

Post by WebbieDave »

I'm more than willing to help with questions related to PHP code you've written. But it sounds like you want me to go to work for you. In that case, I have an hourly rate ;) Give it your best shot. When you run into problems while coding, post it. Then we'll be in a much better position to help.
User avatar
zplits
Forum Contributor
Posts: 158
Joined: Sun Aug 03, 2008 8:59 pm

Re: How to display db fields in a html table

Post by zplits »

Oh. I'm so sorry sir. I think i have wasted your time? I'm just a poor boy with limited knowledge in php. I won't be able to pay your hourly rate. All i can say is that I'm thankful for the help. I really appreciate it.

If i figure this out. I'll post the whole code here, and hope that someone might benefit to what i have done.

cheers. I'm sorry if i wasted your time.
Thanks a lot for the info
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: How to display db fields in a html table

Post by WebbieDave »

You're very welcome. Best of luck to you.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: How to display db fields in a html table

Post by JAB Creations »

It's always best to look at other's code. Here is the code I'm using to spit out a looping query where a table is created to display a list of members. It's in it's early stages still though this should help you move forward...

Code: Select all

<table summary="This table displays registered members at this website.">
<colgroup style="width: 10%;"></colgroup>
<colgroup style="width: 10%;"></colgroup>
<colgroup style="width: 10%;"></colgroup>
<colgroup style="width: 10%;"></colgroup>
<colgroup style="width: 10%;"></colgroup>
<colgroup style="width: 55%;"></colgroup>
<thead>
<tr><td>Name</td><td>Gender</td><td>Status</td><td>Joined</td><td>Last Visit</td><td>Website</td></tr>
</thead>
<tfoot>
<tr><td>Name</td><td>Gender</td><td>Status</td><td>Joined</td><td>Last Visit</td><td>Website</td></tr>
</tfoot>
<tbody>
<?php
include("themes/mysql.php");
//$db_selected = mysql_select_db("jabcreat_members", $db); /* used in mysql.php for this project*/
$result = mysql_query("SELECT id, username, gender, status, date_0, date_1, ip_0, ip_1, website FROM `public_accounts`") or die(mysql_error());
 
while($row = mysql_fetch_array( $result ))
{
 echo '<tr id="member_'.$row['id'].'"><td><a href="members.php?user='.$row['id'].'">'.$row['username'].'</a></td>';
 echo '<td>'.$row['gender'].'</td>';
 echo '<td>'.$row['status'].'</td>';
 echo '<td>'.$row['date_0'].'</td>';
 echo '<td>'.$row['date_1'].'</td>';
 echo '<td><a href="messages.php?message='.$row['id'].'" onblur="row_blur(\'member_'.$row['id'].'\');" onfocus="row_focus(\'member_'.$row['id'].'\');">';
 if (strlen($row['comments']) > 72) {echo substr($row['comments'], 0, 72).'...';} else {echo $row['comments'];}
 echo $row['website'].'</a></td></tr>'."\n";
}
?>
</tbody>
</table>
User avatar
zplits
Forum Contributor
Posts: 158
Joined: Sun Aug 03, 2008 8:59 pm

Re: How to display db fields in a html table

Post by zplits »

Thanks for the code sir. I have successfully displayed it, but one thing is not working. well, I have drop down menu for the measurement field. Here is the code for my drop down list box:

Code: Select all

<select name="measurement" size="1" class="formFieldsDropDown" id="measurement" tabindex="4">
                      <option value="1">kilogram(s)</option>
                      <option value="2">gram(s)</option>
                      <option value="3">Liter(s)</option>
                      <option value="4">milliLiter(s)</option>
                      <option value="5">lb(s)</option>
                      <option value="6">pc(s)</option>
                      <option value="7">gallon(s)</option>
                      <option value="8">sack(s)</option>
                      <option value="9">ounce(s)</option>
                  </select>
When i want to display the values from my database table, it says 1 not the word kilogram(s)
Any fix?
Gevie
Forum Newbie
Posts: 5
Joined: Sun Aug 31, 2008 2:43 pm

Re: How to display db fields in a html table

Post by Gevie »

use something along the lines of

Code: Select all

 
$kilograms_selected = ($row['measurement'] == 1) ? "selected='selected'" : NULL;
 
 
 
for each type of measurement

then in your options do the following

Code: Select all

 
<option value="1" {$kilograms_selected}>Kilogram(s)</option>
 
You'd have to repeat it for each option, it is dirty, I prefer using loops.
Then if the value from the DB is equal to 1 in this example, kilograms will be selected.
Otherwise it will select a different option where it is equal.

$row['measurement'] is an example being your value from the field for that particular row.

Best of Luck.
Post Reply