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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check Boxes 3

Status
Not open for further replies.

je150

IS-IT--Management
Jun 10, 2003
33
US
Hello, i am trying to create an interface to a MySQL database for access into email addresses by name. I wrote the following code that allows me to view all entries in the database in their appropriate fields. The problem comes in when i want to create a check box next to them. Ive looked through online documentation to no avail, other than telling me how to do this with HTML, which i know. The problem is when this is done with HTML as i have done, they dont appear to the left of each choice but rather at the top of the page in one giant block of check boxes.


print &quot;<DIV ALIGN=\&quot;Left\&quot;>&quot;;
print &quot;<TABLE WIDTH=100% BORDER=\&quot;1\&quot; CELLPADDING=\&quot;0\&quot; bgcolor=\&quot;#ABDEFC\&quot;>&quot;;
print &quot;<center><TR><TH>Select</th>&quot;;
print &quot;<TH>Name</th>&quot;;
print &quot;<TH>Department</th>&quot;;
print &quot;<TH>Email</th>&quot;;;
print &quot;</center></tr>&quot;;
if (isset($order)) {
$sorted=$order;
} else {
$sorted=&quot;name&quot;;
}
$table=&quot;employees&quot;;
$result = mysql_query(&quot;SELECT * FROM `$table` ORDER BY `$sorted`&quot;) or die(&quot;Error: &quot; . mysql_error());
$nb = mysql_num_rows($result);

while ($row = mysql_fetch_array($result)) {
$select = &quot;<small>&quot; . str_replace(&quot;\n&quot;,&quot;\n&quot;, print &quot;<form><tr><input type=checkbox></tr></form>&quot;) . &quot;</small>&quot;;
$name = &quot;<small>&quot; . str_replace(&quot;\n&quot;,&quot;\n&quot;,$row[&quot;name&quot;]) . &quot;</small>&quot;;
$department = &quot;<small>&quot; . str_replace(&quot;\n&quot;,&quot;\n&quot;,$row[&quot;dept&quot;]) . &quot;</small>&quot;;
$email = &quot;<small>&quot; . str_replace(&quot;\n&quot;,&quot;\n&quot;,$row[&quot;email&quot;]) . &quot;</small>&quot;;
print &quot;<TR><TD>&quot; . $select . &quot; </td><TD>&quot; . $name . &quot; </td><TD>&quot; . $department . &quot; </td><TD>&quot; . $email . &quot; </td>&quot;;

}
 
That's because in a table, if you have any content outside of the proper <tr> <td>, it will just dump it out at the top of the table. Check your outputted html code to make sure it is correct, or post it for me to do so.

Rick

-----------------------------------------------------------
RISTMO is back! Sorry I've been away for so long--it's been a busy year ;-)
RISTMO Designs
Arab Church
 
change this:
$select = &quot;<small>&quot; . str_replace(&quot;\n&quot;,&quot;\n&quot;, print &quot;<form><tr><input type=checkbox></tr></form>&quot;) . &quot;</small>&quot;;


to:
$select = &quot;<small>&quot; . str_replace(&quot;\n&quot;,&quot;\n&quot;, print &quot;<form><input type=checkbox></form>&quot;) . &quot;</small>&quot;;

now does it work?


Known is handfull, Unknown is worldfull
 
or:

$select = &quot;<small>&quot; . str_replace(&quot;\n&quot;,&quot;\n&quot;, print &quot;<form><tr><td><input type=checkbox></td></tr></form>&quot;) . &quot;</small>&quot;;

Rick

-----------------------------------------------------------
RISTMO is back! Sorry I've been away for so long--it's been a busy year ;-)
RISTMO Designs
Arab Church
 
Just a note:

This is an excellent example of a difficulty unrelated to PHP as such. It makes me root for the use of external HTML templates.
An external template with placeholders and repeating blocks can be validated easily and such a problem will not occur. You can maintain the HTML with a WYSIWYG editor, Dreamweaver for example and be 100% sure it will display correct. You can write your code clear from any formatting issues. No more <td> amd <tr> counting.
Imagine you want to amend your script and add another 5 table cells in there. It's more a trial an error, or trial and get stuck ;)

The problem in this post is not a PHP problem but the common fact that PHP is used to create invalid HTML.
 
I like mixing PHP and HTML! I do it all the time ;-). I guess it would be hard for people who did only one or the other, though :p....That's why I'm a one person design team :-D.

Rick

-----------------------------------------------------------
RISTMO is back! Sorry I've been away for so long--it's been a busy year ;-)
RISTMO Designs
Arab Church
 
It's ok for a one-man team, I suppose.
It is also historically true that the mixed PHP/HTML is how it all started.

PHP offers many ways to achieve results and the overall evolution toward extremely complex PHP applications has certainly made the separation of design/functionality more and more popular.

From the point of view of a multi-person programming/design staff templates are the only choice.

As long as you are just writing custom scripts and don't mind rewriting the &quot;Contact&quot; form that sends e-mail everytime when the customer has a slightly different page setup - happy mixing!
 
I tend to make a template and set it aside and then mix the &quot;content&quot; html and php together. That fixes both problems, to a certain extent.

Rick

-----------------------------------------------------------
RISTMO is back! Sorry I've been away for so long--it's been a busy year ;-)
RISTMO Designs
Arab Church
 
Works great now, thanks everybody =)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top