Where have i gone wrong?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fiddles
Forum Newbie
Posts: 5
Joined: Fri Jun 19, 2009 8:01 am

Where have i gone wrong?

Post 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
Last edited by Benjamin on Wed Jun 24, 2009 12:41 pm, edited 1 time in total.
Reason: Changed code type from text to php.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Where have i gone wrong?

Post 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?
fiddles
Forum Newbie
Posts: 5
Joined: Fri Jun 19, 2009 8:01 am

Re: Where have i gone wrong?

Post 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
Last edited by Benjamin on Wed Jun 24, 2009 12:43 pm, edited 1 time in total.
Reason: Changed code type from text to php.
Loki
Forum Commoner
Posts: 25
Joined: Wed Jun 03, 2009 9:23 pm

Re: Where have i gone wrong?

Post 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.
Last edited by Benjamin on Wed Jun 24, 2009 12:44 pm, edited 1 time in total.
Reason: Changed code type from text to php.
fiddles
Forum Newbie
Posts: 5
Joined: Fri Jun 19, 2009 8:01 am

Re: Where have i gone wrong?

Post 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:
Loki
Forum Commoner
Posts: 25
Joined: Wed Jun 03, 2009 9:23 pm

Re: Where have i gone wrong?

Post by Loki »

Haha, we all make typos!
fiddles
Forum Newbie
Posts: 5
Joined: Fri Jun 19, 2009 8:01 am

Re: Where have i gone wrong?

Post 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!
Last edited by Benjamin on Wed Jun 24, 2009 12:46 pm, edited 1 time in total.
Reason: Changed code type from text to php.
fiddles
Forum Newbie
Posts: 5
Joined: Fri Jun 19, 2009 8:01 am

Re: Where have i gone wrong?

Post 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
Last edited by Benjamin on Wed Jun 24, 2009 12:46 pm, edited 1 time in total.
Reason: Changed code type from text to php.
Post Reply