Page 1 of 1
Help .. Making table tab down until there are no more mysql
Posted: Wed Apr 14, 2004 10:56 pm
by ]{ronic
Hey Guys,
I need help geting a tabing system working from mysql data.
Here is the table layout I want to call the data into ..
Code: Select all
<table width="59%" border="1" cellspacing="0" cellpadding="3">
<tr>
<td height="20" colspan="2"><font color="#000000"><b><font face="Arial" size="2">Forces Member</font></b></font></td>
<td width="45%" height="20"><font color="#000000" face="Arial" style="font-size: 9pt; font-weight: 700">Date Joined:</font></td>
</tr>
<tr>
<td width="14%" rowspan="4"> </td>
<td width="41%" height="20"><font color="#000000"><b><font face="Arial" style="font-size: 9pt">Alias:</font></b></font></td>
<td height="20"><font color="#000000" face="Arial" style="font-size: 9pt"><b>Rank: </b></font></td>
</tr>
<tr>
<td height="20" colspan="2"><font color="#000000"><span style="font weight: 700"><font color="#000000" face="Arial" style="font-size: 9pt"><b>Division:</b></font></span></font></td>
</tr>
<tr>
<td height="20"><font color="#000000" face="Arial" style="font-size: 9pt; font-weight: 700">Pref. Class:</font><font color="#000000" face="Arial" style="font-size: 8pt; font-weight: 700">
</font></td>
<td height="20"><font color="#000000" face="Arial" style="font-weight: 700; font-size: 9pt">Preferred Vehicle: </font></td>
</tr>
<tr>
<td height="20" colspan="2"><font color="#000000"><b><font face="Arial" style="font-size: 9pt">Specialty:
</font></b></font></td>
</tr>
</table>
Each heading is the cell name in which the data needs to be called in from.
I have a basic tab system working now .. but it is just line by line .. no style to the table.
here is an example of that:
Code: Select all
$db = @mysql_connect("$hostserver","$username","$password")
or die ("Problems connecting to database server");
@mysql_select_db ("$dbname") or die ("Problem selecting database");
$query = "SELECT * FROM $dbtable";
$result = @mysql_query($query) or die ("Query failed");
$numofrows =@mysql_num_rows($result);
?>
<table width="666" border="0" align="center" cellpadding="5" cellspacing="1">
<tr bgcolor="#0066CC">
<td width="100" nowrap bgcolor="#0066CC"> <div align="center"><font size="2"><strong><font color="#FFFFFF">Part</font></strong></font></div></td>
<td width="538" nowrap bgcolor="#0066CC"> <div align="center"><font size="2"><strong><font color="#FFFFFF">Description</font></strong></font></div></td>
<td width="58" nowrap> <div align="center"><font size="2"><strong><font color="#FFFFFF">Price</font></strong></font></div></td>
<td width="36" nowrap> <div align="center"><font size="2"><strong><font color="#FFFFFF">Link</font></strong></font></div></td>
</tr>
<?php
for ($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_assoc($result);
if ($i % 2) {
echo "<TR bgcolor="#CCCCCC">\n";
} else {
echo "<TR bgcolor="#0099CC">\n";
}
if(round($rowї'price']))
$price_field="\$".round($rowї'price']);
else $price_field="";
echo "<TD><strong>".$rowї'part']."</strong><TD>".$rowї'description']."</TD><TD align="right">".$price_field."</TD><TD>";
$image = $rowї'link'];
if ($image)
echo "<a href="$image" target="new"><strong><center>Link</center></strong></a>";
else
echo "<center></center>";
echo "</TD></TR>\n";
}
?>
Can any one please help with with the same style but using a table layout as in the first code, to tab down untill there are no more records in the database
If that makes sence?
Thanks heaps
]{ronic
Posted: Thu Apr 15, 2004 8:34 pm
by ]{ronic
Hmmz I will try to say it better .. Dont think the above makes to much sence ..
I need help geting a table to reprduce itself down the page untill there are no more mysql records to display.
Here is the table layout I want to call the data into ..
Code: Select all
<table width="59%" border="1" cellspacing="0" cellpadding="3">
<tr>
<td height="20" colspan="2"><font color="#000000"><b><font face="Arial" size="2">Forces Member</font></b></font></td>
<td width="45%" height="20"><font color="#000000" face="Arial" style="font-size: 9pt; font-weight: 700">Date Joined:</font></td>
</tr>
<tr>
<td width="14%" rowspan="4"> </td>
<td width="41%" height="20"><font color="#000000"><b><font face="Arial" style="font-size: 9pt">Alias:</font></b></font></td>
<td height="20"><font color="#000000" face="Arial" style="font-size: 9pt"><b>Rank: </b></font></td>
</tr>
<tr>
<td height="20" colspan="2"><font color="#000000"><span style="font weight: 700"><font color="#000000" face="Arial" style="font-size: 9pt"><b>Division:</b></font></span></font></td>
</tr>
<tr>
<td height="20"><font color="#000000" face="Arial" style="font-size: 9pt; font-weight: 700">Pref. Class:</font><font color="#000000" face="Arial" style="font-size: 8pt; font-weight: 700">
</font></td>
<td height="20"><font color="#000000" face="Arial" style="font-weight: 700; font-size: 9pt">Preferred Vehicle: </font></td>
</tr>
<tr>
<td height="20" colspan="2"><font color="#000000"><b><font face="Arial" style="font-size: 9pt">Specialty:
</font></b></font></td>
</tr>
</table>
Each heading in the table above is the feild name in mysql with the data needed to be called within those headings.
Can any one please help with this .. Even if someone knows where there is a tutorial to achieve this ...
If it makes sence?
Thanks heaps
]{ronic
Posted: Thu Apr 15, 2004 8:46 pm
by tim
hmm, just by a glance are u wanting something like:
Code: Select all
<?php
$sql = "SELECT * FROM table_name";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
$alias = $row["alias"];
$date = $row["date"];
// etc
echo "<table border=0><tr><td>";
echo "Date joined for $alias was $date</tr></td></table";
}
?>
the while command will generate a loop to display all the rows in the table, all u need to do is define the rest of the varbales according to the info u have stored in your table and modify the table to what you want
if this isnt what your asking for, i'm sorry.
Posted: Thu Apr 15, 2004 9:17 pm
by ]{ronic
Thanks Tim
Yea thats pretty much what I want to acheive .. Could you help me create the table layout as below .. also creating a enter between each table?
So it loops the data into this style of table:
Code: Select all
<table width="59%" border="1" cellspacing="0" cellpadding="3">
<tr>
<td height="20" colspan="2"><font color="#000000"><b><font face="Arial" size="2">Forces Member</font></b></font></td>
<td width="45%" height="20"><font color="#000000" face="Arial" style="font-size: 9pt; font-weight: 700">Date Joined:</font></td>
</tr>
<tr>
<td width="14%" rowspan="4"> </td>
<td width="41%" height="20"><font color="#000000"><b><font face="Arial" style="font-size: 9pt">Alias:</font></b></font></td>
<td height="20"><font color="#000000" face="Arial" style="font-size: 9pt"><b>Rank: </b></font></td>
</tr>
<tr>
<td height="20" colspan="2"><font color="#000000"><span style="font weight: 700"><font color="#000000" face="Arial" style="font-size: 9pt"><b>Division:</b></font></span></font></td>
</tr>
<tr>
<td height="20"><font color="#000000" face="Arial" style="font-size: 9pt; font-weight: 700">Pref. Class:</font><font color="#000000" face="Arial" style="font-size: 8pt; font-weight: 700">
</font></td>
<td height="20"><font color="#000000" face="Arial" style="font-weight: 700; font-size: 9pt">Preferred Vehicle: </font></td>
</tr>
<tr>
<td height="20" colspan="2"><font color="#000000"><b><font face="Arial" style="font-size: 9pt">Specialty:
</font></b></font></td>
</tr>
</table>
Thanks
]{ronic
Posted: Thu Apr 15, 2004 9:24 pm
by tim
just apply my code to yours, I dont know what your SQl table looks like, but define all the variables as u have column names that u wih to display inside your table.
like lets say u have a table with a id, username, date, and password
$row= mysql_fetch_array($sql);
$id = $row["id"]; // the id coulmn
$username = $row["username"]; // the username column
and so-on.
Then add the variables wherever you want in your table
its easy, and then by your </table> add a <BR> (thats your line break, or "enter")
your done, all the date inside the table will be put in that format. howver i'm not going to look at your long table n set the vars n stuff for you. that is your job =] unless u wish to pay? lol

Posted: Thu Apr 15, 2004 9:40 pm
by ]{ronic
Yer .. I got that sussed .. But I keep getting errors trying to make the table look the the html table above .. I kno how to display the variables etc .. just having problems building the table in php ...
Thanks heaps for your help tho .. Very much appreciated
]{ronic
Posted: Thu Apr 15, 2004 10:03 pm
by John Cartwright
Code: Select all
<?php
<?php
$sql = "SELECT * FROM table_name";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
$alias = $row["alias"];
$datejoined = $row["datejoined"];
$rank = $row["rank"];
$division = $row["division"];
$prefclass = $row["prefclass"];
$prefvehicle = $row["prefvehicle"];
$speciality = $row["speciality"];
echo '<table width="59%" border="1" cellspacing="0" cellpadding="3">
<tr>
<td height="20" colspan="2"><font color="#000000"><b><font face="Arial" size="2">Forces Member</font></b></font></td>
<td width="45%" height="20"><font color="#000000" face="Arial" style="font-size: 9pt; font-weight: 700">Date Joined: $datejoined</font></td>
</tr>
<tr>
<td width="14%" rowspan="4"> </td>
<td width="41%" height="20"><font color="#000000"><b><font face="Arial" style="font-size: 9pt">Alias: $alias</font></b></font></td>
<td height="20"><font color="#000000" face="Arial" style="font-size: 9pt"><b>Rank: $rank</b></font></td>
</tr>
<tr>
<td height="20" colspan="2"><font color="#000000"><span style="font weight: 700"><font color="#000000" face="Arial" style="font-size: 9pt"><b>Division: $division</b></font></span></font></td>
</tr>
<tr>
<td height="20"><font color="#000000" face="Arial" style="font-size: 9pt; font-weight: 700">Pref. Class: $prefclass</font><font color="#000000" face="Arial" style="font-size: 8pt; font-weight: 700"> </font></td>
<td height="20"><font color="#000000" face="Arial" style="font-weight: 700; font-size: 9pt">Preferred Vehicle: $prefvehicle</font></td>
</tr>
<tr>
<td height="20" colspan="2"><font color="#000000"><b><font face="Arial" style="font-size: 9pt">Specialty: $speciality</font></b></font></td>
</tr>
</table>';
}
?>
?>
As you can see all you had to do is plug in the variables.
btw you should look into css styles to reduce the amount of code... that is the sloppiest table I have EVER seen.... you know you are terrible if you see font tags

Posted: Fri Apr 16, 2004 4:53 pm
by tim
did the above work? if not, letss ee the updated code with the errors.
Phenom, actually I like CSS, but I like to leae the font color into the body.
<p class=text><font color=green>
Nice to assign one CSS text n go with color. lol but yeah, that table is nasty

Posted: Sat Apr 17, 2004 9:08 pm
by ]{ronic
Hey Tim,
Na that code didnt work .. I asume thats not how tables are created in php .. I have worked my way thru it and achieved what I wanted to do ..
Below is a rough copy of the code:
Code: Select all
<?php
$dbname="#####";
$dbtable="#####";
$hostserver="#####";
$username="#####";
$password="#####";
$db = @mysql_connect("$hostserver","$username","$password")
or die ("Problems connecting to database server");
@mysql_select_db ("$dbname") or die ("Problem selecting database");
$sql = "SELECT * FROM $dbtable";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
$alias = $rowї"alias"];
$datejoined = $rowї"datejoined"];
$rank = $rowї"rank"];
$division = $rowї"division"];
$prefclass = $rowї"prefclass"];
$prefvehicle = $rowї"prefvehicle"];
$speciality = $rowї"specialty"];
?>
<div align="center"></div>
<div align="center"></div>
<div align="center"></div>
<table width="92%" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#413723">
<tr>
<td height="20" colspan="2">
<div align="center"><font color="#000000"><b><font color="#F9D28F" size="2" face="tahoma">Urban
Legends Forces Member</font></b></font> </div></td>
<td width="45%" height="20"> <font color="#000000" face="tahoma" style="font-size: 8pt; font-weight: 600">Date
Joined:</font> <font color="#000000" face="tahoma" style="font-size: 8pt; font-weight: 500">
<?php echo $rowї'datejoined']; ?> </font></td>
</tr>
<tr>
<td width="14%" rowspan="4"><img src="profileshot24.jpg" width="68" height="83"></td>
<td width="41%" height="20"> <font color="#000000" face="tahoma" style="font-size: 8pt; font-weight: 600">Alias:</font>
<font color="#000000" face="tahoma" style="font-size: 8pt; font-weight: 500">
<?php echo $rowї'alias']; ?> </font></td>
<td height="20"> <font color="#000000" face="tahoma" style="font-size: 8pt; font-weight: 600">Rank:</font>
<font color="#000000" face="tahoma" style="font-size: 8pt; font-weight: 500">
<?php echo $rowї'rank']; ?> </font></td>
</tr>
<tr>
<td height="20"> <font color="#000000" face="tahoma" style="font-size: 8pt; font-weight: 600">Wolf
Pack</font> <font color="#000000 face="tahoma" style="font-size: 8pt; font-weight: 500">
</font> </td>
<td height="20"> <font color="#000000" face="tahoma" style="font-size: 8pt; font-weight: 600">Division:</font>
<font color="#000000" face="tahoma" style="font-size: 8pt; font-weight: 500">
<?php echo $rowї'division']; ?> </font> </td>
</tr>
<tr>
<td height="20"> <font color="#000000" face="tahoma" style="font-size: 8pt; font-weight: 600">Pref
Class:</font> <font color="#000000" face="tahoma" style="font-size: 8pt; font-weight: 500">
<?php echo $rowї'prefclass']; ?> </font> </td>
<td height="20"> <font color="#000000" face="tahoma" style="font-size: 8pt; font-weight: 600">Pref
Vehicle:</font> <font color="#000000" face="tahoma" style="font-size: 8pt; font-weight: 500">
<?php echo $rowї'prefvehicle']; ?> </font></td>
</tr>
<tr>
<td height="20" colspan="2"> <font color="#000000" face="tahoma" style="font-size: 8pt; font-weight: 600">Specialty:</font>
<font color="#000000" face="tahoma" style="font-size: 8pt; font-weight: 500">
<?php echo $rowї'specialty']; ?> </font></td>
</tr>
</table>
<div align="left"><br>
<?php
}
?>
Thanks for your help anyway
Regards
]{ronic
Posted: Sun Apr 18, 2004 3:56 am
by malcolmboston
Phenom wrote:
btw you should look into css styles to reduce the amount of code... that is the sloppiest table I have EVER seen.... you know you are terrible if you see font tags

lol, too true, even dreamweaver tells you that font tag is becoming defunct and to use CSS, i always aim to have absolutely no "presentational" mark-up anywhere in my page, its all defined in CSS files
Posted: Sun Apr 18, 2004 8:02 pm
by ]{ronic
Thanks Guys ..
I have been playing around tidying up the code and using css .. I cant get it to display the records on the same line as .. alias: .. It displays it on the next line with a douple line enter ..
Here is the code:
Code: Select all
<TITLE>Members</TITLE>
<STYLE TYPE="text/css">
<!--
H1 { color: #F9D28F; font-size: 20px; font-family: tahoma }
P { color: #000000; font-size: 11px; font-weight: 600; font-family: tahoma }
Table { color: #000000; font-size: 11px; font-weight: 500; font-family: tahoma }
-->
</STYLE>
</HEAD>
<BODY>
<?php
$dbname="#####";
$dbtable="#####";
$hostserver="#####";
$username="#####";
$password="#####";
$db = @mysql_connect("$hostserver","$username","$password")
or die ("Problems connecting to database server");
@mysql_select_db ("$dbname") or die ("Problem selecting database");
$sql = "SELECT * FROM $dbtable";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
$alias = $rowї"alias"];
$datejoined = $rowї"datejoined"];
$rank = $rowї"rank"];
$division = $rowї"division"];
$prefclass = $rowї"prefclass"];
$prefvehicle = $rowї"prefvehicle"];
$speciality = $rowї"specialty"];
$avatar = $rowї"avatar"];
?>
<table width="92%" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#413723">
<tr>
<td height="20" colspan="2" valign="middle"><div align="center"><H1>Urban Legends Forces Member</H1></div></td>
<td width="45%" height="20"><P>Date Joined:</P> <?php echo $rowї'datejoined']; ?></td>
</tr>
<tr>
<td width="14%" rowspan="4"><div align="center"><img src="<?php echo $rowї'avatar']; ?>"></div></td>
<td width="41%" height="20"><P>Alias:</P> <?php echo $rowї'alias']; ?></td>
<td height="20"><P>Rank:</P> <?php echo $rowї'rank']; ?></td>
</tr>
<tr>
<td height="20"><P>Wolf Pack</P></td>
<td height="20"><P>Division:</P> <?php echo $rowї'division']; ?></td>
</tr>
<tr>
<td height="20"><P>Pref Class:</P> <?php echo $rowї'prefclass']; ?></td>
<td height="20"><P>Pref Vehicle:</P> <?php echo $rowї'prefvehicle']; ?></td>
</tr>
<tr>
<td height="20" colspan="2"><P>Specialty:</P> <?php echo $rowї'specialty']; ?></td>
</tr>
</table>
<div align="left"><br>
<?php
}
?>
Im trying to get it to display in the same format as the messy code I submited in the earlyer post. Any ideas on what I am doing wrong?
sorry for the lame noobie questions
Thanks
]{ronic
Posted: Sun Apr 18, 2004 10:00 pm
by ]{ronic
Hey guys..
Is the way I have set css etc out correct .. or are there better ways for faster loading etc etc ..
Code: Select all
<STYLE TYPE="text/css">
<!--
body { background-color: #766240; }
font { font-family: Tahoma; font-size: 10px; font-weight: bold; color: #000000; }
font.two { font-family: Tahoma; font-size: 14px; font-weight: bold; color: #F9D28F; }
table { font-family: tahoma; font-size: 11px; font-weight: 500; color: #000000; }
-->
</STYLE>
</HEAD>
<BODY>
<?php
$dbname="#####";
$dbtable="#####";
$hostserver="#####";
$username="#####";
$password="#####";
$db = @mysql_connect("$hostserver","$username","$password")
or die ("Problems connecting to database server");
@mysql_select_db ("$dbname") or die ("Problem selecting database");
$sql = "SELECT * FROM $dbtable";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
$alias = $rowї"alias"];
$datejoined = $rowї"datejoined"];
$rank = $rowї"rank"];
$division = $rowї"division"];
$prefclass = $rowї"prefclass"];
$prefvehicle = $rowї"prefvehicle"];
$speciality = $rowї"specialty"];
$avatar = $rowї"avatar"];
?>
<table width="55%" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#413723">
<tr>
<td height="20" colspan="2" valign="middle"><div align="center"><font class=two>Urban Legends Forces Member</font></div></td>
<td width="45%" height="20"><font>Date Joined:</font> <?php echo $rowї'datejoined']; ?></td>
</tr>
<tr>
<td width="14%" rowspan="4"><div align="center"><img src="<?php echo $rowї'avatar']; ?>"></div></td>
<td width="41%" height="20"><font>Alias:</font> <?php echo $rowї'alias']; ?></td>
<td height="20"><font>Rank:</font> <?php echo $rowї'rank']; ?></td>
</tr>
<tr>
<td height="20"><font>Wolf Pack</font></td>
<td height="20"><font>Division:</font> <?php echo $rowї'division']; ?></td>
</tr>
<tr>
<td height="20"><font>Pref Class:</font> <?php echo $rowї'prefclass']; ?></td>
<td height="20"><font>Pref Vehicle:</font> <?php echo $rowї'prefvehicle']; ?></td>
</tr>
<tr>
<td height="20" colspan="2"><font>Specialty:</font> <?php echo $rowї'specialty']; ?></td>
</tr>
</table>
<div align="left"><br>
<?php
}
?>
]{ronic
Posted: Sun Apr 18, 2004 10:01 pm
by John Cartwright
Looks good.