Page 1 of 1

Where have i gone wrong?

Posted: Fri Jun 19, 2009 8:04 am
by fiddles
Hi all,

I have this script below which just calls on the database to display all in that table, ive recently added in some formatting/styling into the code and now im no longer getting any results and cant make out what i have done wrong!

Code: Select all

<style type="text/css">
.ay_client
{
 border:2px solid #ccc;
 background:#fff;
 width:500px;
 padding:10px;
 text-align:center;
 overflow:auto;
 table-cell:2px solid #ccc;
 }
td {
 position: relative;
 width: 14%;
 margin: 0;
 border-width: 1px 1px 1px 1px;
 border-style: solid;
 border-color: #000;
 padding-top: 1em;
 vertical-align: center;
}
tr.odd {
      background-color:#ffffff;
}
tr.even {
      background-color:#cccccc;
}
</style>
<div class="ay_client">
<?php
$query =  mysql_query("SELECT * FROM jos_ay_client_activity");
{
echo $row['month'];
}
?><table><tr><td><b>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=datetime&dir=ASC">
<img src="images/M_images/sort0.png"></a>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=datetime&dir=DESC">
<img src="images/M_images/sort1.png"></a>
<br>Entered</b></td>&nbsp;
<td><b>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=month&dir=ASC">
<img src="images/M_images/sort0.png"></a>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=month&dir=DESC">
<img src="images/M_images/sort1.png"></a>
<br>Month</b></td>&nbsp;
<td><b>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=year&dir=ASC">
<img src="images/M_images/sort0.png"></a>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=year&dir=DESC">
<img src="images/M_images/sort1.png"></a>
<br>Year</b></td>&nbsp;
<td><b>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=client&dir=ASC">
<img src="images/M_images/sort0.png"></a>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=client&dir=DESC">
<img src="images/M_images/sort1.png"></a>
<br>Client</b></td>&nbsp;
<td><b>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=surveys&dir=ASC">
<img src="images/M_images/sort0.png"></a>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=surveys&dir=DESC">
<img src="images/M_images/sort1.png"></a>
<br>Surveys</b></td>&nbsp;
<td><b>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=airtests&dir=ASC">
<img src="images/M_images/sort0.png"></a>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=airtests&dir=DESC">
<img src="images/M_images/sort1.png"></a>
<br>Air Tests</b></td>&nbsp;
<td><b>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=project&dir=ASC">
<img src="images/M_images/sort0.png"></a>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=project&dir=DESC">
<img src="images/M_images/sort1.png"></a>
<br>Projects</b></td>&nbsp;
<td><b>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=bulks&dir=ASC">
<img src="images/M_images/sort0.png"></a>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=bulks&dir=DESC">
<img src="images/M_images/sort1.png"></a>
<br>Bulks</b></td></tr></table>
<?php
while($row = mysql_fetch_array($query))
echo '<table>';
for ($i = 0; $i < 10; $i++)
{
$class = $i%2 == 0? 'odd':'even';
    echo "<tr class='" . $class . "' ><td>";
    echo $row['datetime'];
    echo "</td><td>";
    echo $row['month'];
    echo "</td><td>";
    echo $row['year'];
    echo "</td><td>";
    echo $row['client'];
    echo "</td><td>";
    echo $row['surveys'];
    echo "</td><td>";
    echo $row['airtests'];
    echo "</td><td>";
    echo $row['project'];
    echo "</td><td>";
    echo $row['bulks'];
    echo "</td></tr>";
}
 
echo "</table>";
?></div>
Anyone see anything that jumps out immediately?

Cheers

Re: Where have i gone wrong?

Posted: Fri Jun 19, 2009 10:18 am
by Eric!
Quick guess is line 84 is missing an open bracket. Does this script run? I'm assuming not 'getting results' means your database data isn't appearing. Did you look at the outputted html source for signs of other problems?

Re: Where have i gone wrong?

Posted: Fri Jun 19, 2009 10:53 am
by fiddles
Hi Eric, Thanks for the reply

Code: Select all

while($row = mysql_fetch_array($query))
There are two open and two close brackets? Unless im missing something from lines above :P

Yes sorry, no data is being displayed, the formatting i added in was to highlight even/odd cells in two separate colours to make the lines distinguishable.

There appears to be no problems with any html/css other php files associated with the page that this information is displayed on. Basically this was a working script before i added in the formatting - after i implemented the formatting code is where it went proverbially tits up.

The lines i added into the working script for the formatting were

Code: Select all

for ($i = 0; $i < 10; $i++)
$class = $i%2 == 0? 'odd':'even';
class='" . $class . "' // into the tr tag for my results
- And obviously css styling

I also had to move the script around a bit to accommodate the styling.

Im no PHP pro - have some experience - obviously not enough to fix this! :cry:

Here is the original script

Code: Select all

<style>
.ay_client
{
 border:2px solid #ccc;
 background:#ff;
 width:500px;
 height:500px;
 padding:10px;
 text-align:center;
 overflow:auto;
 }
</style>
<div class="ay_client">
<?php
$query =  mysql_query("SELECT * FROM jos_ay_client_activity");
{
echo $row['month'];
}
echo "<table><tr><td>Date Time</td>&nbsp;<td>Month</td>&nbsp;<td>Year</td>&nbsp;<td>Client</td>&nbsp;<td>Surveys</td>&nbsp;<td>Air Tests</td>&nbsp;<td>Project Managements</td>&nbsp;<td>Bulk Samples</td></tr>";
 
while($row = mysql_fetch_array($query))
{
    echo "<tr><td>";
    echo $row['datetime'];
    echo "</td><td>";
    echo $row['month'];
    echo "</td><td>";
    echo $row['year'];
    echo "</td><td>";
    echo $row['client'];
    echo "</td><td>";
    echo $row['surveys'];
    echo "</td><td>";
    echo $row['airtests'];
    echo "</td><td>";
    echo $row['project'];
    echo "</td><td>";
    echo $row['bulks'];
    echo "</td></tr>";
}
 
echo "</table>";
?></div>
Any pointers greatly appreciated

Re: Where have i gone wrong?

Posted: Fri Jun 19, 2009 10:58 am
by Loki
Change

Code: Select all

while($row = mysql_fetch_array($query))
to

Code: Select all

while($row = mysql_fetch_array($query)) {
{} are brackets. :P You seem to have deleted one when you added the styling.

Re: Where have i gone wrong?

Posted: Fri Jun 19, 2009 11:14 am
by fiddles
In which case apologies Eric - lost in um translation? :)

Thanks for clarifying Loki - also had deleted the close bracket after my table close tag :) Why you ask? No idea :) i wont be doing that again though - thanks for checking my work though guys, its friday night beers on me! :drunk:

Re: Where have i gone wrong?

Posted: Fri Jun 19, 2009 11:28 am
by Loki
Haha, we all make typos!

Re: Where have i gone wrong?

Posted: Mon Jun 22, 2009 2:53 am
by fiddles
Hehe so i guess i was in too much of a rush to check the code on Friday, got a slight problem with it :roll:

Code: Select all

<style type="text/css">
.ay_client
{
 border:2px solid #ccc;
 background:#fff;
 width:500px;
 padding:10px;
 text-align:center;
 overflow:auto;
 table-cell:2px solid #ccc;
 }
td {
 position: relative;
 width: 14%;
 margin: 0;
 border-width: 1px 1px 1px 1px;
 border-style: solid;
 border-color: #000;
 padding-top: 1em;
 vertical-align: center;
}
tr.odd {
      background-color:#ffffff;
}
tr.even {
      background-color:#cccccc;
}
</style>
<div class="ay_client">
<?php
$query =  mysql_query("SELECT * FROM jos_ay_client_activity");
{
echo $row['month'];
}
?><table><tr><td><b>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=datetime&dir=ASC">
<img src="images/M_images/sort0.png"></a>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=datetime&dir=DESC">
<img src="images/M_images/sort1.png"></a>
<br>Entered</b></td>&nbsp;
<td><b>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=month&dir=ASC">
<img src="images/M_images/sort0.png"></a>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=month&dir=DESC">
<img src="images/M_images/sort1.png"></a>
<br>Month</b></td>&nbsp;
<td><b>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=year&dir=ASC">
<img src="images/M_images/sort0.png"></a>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=year&dir=DESC">
<img src="images/M_images/sort1.png"></a>
<br>Year</b></td>&nbsp;
<td><b>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=client&dir=ASC">
<img src="images/M_images/sort0.png"></a>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=client&dir=DESC">
<img src="images/M_images/sort1.png"></a>
<br>Client</b></td>&nbsp;
<td><b>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=surveys&dir=ASC">
<img src="images/M_images/sort0.png"></a>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=surveys&dir=DESC">
<img src="images/M_images/sort1.png"></a>
<br>Surveys</b></td>&nbsp;
<td><b>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=airtests&dir=ASC">
<img src="images/M_images/sort0.png"></a>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=airtests&dir=DESC">
<img src="images/M_images/sort1.png"></a>
<br>Air Tests</b></td>&nbsp;
<td><b>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=project&dir=ASC">
<img src="images/M_images/sort0.png"></a>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=project&dir=DESC">
<img src="images/M_images/sort1.png"></a>
<br>Projects</b></td>&nbsp;
<td><b>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=bulks&dir=ASC">
<img src="images/M_images/sort0.png"></a>
<a href="index.php?option=com_jumi&fileid=4&Itemid=50?orderby=bulks&dir=DESC">
<img src="images/M_images/sort1.png"></a>
<br>Bulks</b></td></tr></table>
<?php
while($row = mysql_fetch_array($query)) {
echo '<table>';
for ($i = 0; $i < 10; $i++)
{
$class = $i%2 == 0? 'odd':'even';
    echo "<tr class='" . $class . "' ><td>";
    echo $row['datetime'];
    echo "</td><td>";
    echo $row['month'];
    echo "</td><td>";
    echo $row['year'];
    echo "</td><td>";
    echo $row['client'];
    echo "</td><td>";
    echo $row['surveys'];
    echo "</td><td>";
    echo $row['airtests'];
    echo "</td><td>";
    echo $row['project'];
    echo "</td><td>";
    echo $row['bulks'];
    echo "</td></tr>";
}
 
echo "</table>"; }
?></div>
Basically i get results, the formatting is correct, but each record is displayed 10 times! Im guessing the problem lies within:

Code: Select all

for ($i = 0; $i < 10; $i++)
{
$class = $i%2 == 0? 'odd':'even';
If i change 10 to 1 - I get the correct amount of results but with no formatting... think i need to change the code slightly - anything obvious?

*EDIT* Ive been told that all i need to do is add a variable for each row... but im unsure on this!

Re: Where have i gone wrong?

Posted: Wed Jun 24, 2009 11:21 am
by fiddles
Fixed problem now with this

Code: Select all

<?php
$count = 0;
echo '<table>';
while($row = mysql_fetch_array($query)) {    
    $class = $count%2 == 0 ? 'odd' : 'even';
    echo "<tr class='" . $class . "' ><td>";
    echo $row['datetime'];
    echo "</td><td>";
    echo $row['month'];
    echo "</td><td>";
    echo $row['year'];
    echo "</td><td>";
    echo $row['client'];
    echo "</td><td>";
    echo $row['surveys'];
    echo "</td><td>";
    echo $row['airtests'];
    echo "</td><td>";
    echo $row['project'];
    echo "</td><td>";
    echo $row['bulks'];
    echo "</td></tr>";  
    $count++;
}
echo "</table>";
?>
added in count and changed the variable $i to $count - thanks to those who helped