[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

dynamic table results

Posted on 2003-12-01
9
Medium Priority
?
290 Views
Last Modified: 2008-03-17
hello,
I am trying to find a tutorail to create a dynamic table, what i mean is this, if their are 3 results it will output like this
<tr><td>$output</td><td>$output</td><td>$output</td></tr>

is their is only one then it would be this
<tr><td>$output</td><td>&nbsp;</td><td>&nbsp;</td></tr>

is their is 5 then it would be this
<tr><td>$output</td><td>$output</td><td>$output</td></tr>
<tr><td>$output</td><td>$output</td><td>&nbsp;</td></tr>

I have no idea how to do this with php, i have an sap script, but i cant see using it,, this is my output script for displaying single rows
            <?
while($row = @mysql_fetch_array($result))
{

     $imageID = $row['imageID'];
     $imageName = $row['imageName'];
     $imageNameS = $row['imageNameS'];       
     $imageClientID = $row['imageClientID'];
       $imageBlurb = $row['imageBlurb'];
       $imageDate = $row['imageDate'];

$option_block .="<td><a href='admin/uploads/$imageName' target='blank'><img src='$imageNameS' height='100'></a></td>";

}
$display_block = "
<table><tr>
 $option_block  
  </tr></table>";
?>
0
Comment
Question by:jblayney
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 1

Author Comment

by:jblayney
ID: 9854998
ok, i tried this,i think im close.. no errors , but no output either

            <?
while($row = @mysql_fetch_array($result))
{

     $imageID = $row['imageID'];
     $imageName = $row['imageName'];
     $imageNameS = $row['imageNameS'];       
     $imageClientID = $row['imageClientID'];
       $imageBlurb = $row['imageBlurb'];
       $imageDate = $row['imageDate'];


$i = $row;
while ($i < 3) {
$option_block .="<tr><td><a href='admin/uploads/$imageName' target='blank'><img src='$imageNameS' height='100'></a></td>";
$i++;
$option_block .="</tr>";
}
$option_block .="</tr>";
}



$display_block = "
<table>
 $option_block  
</table>";
?>
0
 
LVL 1

Author Comment

by:jblayney
ID: 9855283
ok, im even closer, my output now diplays an error and each image is displayed 3 times.. lol

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /u/j/jeremy/www.website.com/photopage.php on line 119
 
is my error

while($row = @mysql_fetch_array($result))
{

     $imageID = $row['imageID'];
     $imageName = $row['imageName'];
     $imageNameS = $row['imageNameS'];       
     $imageClientID = $row['imageClientID'];
       $imageBlurb = $row['imageBlurb'];
       $imageDate = $row['imageDate'];

$num_rows = mysql_num_rows($sql);
$i = $num_rows;
while ($i < 3) {
$option_block .="<td><a href='admin/uploads/$imageName' target='blank'><img src='admin/uploads/$imageNameS' height='100'></a></td>";
$i++;
$option_block .="</tr>";
}
$option_block .="</tr>";
}
$display_block = "
<table>
 $option_block  
</table>";
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9855375
hi,

i thought i'd try and do this as cleanly as possible:

<?
$j = 0;
print "<table>";
for($i = 0; $row = mysql_fetch_array($result) > $i; $i++) {
  if($j == 0) {
    print "<tr>";
  }
  print "<td><a href=\"admin/uploads/" . $row["imageName"] . "\" target='blank'><img src=\"" . $row["imageNameS] . "\" height=\"100\"></a></td>";
  if($j == 2) {
    print "</tr>";
    $j = -1;
  }
$j++;
}
$left = 3 - $j;
$k = 0;
if($left > 0) {
  for($k = 0; $k < $left; $k++) {
    print "<td>&nbsp;</td>\n";
  }
}
print "</table>";
?>

tell me how you get on

loz
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:jblayney
ID: 9856123
tx loz,
it is clean, one thign doesnt work though

print "<td><a href=\"admin/uploads/" . $row["imageName"] . "\" target='blank'><img src=\"admin/uploads/" . $row["imageNameS"] . "\" height=\"100\"></a></td>";

its displaying empty images and the links dont work, when you roll over with the mouse it displays the file path minus the filename
0
 
LVL 1

Author Comment

by:jblayney
ID: 9856186
hey loz,
i rewrote the output 3 different ways, it all does the same thing, it gets the proper amount of results and displayes the tr and td properly, but its not getting the imageName and imageNameS,

Its like its this
I know their are 4 of you, but i dont know your names
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9856199
hmm that's strange can you do print_r($row); after each for statement and paste the html in here? (i.e. run the script > view source then copy the output and paste it here)

cheers,

loz
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9856209
well that leads me to suspect something in your query is amiss - can i see it? maybe you're not selecting the correct columns?

loz
0
 
LVL 1

Author Comment

by:jblayney
ID: 9856293
ok, my SQL was select * but now i specified

$sql = "SELECT imageID, imageName, imageNameS FROM $table_name WHERE imageClientID = $id ORDER BY imageName";
            
$result = @mysql_query($sql, $connection) or die("Error3 - Couldn't connect - please try later.");

$j = 0;
print "<table>";
for($i = 0; $row = @mysql_fetch_array($result) > $i; $i++) {
print_r($row);
if($j == 0) {
print "<tr>";
}
print "<td><a href=\"admin/uploads/" .$row["imageName"]. "\" target='blank'><img src=\"admin/uploads/" .$row["imageNameS"]. "\" height=\"100\"></a></td>";


if($j == 2) {
print "</tr>";
$j = -1;
}
$j++;
}
$left = 3 - $j;
$k = 0;
if($left > 0) {
for($k = 0; $k < $left; $k++) {
print_r($row);
print "<td>&nbsp;</td>\n";
}
}
print "</table>";
?>

I added 2 print_r($row); and my HTML output is

<table>1<tr><td><a href="admin/uploads/" target='blank'><img src="admin/uploads/" height="100"></a></td>1<td><a href="admin/uploads/" target='blank'><img src="admin/uploads/" height="100"></a></td>1<td><a href="admin/uploads/" target='blank'><img src="admin/uploads/" height="100"></a></td></tr>1<tr><td><a href="admin/uploads/" target='blank'><img src="admin/uploads/" height="100"></a></td><td>&nbsp;</td>
<td>&nbsp;</td>
</table>
0
 
LVL 13

Accepted Solution

by:
lozloz earned 200 total points
ID: 9857516
try this:

<?
$j = 0;
print "<table>";
$num = mysql_num_rows($result);
for($i = 0; $num > $i; $i++) {
  $row = mysql_fetch_assoc($result);
  if($j == 0) {
    print "<tr>";
  }
  print "<td><a href=\"admin/uploads/" . $row["imageName"] . "\" target='blank'><img src=\"" . $row["imageNameS] . "\" height=\"100\"></a></td>";
  if($j == 2) {
    print "</tr>";
    $j = -1;
  }
$j++;
}
$left = 3 - $j;
$k = 0;
if($left > 0) {
  for($k = 0; $k < $left; $k++) {
    print "<td>&nbsp;</td>\n";
  }
}
print "</table>";
?>

loz
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question