Page 1 of 2
Help placing mysql results in html table.
Posted: Tue Jan 20, 2009 9:30 am
by Skunk1311
Hey all, sorry about my first post asking for help!
Well i need help displaying mysql results in a html table.
The table consits of 6 columns and 20 rows.
I have a html form that has 6 input boxes. Each box inputs that info to a different database in a mysql database. I have 6 tables in my mysql database.
My form works and inputs the data into each table in my mysql database just fine.
So say i input the textboxes on my form where i submit to my database with a word in each. Thats 6 different words. I want word 1 in the first column of the first row word 2 in second column of first row and so on till it has done 6 columns on the first row.
Then say i go back to my form and input 6 more different words. I want to do the same as the first but on a new row. And so on..
Here is what i have atm. Unfortunately it keeps displaying the next submitted results in the next column instead of starting a new row.
Code: Select all
<?PHP
include 'mysql_connect.php';
echo "<table border='1' width='100%' cellspacing='0' cellpadding='0'>";
$query=mysql_query("select * from news_posts, realname, skill, favmap,
ctwep, twep") or die("Error Occured,plz try again");
$left = true;
while($row=mysql_fetch_array($query))
{
if ($left)
{
echo "<tr>";
}
echo "<td>";
echo $row['title'];
echo"</td>";
echo "<td>";
echo $row['realname'];
echo"</td>";
echo "<td>";
echo $row['skill'];
echo"</td>";
echo "<td>";
echo $row['favmap'];
echo"</td>";
echo "<td>";
echo $row['ctwep'];
echo"</td>";
echo "<td>";
echo $row['twep'];
echo"</td>";
if (!$left)
{
echo"</tr>";
}
$left = !$left;
}
echo"</table>";
?>
Re: Help placing mysql results in html table.
Posted: Tue Jan 20, 2009 9:44 am
by Burrito
get rid of your $left boolean.
Re: Help placing mysql results in html table.
Posted: Tue Jan 20, 2009 12:07 pm
by Skunk1311
Ok, not it is showing a row with 6 colums but the row is like squished to like 1 pixel or something. Cant see any entrys in it. Although there is 18 entries all together in all my database tables. So there should be 3 rows, 18 cells altogether =/
Here is my code :
Code: Select all
<?PHP
include 'mysql_connect.php';
echo "<table border='1' width='100%' cellspacing='0' cellpadding='0'>";
$query=mysql_query("select * from news_posts, realname, skill, favmap, ctwep, twep") or die("Error Occured,plz try again");
while($row=mysql_fetch_array($query))
echo "<tr>";
echo "<td>";
echo $row['title'];
echo"</td>";
echo "<td>";
echo $row['realname'];
echo"</td>";
echo "<td>";
echo $row['skill'];
echo"</td>";
echo "<td>";
echo $row['favmap'];
echo"</td>";
echo "<td>";
echo $row['ctwep'];
echo"</td>";
echo "<td>";
echo $row['twep'];
echo"</td>";
echo"</tr>";
echo"</table>";
?>
Re: Help placing mysql results in html table.
Posted: Tue Jan 20, 2009 12:13 pm
by Burrito
look at the source to find out why it's 'shrinking' the cell widths.
you have 18 entries...does that mean 3 rows with 6 entries each? That's how I interepreted your original post.
if you're trying to create new rows based on a count of your loop, look at using a modulous operator.
Re: Help placing mysql results in html table.
Posted: Tue Jan 20, 2009 12:21 pm
by Skunk1311
Hi, i will have a look shortly.
And yes your right 3 rows 6 entries each.
But i want it to create a new row for every 6 more entries.
Thanks for help so far man.
edit: I dont think its the source i think its just not displaying the entries or something?
I cant find anything related.
Re: Help placing mysql results in html table.
Posted: Tue Jan 20, 2009 12:27 pm
by Burrito
when you view the source do you see the values from your table being output?
Re: Help placing mysql results in html table.
Posted: Tue Jan 20, 2009 12:37 pm
by Skunk1311
Sorry mate i think you are on a different track than me.
Im very new to mysql/php so please bear with me.
Ok so i have a blank php page.
I have a mysql database. In my mysql database i have 6 tables.
I have a form where i input data to my mysql tables. 6 Textboxes, each one submits to a different table for example:
Now I have them in my mysql database. I want like the first textbox input to the first cell, second textbox to second cell and so on for six cells because there is six inputs. My script so far does that fine
But when i go back to the form where i input data to the mysql tables. I input another 6 inputs. And i want it to start a new row and do the same as last time but on a new row with the new inputs. The last row stays there aswell this one will go underneath. And so on.
Sorry i have tried to make it more clear. And sorry if your last post was on track. I just didn't understand.
Peace.
Re: Help placing mysql results in html table.
Posted: Tue Jan 20, 2009 12:43 pm
by Burrito
fyi, that's really not a good way to structure your tables.
what I"m trying to determine is if your while() loop is actually outputting any data.
try just echoing from your $row[] array w/o putting anything inside html tables to make sure you are indeed retrieving information from your database.
Re: Help placing mysql results in html table.
Posted: Tue Jan 20, 2009 1:09 pm
by Skunk1311
Yes i can display information from my database as stated earlier i can also get them in the first six cells like a want all i need it to do is start a new row after and insert the next set of results from the tables.
Re: Help placing mysql results in html table.
Posted: Tue Jan 20, 2009 1:15 pm
by Burrito
Code: Select all
$query=mysql_query("select * from news_posts, realname, skill, favmap, ctwep, twep") or die("Error Occured,plz try again");
while($row=mysql_fetch_array($query))
{
echo "<tr>";
echo "<td>";
echo $row['title'];
echo"</td>";
echo "<td>";
echo $row['realname'];
echo"</td>";
echo "<td>";
echo $row['skill'];
echo"</td>";
echo "<td>";
echo $row['favmap'];
echo"</td>";
echo "<td>";
echo $row['ctwep'];
echo"</td>";
echo "<td>";
echo $row['twep'];
echo"</td>";
echo"</tr>";
}
Re: Help placing mysql results in html table.
Posted: Tue Jan 20, 2009 2:09 pm
by Skunk1311
Wow strange result :S
If you scroll down to the table on
http://spectrumclan.co.uk/members.php
You will see what i mean.
The first row should be as follows :
paul jessica high de_dust2 m4 ak
The second row should be :
sdgdsfds dsfdsfdsf dsfdsfsdf dsfdsfds fsdfsdfd sfdsfsdf
But it has mangled them all up and added like 500 rows which has really messed up the template.
Please take a look. Thanks.
Re: Help placing mysql results in html table.
Posted: Tue Jan 20, 2009 2:12 pm
by Burrito
that's because of your mysql table structure. It's selecting one row for each table's value against every other table. That's why I said it's not a good table layout.
Re: Help placing mysql results in html table.
Posted: Tue Jan 20, 2009 2:21 pm
by Skunk1311
How do you suggest i lay it out? its my first time actually using mysql btw
Re: Help placing mysql results in html table.
Posted: Tue Jan 20, 2009 2:25 pm
by Burrito
just create different fields for each of your values on one table.
then change your insert statement to:
Code: Select all
INSERT INTO `myTable` (`field1`,`field2`,`field3`,`field4`,`field5`,`field6`) VALUES ('value1','value2','value3','value4','value5','value6')
then select them by:
Re: Help placing mysql results in html table.
Posted: Tue Jan 20, 2009 2:27 pm
by Burrito
the only time you want to use multiple tables is for database normalization (google it).
if you have a one to many relationship.
ex:
one user has multiple guns in CSS. You would create a user table and a guns table and tie them together using a 'key'.
in that case, you'd have multiple rows on your guns table that are tied to one user by the id from the user table.