Jump to content

[SOLVED] Data into Table


EagleAmerican

Recommended Posts

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>';
}

Link to comment
Share on other sites

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.

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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...');

Link to comment
Share on other sites

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());

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.