Forum Moderators: coopster
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>PARTNERS PAGE</title>
</head>
<body>
<?php
$query = "SELECT link FROM testlogo";
$results = mysql_query($query)
or die(mysql_error());
echo '<table>';
$cols=3;
$numtd = 3;
while ($row = mysql_fetch_row($results)) {
echo "<tr>";
foreach($row as $value) {
echo "<td>$value</td>";
echo "</tr>";
}
}
echo "</tr>";
echo "</table>\n";
?>
</body>
</html>
Also if you are trying to create 3 columns and not 3 rows, your code should look like this:
while ($row = mysql_fetch_row($results)) {
echo "<tr>";
foreach($row as $value) {
echo "<td>$value</td>";
}
echo "</tr>";
}
echo "</table>\n";
Columns go up/down, rows go left/right.
If you are looking for 3 columns, then it is possible that your query is not returning the proper data.
Lets do some troubleshooting here. Insert the following code after "$numtd = 3;":
print_r(mysql_fetch_row($results));
Let me know what you get back from the print_r. Just paste the results into here.
<?php
$sql="select link from testlogo";
if(mysql_query($sql))
{
$check=mysql_query($sql);
$no=mysql_num_rows($check);
}
echo"<table>";
echo "<table border=\"1\">\n";
for($i=0; $i<$no; $i++){
if($i%3==0){echo"<tr><td>";}
else{echo "<td>";
}
print mysql_result($check,0+$i,"link");
if($i%3==0){
echo "</td>";}
else
{
echo "</td>";}
}
echo "</tr>";
echo "</table>\n";
?>
</body>
</html>
a simple example using 3 columns:
$array = array(1,2,3,4,5,6,7,8,9,10,11,12,13);
$cols = 3;
$count = count($array);if($count%$cols > 0){
for($i=0;$i<($cols-$count%$cols);$i++){
$array[] = ' ';
}
}
echo "<table border=\"1\">\r\n";foreach($array as $key => $td){
if($key%$cols == 0) echo "<tr>\r\n";
echo "<td>$td</td>\r\n";
if($key%$cols == ($cols - 1)) echo "</tr>\r\n";
}
echo "</table>";
will return:
<table border="1">
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
<tr>
<td>10</td>
<td>11</td>
<td>12</td>
</tr>
<tr>
<td>13</td>
<td> </td>
<td> </td>
</tr>
</table>
$array = array($no);
$cols = 3;
$count = count($array);
you see i want the page to be dynamic and the array is static, however I'm not 100% sure if you can actually call a variable from within an array, so far what I have been getting is a frame with 3 boxes and one with the number of records to be display.
8
try this:
$sql="select link from testlogo";
$array = array(); // initialize array
if(mysql_query($sql))
{
$check=mysql_query($sql);
while($row=mysql_fetch_row($check)){
$array[] = $row[0];
}
}
$cols = 3;
$count = count($array);
if($count%$cols > 0){
for($i=0;$i<($cols-$count%$cols);$i++){
$array[] = ' ';
}
}
echo "<table border=\"1\">\r\n";foreach($array as $key => $td){
if($key%$cols == 0) echo "<tr>\r\n";
echo "<td>$td</td>\r\n";
if($key%$cols == ($cols - 1)) echo "</tr>\r\n";
}
echo "</table>";