EagleAmerican Posted July 22, 2007 Share Posted July 22, 2007 I'm trying to get a neat and clean readout of all of the parasites that are in the MySQL table. Right now everything works except all of the info is all over the table and I can't seem to get the table to be clean and presentable for when I open my site to the public. Any help is deeply appreciated! echo '<p>Parasite list:</p><TABLE width="100%" height="100%" border="1" cellpadding="2" cellspacing="5"><TR> <TD align="left" valign="top" width="161">Name</TD> <TD align="left" valign="top" width="122">From</TD> <TD align="left" valign="top" width="128">Genre</TD> <TD align="left" valign="top" width="161">Description</TD> <TD align="left" valign="top" width="164">Technical Info</TD> </TR>'; while ($row = mysql_fetch_array($name)) { echo '<tr><td align="left" valign="top" width="161">' . $row['parasitename'] . '</td>'; } while ($row = mysql_fetch_array($from)) { echo '<td align="left" valign="top" width="122">' . $row['parasitefrom'] . '</td>'; } while ($row = mysql_fetch_array($genre)) { echo '<td align="left" valign="top" width="128">' . $row['parasitegenre'] . '</td>'; } while ($row = mysql_fetch_array($description)) { echo '<td align="left" valign="top" width="161">' . $row['parasitedescription'] . '</td>'; } while ($row = mysql_fetch_array($techinfo)) { echo '<td align="left" valign="top" width="164">' . $row['parasitetechinfo'] . '</td></tr>'; } Quote Link to comment Share on other sites More sharing options...
trq Posted July 22, 2007 Share Posted July 22, 2007 Your description is quite vague and by the looks of all those loops you appear to be running multiple queries on the same table. Can we see how you create these resource results? You might also want to post a link so we can see the finished product, allong with a descript of how you want it cleaned up. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 22, 2007 Share Posted July 22, 2007 I think you should probably be doing something like: <?php $sql = mysql_query("SELECT `parasitename`,`parasitefrom,`parasitegenre,`parasitedescription`,`parasitetechinfo` FROM `yourtable`") or die(mysql_error()); echo '<p>Parasite list:</p> <TABLE width="100%" height="100%" border="1" cellpadding="2" cellspacing="5"><TR> <TD align="left" valign="top" width="161">Name</TD> <TD align="left" valign="top" width="122">From</TD> <TD align="left" valign="top" width="128">Genre</TD> <TD align="left" valign="top" width="161">Description</TD> <TD align="left" valign="top" width="164">Technical Info</TD> </TR>'; while ($row = mysql_fetch_array($sql)) { echo '<tr><td align="left" valign="top" width="161">' . $row['parasitename'] . '</td>'; echo '<td align="left" valign="top" width="122">' . $row['parasitefrom'] . '</td>'; echo '<td align="left" valign="top" width="128">' . $row['parasitegenre'] . '</td>'; echo '<td align="left" valign="top" width="161">' . $row['parasitedescription'] . '</td>'; echo '<td align="left" valign="top" width="164">' . $row['parasitetechinfo'] . '</td></tr>'; } ?> But as thorpe says, it would be helpful to have a bit more information. Quote Link to comment Share on other sites More sharing options...
EagleAmerican Posted July 22, 2007 Author Share Posted July 22, 2007 Thanks so far.. but now I get Parse error: parse error, unexpected '<' in /home/www/parasitedb.freehostia.com/add_parasite.php on line 93 Unfortunately the site is currently password protected as only me and my friend who are the founders of the site can get in. We do not wish for public access because right now anyone that gets in can add and view and I cannot have the public adding stuff to the database at this time before I put protections on it. Here is the full code and I hope that someone can help me out here. Thanks sooooooooo much! <HTML> <HEAD> <TITLE>ParasiteDB - Staff Area - New Parasite</TITLE> </HEAD> <BODY bgcolor="#000080" text="#008000"> <IMG src="images/img00002.bmp" width="799" height="77" align="top" style="position:absolute;left:0px;top:0px;width:799px;height:77px;z-index:0"> <DIV style="position:absolute; left:259px; top:76px; width:291px; height:23px; z-index:1" align="center" valign="top"> <FONT style="FONT-SIZE:14pt" color="#FFFF80" face="Tahoma">Staff Area -> Add New Parasite</FONT></DIV> <DIV style="position:absolute; left:14px; top:73px; width:150px; height:31px; z-index:2" align="left" valign="top"> <?php echo 'Hello, <b>Staff</b>.'; ?></DIV> <DIV style="position:absolute; left:278px; top:132px; width:257px; height:91px; z-index:3" align="left" valign="top"> <?php if (isset($_GET['addparasite'])): // User wants to add a joke ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <label>Name:<br /> <textarea name="parasitename" rows="1" cols="50"> </textarea></label><br /> <label>From:<br /> <textarea name="parasitefrom" rows="1" cols="50"> </textarea></label><br /> <label>Genre:<br /> <textarea name="parasitegenre" rows="1" cols="50"> </textarea></label><br / <label>Description:<br /> <textarea name="parasitedescription" rows="5" cols="50"> </textarea></label><br /> <label>Technical Info:<br /> <textarea name="parasitetechinfo" rows="5" cols="50"> </textarea></label><br /> <input type="submit" value="Add" /> </form> <?php else: // Default page display $dbcnx = @mysql_connect('mysql3.freehostia.com', 'adaarm_db', 'ppk6g4fdsghd34468n'); if (!$dbcnx) { exit('<p>Unable to connect to the ' . 'database server at this time.</p>'); } // Select the jokes database if (!@mysql_select_db('adaarm_db')) { exit('<p>Unable to locate the ' . 'database at this time.</p>'); } if (isset($_POST['parasitename'])) { $parasitename = $_POST['parasitename']; $parasitefrom = $_POST['parasitefrom']; $parasitegenre = $_POST['parasitegenre']; $parasitedescription = $_POST['parasitedescription']; $parasitetechinfo = $_POST['parasitetechinfo']; $sql = "INSERT INTO parasite SET parasitename='$parasitename', parasitefrom='$parasitefrom', parasitegenre='$parasitegenre', parasitedescription='$parasitedescription', parasitetechinfo='$parasitetechinfo'"; if (@mysql_query($sql)) { echo "<p>The parasite '$parasitename' has been added.</p>"; } else { echo '<p>Error adding submitted parasite: ' . mysql_error() . '</p>'; } } $name = @mysql_query('SELECT parasitename FROM parasite'); if (!$name) { exit('<p>Error performing query1: ' . mysql_error() . '</p>'); } $from = @mysql_query('SELECT parasitefrom FROM parasite'); if (!$from) { exit('<p>Error performing query2: ' . mysql_error() . '</p>'); } $genre = @mysql_query('SELECT parasitegenre FROM parasite'); if (!$genre) { exit('<p>Error performing query3: ' . mysql_error() . '</p>'); } $description = @mysql_query('SELECT parasitedescription FROM parasite'); if (!$description) { exit('<p>Error performing query4: ' . mysql_error() . '</p>'); } $techinfo = @mysql_query('SELECT parasitetechinfo FROM parasite'); if (!$techinfo) { exit('<p>Error performing query5: ' . mysql_error() . '</p>'); } <?php $sql = mysql_query("SELECT `parasitename`,`parasitefrom,`parasitegenre,`parasitedescription`,`parasitetechinfo` FROM `yourtable`") or die(mysql_error()); echo '<p>Parasite list:</p> <TABLE width="100%" height="100%" border="1" cellpadding="2" cellspacing="5"><TR> <TD align="left" valign="top" width="161">Name</TD> <TD align="left" valign="top" width="122">From</TD> <TD align="left" valign="top" width="128">Genre</TD> <TD align="left" valign="top" width="161">Description</TD> <TD align="left" valign="top" width="164">Technical Info</TD> </TR>'; while ($row = mysql_fetch_array($sql)) { echo '<tr><td align="left" valign="top" width="161">' . $row['parasitename'] . '</td>'; echo '<td align="left" valign="top" width="122">' . $row['parasitefrom'] . '</td>'; echo '<td align="left" valign="top" width="128">' . $row['parasitegenre'] . '</td>'; echo '<td align="left" valign="top" width="161">' . $row['parasitedescription'] . '</td>'; echo '<td align="left" valign="top" width="164">' . $row['parasitetechinfo'] . '</td></tr>'; } ?> echo '<p><a href="' . $_SERVER['PHP_SELF'] . '?addparasite=1">Add a Parasite</a></p>'; endif; ?> </table></DIV> </BODY> </HTML> Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 22, 2007 Share Posted July 22, 2007 You need to remove the opening and closing php tags in the code i posted. The reason why i post them is to show syntax highlighting. Also, in the future, try and identify the line that the error is on - it'll help others help you. Quote Link to comment Share on other sites More sharing options...
EagleAmerican Posted July 22, 2007 Author Share Posted July 22, 2007 How do I do that? Right now I have to press how many times I press my down arrow key. Is there an easier way? Thanks, Adam Quote Link to comment Share on other sites More sharing options...
EagleAmerican Posted July 22, 2007 Author Share Posted July 22, 2007 I changed yourtable into parasite (the name of my table) and because of the error I got. Now I get this error message where the table should be: Unknown column 'parasitefrom,' in 'field list' I don't know how to fix that. Help please? Thanks, Adam Quote Link to comment Share on other sites More sharing options...
trq Posted July 22, 2007 Share Posted July 22, 2007 I don't know how to fix that. Help please? Does the field parasitefrom exist in your table? Quote Link to comment Share on other sites More sharing options...
EagleAmerican Posted July 22, 2007 Author Share Posted July 22, 2007 I think so. This is my first PHP site that I am writing myself. Here is the export from PhpMyAdmin: -- phpMyAdmin SQL Dump -- version 2.6.4-pl2 -- http://www.phpmyadmin.net -- -- Host: mysql3.freehostia.com -- Generation Time: Jul 22, 2007 at 05:48 PM -- Server version: 4.1.11 -- PHP Version: 4.4.4-8+etch1 -- -- Database: `adaarm_db` -- CREATE DATABASE `adaarm_db` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci; USE adaarm_db; -- -------------------------------------------------------- -- -- Table structure for table `parasite` -- CREATE TABLE `parasite` ( `id` int(11) NOT NULL auto_increment, `parasitename` text, `parasitefrom` text, `parasitegenre` text, `parasitedescription` text, `parasitetechinfo` text, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; -- -- Dumping data for table `parasite` -- INSERT INTO `parasite` VALUES (1, 'Test.Blah', 'Unknown', 'Unknown', 'This is a Test Parasite.', 'Test Parasite.'); INSERT INTO `parasite` VALUES (3, 'Test.Blah2', 'Blah2', 'Blah.*', 'Test', 'Test Info...'); Quote Link to comment Share on other sites More sharing options...
trq Posted July 22, 2007 Share Posted July 22, 2007 Sorry, I didn't even look. There is errors in the query. Should be... $sql = mysql_query("SELECT parasitename,parasitefrom,parasitegenre,parasitedescription,parasitetechinfo FROM parasite") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 22, 2007 Share Posted July 22, 2007 How do I do that? Right now I have to press how many times I press my down arrow key. Is there an easier way? Thanks, Adam You want to get yourself something better to develop your php scripts in. There's a topic here: http://www.phpfreaks.com/forums/index.php/topic,54859.0.html About the editors there are. There are plenty of free ones. Personally, i use php designer 2007. Edit: Beaten to it by thorpe. Sorry - i made a typo in the original query i posted. Quote Link to comment Share on other sites More sharing options...
EagleAmerican Posted July 22, 2007 Author Share Posted July 22, 2007 Thanks so much for your help, both of you! But the width on the table just isn't working. I know HTML and I don't know why it isn't. All of the table boxes are the same width and hight and because of the description and tech info being longer makes the table look weird... any way to fix that? Thanks, Adam Quote Link to comment Share on other sites More sharing options...
trq Posted July 22, 2007 Share Posted July 22, 2007 any way to fix that? That would be a html issue. We have a html forum especially for such questions. Quote Link to comment Share on other sites More sharing options...
EagleAmerican Posted July 22, 2007 Author Share Posted July 22, 2007 Ok, thanks for all of your help. I'm off to the HTML help forum. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.