Help - Search - Members - Calendar
Full Version: Tables with PHP
Weborum Webmaster Forum > Web Page Design > PHP
Just Another Artist
Hi,

I am starting a new thread for this topic as now it's about displaying retrieved DB data as opposed to the other thread just finished on how to successfully retriev DB data.

As you look at the code below, you will notice that I have two TD's being echoed, but since there are more entries in the DB table than two values, the code simply keeps creating data cells to hold the information. I don't want it to do that; I want the TH cell only to be there once and the AudioTitles to appear in the same column listed below.

Does that make any sense? How do I do that? Got a link?

CODE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Query test page</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="content-language" content="en-us" />
<meta http-equiv="Imagetoolbar" content="no" />
<link rel="stylesheet" href="sah-css.css" type="text/css" />

</head>
<body>


<table cellpadding="5" cellspacing="0" border="1">
<?php include_once ("config.php");

$sql = "SELECT AudioID, AudioTitle, AudioDate FROM sermonaudio";
$result = mysql_query($sql, $db);
$count = mysql_num_rows($result);
if($count == 0)
{
echo '<p>No records available.</p>';
}
while($row = mysql_fetch_assoc($result))
{
$AudioID = $row['AudioID'];
$AudioTitle = stripslashes($row['AudioTitle']);
$AudioDate = date("d.m.y",$row['AudioDate']);

echo '<tr>';
echo '<th>Title</th>';
echo '</tr>';
echo '<tr>';
echo '<td>'.$AudioTitle.'</td>';
echo '</tr>';
}
?>
</table>
</body>
</html>


Thanks,
Shad
Joe
Post what you want to achieve in plain HTML Shad.
Just Another Artist
I guess I should have posted this with the first message...heh.

Here is a quick example table and then from your code I will add more fields/cols later as needed.

<table>
<tr>
<th>AudioTitle</th>
<th>AudioSpeaker</th>
</tr>
<tr>
<td>track one</td>
<td>michael</td>
</tr>
<tr>
<td>track two</td>
<td>tom</td>
</tr>
</table>

Thanks,
Shad
Joe
So where does the track data come from?
Just Another Artist
QUOTE(joe2kiss @ May 20 2006, 01:22 PM) [snapback]34119[/snapback]

So where does the track data come from?

So where does the track data come from?

I think you're asking for the audio path, which is audio/.

I'm on yahoo messenger if you prefer that method.
sjthomas
Hey Shad, If I understand you correctly, this code should do the trick: -

CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Query test page</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="content-language" content="en-us" />
<meta http-equiv="Imagetoolbar" content="no" />
<link rel="stylesheet" href="sah-css.css" type="text/css" />

</head>
<body>


<table cellpadding="5" cellspacing="0" border="1">
<tr><th>Title</th><th>Audio Speaker</th></tr>
<?php include_once ("config.php");

$sql = "SELECT AudioID, AudioTitle, AudioDate FROM sermonaudio";
$result = mysql_query($sql, $db);
$count = mysql_num_rows($result);
if($count == 0)
{
echo '<p>No records available.</p>';
}
$i ='1';
while($row = mysql_fetch_assoc($result))
{
$AudioID = $row['AudioID'];
$AudioTitle = stripslashes($row['AudioTitle']);
$AudioDate = date("d.m.y",$row['AudioDate']);

echo '<tr>';
echo '<td>Track '.$i.'</td>';
echo '<td>'.$AudioTitle.'</td>';
echo '</tr>';
}
?>
</table>
</body>
</html>


That will output as per your example but with the number instead of word for the track number (so track 1 instead of track one). If your getting the track name, and not just incrementing for the number in the DB then swap that line so it contains the track name and not the "Track '.$i.' bit.

Hope that helps, I'm not convinced that's what you were after though...
Joe
Ah, I think your right there Si. I'm really out of touch with my table coding so I didn't quite get what was meant.
Just Another Artist
Thanks Si! That's what I was looking for...now to go surf the Net in hopes of figuring out what the $i function is/does.

Well, in looking at the code more, I think that you simply used the letter "i" for an example as user-created variable names are regardless of what they say/mean, right?

I have taken Si's updated code and tried to make it auto-increment, but I'm missing something and I'm not sure what it is.

CODE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Query test page</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="content-language" content="en-us" />
<meta http-equiv="Imagetoolbar" content="no" />
<link rel="stylesheet" href="sah-css.css" type="text/css" />

</head>
<body>


<table cellpadding="5" cellspacing="0" border="1">
<tr><th>Title</th><th>Audio Speaker</th></tr>
<?php include_once ("config.php");

$sql = "SELECT AudioID, AudioTitle, AudioDate FROM sermonaudio";
$result = mysql_query($sql, $db);
$count = mysql_num_rows($result);
if($count == 0)
{
echo '<p>No records available.</p>';
}
$i = 1;
if ($i > 0)
{
$i++;
}
while($row = mysql_fetch_assoc($result))
{
$AudioID = $row['AudioID'];
$AudioTitle = stripslashes($row['AudioTitle']);
$AudioDate = date("d.m.y",$row['AudioDate']);

echo '<tr>';
echo '<td>Track '.$i.'</td>';
echo '<td>'.$AudioTitle.'</td>';
echo '</tr>';
}
?>
</table>
</body>
</html>


Thanks
sjthomas
Yeah I used the letter i just because it tends to be used as throwaway variables, the letters n and x are also used in this way, not sure why, I think its a throwback to the days where programmers were mathematicians. I did actually miss out a line of code if you want to increment the track numbers, my bad. All you need to do is add
CODE
$i++;

after the line
CODE
echo '</tr>';

which is near the end. it has to be inside the brackets though and after the line which echos out the variable (the track line). Hope that helps.
Just Another Artist
QUOTE(sjthomas @ May 25 2006, 10:31 AM) [snapback]34141[/snapback]

Yeah I used the letter i just because it tends to be used as throwaway variables, the letters n and x are also used in this way, not sure why, I think its a throwback to the days where programmers were mathematicians. I did actually miss out a line of code if you want to increment the track numbers, my bad. All you need to do is add
CODE
$i++;

after the line
CODE
echo '</tr>';

which is near the end. it has to be inside the brackets though and after the line which echos out the variable (the track line). Hope that helps.

What??

CODE

<table cellpadding="5" cellspacing="0" border="1">
<tr><th>Title</th><th>Audio Speaker</th></tr>
<?php include_once ("config.php");

$sql = "SELECT AudioID, AudioTitle, AudioDate FROM sermonaudio";
$result = mysql_query($sql, $db);
$count = mysql_num_rows($result);
if($count == 0)
{
echo '<p>No records available.</p>';
}
$i++;
while($row = mysql_fetch_assoc($result))
{
$AudioID = $row['AudioID'];
$AudioTitle = stripslashes($row['AudioTitle']);
$AudioDate = date("d.m.y",$row['AudioDate']);

echo '<tr>';
echo '<td>Track '.$i.'</td>';
echo '<td>'.$AudioTitle.'</td>';
echo '</tr>';
}
?>
</table>


I'm not sure what you are trying to say.
Joe
[php]table cellpadding="5" cellspacing="0" border="1">
<tr><th>Title</th><th>Audio Speaker</th></tr>
<?php include_once ("config.php");

$sql = "SELECT AudioID, AudioTitle, AudioDate FROM sermonaudio";
$result = mysql_query($sql, $db);
$count = mysql_num_rows($result);
if($count == 0)
{
echo '<p>No records available.</p>';
}
$i++;
while($row = mysql_fetch_assoc($result))
{
$AudioID = $row['AudioID'];
$AudioTitle = stripslashes($row['AudioTitle']);
$AudioDate = date("d.m.y",$row['AudioDate']);

echo '<tr>';
echo '<td>Track '.$i.'</td>';
echo '<td>'.$AudioTitle.'</td>';
echo '</tr>';
$i++;
}
?>
</table>[/php]
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.