Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie - Html Table

Status
Not open for further replies.

cogdev

MIS
Nov 30, 2001
85
US
I am trying to display data in a table. here is what I have so far:

$result = mysql_query("select * from tbl_regist_cube_term_heads where gender = '$selGender' ", $db);
// display all the different courses from tbl_lkp_course_subject in the select list
while ($myrow = mysql_fetch_array($result))
{
printf("<option>%s</option>\n",$myrow["gender"]);
printf("<option>%s</option>\n",$myrow["major"]);
}



of course this produces a jumbled output. I would like this displayed in columns.

 
Interesting. The [tt]<option></option>[/tt] tags are the inner workings of a [tt]select[/tt] box.

I think what you want is something like this:

[tt]
// start table
echo '<table border="1">';

// query database
$result = mysql_query("select * from tbl_regist_cube_term_heads where gender = '$selGender'", $db);

// loop through records, printing new row for each
while ($myrow = mysql_fetch_array($result)) {
printf("<tr><td>%s</td>\n",$myrow['gender']);
printf("<td>%s</td></tr>\n",$myrow['major']);
}

// close table
echo '</table>';
[/tt]

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
Thanks. How can I insert headings for the Columns. This code displays the field with no headings.
 
You mean something like this?

[tt]
// start table
echo '<table border="1">';
echo '<tr>';
echo '<th>gender</th>';
echo '<th>major</th>';
echo '</tr>';

// query database
$result = mysql_query("select * from tbl_regist_cube_term_heads where gender = '$selGender'", $db);

// loop through records, printing new row for each
while ($myrow = mysql_fetch_array($result)) {
printf("<tr><td>%s</td>\n",$myrow['gender']);
printf("<td>%s</td></tr>\n",$myrow['major']);
}

// close table
echo '</table>';
[/tt]


*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
Here is the Full Code Listing:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE></TITLE>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</HEAD>

<BODY>
<?php

if ($selCrsOrDept == "G" and $selGender == "S")
{
echo "Please selecet a select gender";
}
else {
$db = mysql_connect("server","username","passord")
or die("001 - Connection Failed");
mysql_select_db("idbr", $db);
$result = mysql_query("select * from tbl_regist_cube_term_heads where gender = '$selGender' ", $db);

//printf("<strong>Gender: </strong> %s", $selGender);
// start table
echo '<table border="1">';
echo '<tr>';
echo '<th>gender</th>';
echo '<th>major</th>';
echo '</tr>';

// query database
$result = mysql_query("select * from tbl_regist_cube_term_heads where gender = '$selGender'", $db);

// loop through records, printing new row for each
while ($myrow = mysql_fetch_array($result)) {
printf("<tr><td>%s</td>\n",$myrow['gender']);
printf("<td>%s</td></tr>\n",$myrow['major']);


// close table
echo '</table>';
}}
?>

</Body>
</html>



this is giving me a single row of data, and the other 100+ rows are just jumbled...what am I missing here?
 
You are closing the table WITHIN the while loop. This line: [tt]echo '</table>';[/tt] should be AFTER the first [tt]}[/tt].

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
Move one of the closing "}" to before your close table. If you looked at the generated code you would have seen 100 "</table>" tags.

Ken
 
Thanks a lot. You obviously know this stuff inside out...secrets to being like you?
 
Practice.
Experience.
Experience.
Experience.

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
So this is working. I want to insert an additional row in my table that printes the value of the $selGender Variable.
How can I do that?


I guess this is the pseudocode:

echo '<th>printf("<strong>Gender: </strong> %s", $selGender);</th>';


Thanks for your help.
 
For a cell to display properly, it needs surrounding [tt]<tr></tr>[/tt] (table row) tags.

Furthermore, because there are two columns in your table, you'll need to either stick with two cells or use the [tt]colspan[/tt] property of the cell.

But I'm confusing you.

This variable doesn't need to be placed in each row as a new cell, because you're not getting it from the database, are you?

Do you want it to look like this?
[tt]
selGender = S

gender | major
------------------------
m | accounting
m | math
f | education
[/tt]
OR do you want it to look like this?
[tt]

gender | major | selgender
-------------------------------------
m | accounting | s
m | math | s
f | education | s
[/tt]

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
$selgender is actually a filter on gender..so what is want is :

-------------------
Gender: M
-------------------
Gender | Major|
M Accounting
M
M


Eventually I will take out gender from the columns and display other attributes.
 
You don't need to do this within the table. You could enter this line of code right before the [tt]echo '<table>';[/tt] line of code:

[tt]echo 'Gender: ' . $selGender . '<br>';[/tt]

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
Thanks. But eventually my selection will grow and I will want to display the selection variables in a tabular form. if I wanted something like this:

----------------------------------------------------
Report Name Description etc
---------------------------------------------------
Gender: F | Country : Can | Date:...|
-------------------------------------------------
-------------------------------------------------
Major | GPA | Level |
-------------------------------------------------
M 4 2
A
T
E


Thanks for your patience...is this making sense?
 
So what is it that you want to do? Put the selection values in a new table?

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
No. The table will have a header section that just displays the selection values, the currebt date etc. This way if a user prints the output they will know what the filters were. And for the purpose of presentation I would like to have all this done in a single table...well maybe two tables that joined?

 
OK.

Well, I've given you the code you need to get this functionality. If you need further help with HTML basics, there are a miriad of resources on the internet.

With the PHP I've given you, and this link, you should be able to get what you need.

Hope that helps.


*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
Thank you very much...your patience is much appreciated
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top