Jump to content

[SOLVED] Formating a table 'within' php


fireice87

Recommended Posts

Hey im trying to make a table  that is built with a php loop that selects data from a mysql database. iv created the table and made the loop. The problem im having is with the table formatting it seems very awkward to try and get it how i want as its hard to see why  some of the issues are occuring.

Heres an image of the table, below the image is the code, then what i need help changing thanks!

table.jpg

<?php
$sql = "Select * FROM giglist";  //pull the users from the table

$result= @mysql_query($sql, $conn )
or die(" Could not add style facts");

echo "<table  border=\"1\">";                                                     // display the users in table
$c = 0;
while($row = mysql_fetch_array($result)) { 
    $date = $row['date'];
$band = $row['band'];
$venue = $row['venue'];
$location = $row['location'];
$numattending = $row['numattending'];
$numcomments =  $row['numcomments'];
$addedby = $row['added_by'];
  	echo "<tr height=\"20px\">"; // If the counter has ticked 6 times, start a new row.
   	echo "<td width=\"50px\"align=center>", $date; ?></td><? 
echo "<td width=\"120px\"align=center>", $band; ?> </td><?
echo "<td width=\"230px\"align=center colspan=\"2\">", $venue; ?> - <? echo $location; ?> </td></tr><?
echo "<tr height=\"20px\"align=center>";
echo "<tr width=\"50px\"align=center>";
echo "<td width=\"130px\"align=center>" ?><img src="ContactInvite.jpg" alt="num attending" /> <? echo  $numattending; ?></td> <?
echo "<td width=\"120px\"align=center>" ?><img src="Comment.jpg" alt="Comments" /> <? echo $numcomments; ?></td> <?
echo "<td width=\"120px\"align=center>" ?><img src="Write.jpg" alt="Added by" /> <? echo $addedby; ?></td><?
echo "</tr>";
}
echo "</table>"; 
?>

My main problem is the white space between the rows i have no idea why thats being created and have tried re writing the code in diffrent ways but cant get rid of it.

Allthough a diffrent issue im allso confused how to shorten a variable.

for example if the location varaiable was to long to display how would i only show the first 15 characters?

Thanks for anyhelp :)

 

Link to comment
Share on other sites

<?php
    $sql = "Select * FROM giglist";  //pull the users from the table

    $result= @mysql_query($sql, $conn )
    or die(" Could not add style facts");

    echo "<table  border=\"1\">\n";

    while($row = mysql_fetch_array($result)) { 
        echo "<tr height=\"20px\">\n";
        echo "  <td width=\"130px\" align=\"center\">$row['date']</td>\n";
        echo "  <td width=\"120px\" align=\"center\">$row['band']</td>\n";
        echo "  <td width=\"120px\" align=\"center\">$row['venue'] - " . substr($row['location'], 0, 15) . "</td>\n";
        echo "</tr>\n";

        echo "<tr height=\"20px\">\n";
        echo "  <td width=\"130px\" align=\"center\"><img src=\"ContactInvite.jpg\" alt=\"num attending\" $row['numattending']</td>\n";
        echo "  <td width=\"120px\" align=\"center\"><img src=\"Comment.jpg\" alt=\"Comments\" /> $row['numcomments']</td>\n";
        echo "  <td width=\"120px\" align=\"center\"><img src=\"Write.jpg\" alt=\"Added by\" /> $row['added_by']</td>\n";
        echo "</tr>\n";
    }

    echo "</table>\n"; 
?>

Link to comment
Share on other sites

;D Thank you that works brilliantly!

 

at first it was throwing up "Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING on llin 46- 48

 

after playing about for a bit i copied the method u used on  . substr($row['location'], 0, 15) . and added the full stops

so turned it into  echo "  <td width=\"130px\" align=\"center\">" . $row['date'] . "</td>\n";

 

I dont know why that worked though? Iv seen these full stops in code before but didnbt come across it when i was learning the basic php syntax

 

Thanks again ! :D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.