Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > PHP

Reply
 
LinkBack Thread Tools Display Modes
Old 08-28-2004, 07:24 PM   #1 (permalink)
xtrax_22
Registered User
 
xtrax_22's Avatar
 
Join Date: Aug 2004
Posts: 8
xtrax_22 is on a distinguished road
Making a dynamic Table cell

Ok what it is l got this mod that users can upload there photo to there account ..

And what this does is it grabse there photo and displays it in a 3 cell column and then it just randomly adds new ones as required..

How you ask l already got it set up for the function and it works great the user can only upload on of 2 file formates GIF and JPEG..
which you can see in the function between table and this is where the tricky part came in..

It will only show the picture of the users that are currently logged in to there account.. which is perfect for us as we already have the other page to display all the members who have added a picture..

The problem is the tables l tried to add around my code is throwing a parser error

ERROR
Parse error: parse error in /home/virtual/site13/fst/var/www/html/tes1t.php on line 41

Here is what l got so far ..
PHP Code:
<?php  
include("header.php");  
$index 0;    
//require_once("mainfile.php");    
$module_name basename(dirname(__FILE__));    
function 
who_online() {   
    global 
$prefix$db;   
     
$sql "SELECT uname, guest FROM ".$prefix."_session WHERE guest = 0";   
     
$result $db->sql_query($sql);   
     
$member_online_num $db->sql_numrows($result);   
     
$who_online_now "";   
     
$i 1
OpenTable();  
$count 0;  
echo 
"<table border=\"1\" cellspacing=\"10\" cellpadding=\"10\">";    
     while(
$session $db->sql_fetchrow($result)) {   
         if(isset(
$session["guest"]) and $session["guest"] == 0) {   
               
$sql ="select user_id from ".$prefix."_users where username='$session[uname]'"
               list(
$user_id) = mysql_fetch_row(mysql_query($sql)); 
               
$count++;   
               if(
$count == 1) { echo "<tr>"; }   
               if(
file_exists("/home/virtual/site13/fst/var/www/html/modules/Photo/memberphotos/$user_id.jpg")) { 
                    
$who_online_now .= "<TD><center><A HREF=\"modules.php?name=Your_Account&amp;op=userinfo&amp;username=$session[uname]\"><img src=\"modules/Photo/memberphotos/$user_id.jpg\" border=\"0\" alt=\"$session[uname]\"><br>$session[uname]</center></TD></a>\n";
                    if(
$count == 3)   { echo "</tr>"; }   
                    if(
$count == 3)   { $count 0; }   
                    } 
                   }
                  }  
if(
$count == 1) { echo "<td>&nbsp;</td><td>&nbsp;</td></tr>"; }
if(
$count == 2) { echo "<td>&nbsp;</td></tr>"; } 
echo 
"</table>"
                    
$count++;   
                    if(
$count == 1) { echo "<tr>"; }       
                    
$i++; 
               }elseif(
file_exists("/home/virtual/site13/fst/var/www/html/modules/Photo/memberphotos/$user_id.gif")) { 
                    
$who_online_now .= "<TD><center><A HREF=\"modules.php?name=Your_Account&amp;op=userinfo&amp;username=$session[uname]\"><img src=\"modules/Photo/memberphotos/$user_id.gif\" border=\"0\" alt=\"$session[uname]\"><br>$session[uname]</center></TD></a>\n";
                    if(
$count == 3)   { echo "</tr>"; }   
                    if(
$count == 3)   { $count 0; }   
                    } 
                   }
                  }  
if(
$count == 1) { echo "<td>&nbsp;</td><td>&nbsp;</td></tr>"; }
if(
$count == 2) { echo "<td>&nbsp;</td></tr>"; } 
echo 
"</table>"
$i++; 
               } 
          }   
     }   
     return 
$who_online_now;   
}  
$some_stuff who_online();  
echo 
"$some_stuff"
CloseTable();
include(
"footer.php");  
}
?>
I appreciate your help greatly as its been paining me for a week or 2 now..

XtraX

Last edited by bdl; 08-28-2004 at 07:51 PM.
xtrax_22 is offline   Reply With Quote
Old 08-28-2004, 08:15 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,475
sde is on a distinguished road
rule #1: php error reporting is your friend =) .. parse error is just a syntax problem.

you could help greatly by pointing out ( maybe commenting above ) line 41.
__________________
Mike
sde is offline   Reply With Quote
Old 08-28-2004, 08:18 PM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,475
sde is on a distinguished road
i don't see it by just browsing your script, but you may want to fix this area:
Quote:
$who_online_now .= "<TD><center><A HREF=\"modules.php?name=Your_Account&op=userinfo&u sername=$session[uname]\"><img src=\"modules/Photo/memberphotos/$user_id.gif\" border=\"0\" alt=\"$session[uname]\"><br>$session[uname]</center></TD></a>\n";
your closing </a> tag is outside your </td> tag.
__________________
Mike
sde is offline   Reply With Quote
Old 08-29-2004, 01:57 AM   #4 (permalink)
DavH27
PHP Pilgrim
 
DavH27's Avatar
 
Join Date: Aug 2004
Location: London
Posts: 167
DavH27 is on a distinguished road
Now that's just shoddy HTML :tsk: :tsk:

Upon testing that code, I got the parse rror for an enexpected T_ELSEIF statement.
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a
DavH27 is offline   Reply With Quote
Old 08-29-2004, 07:09 AM   #5 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,475
sde is on a distinguished road
we like people to feel comfortable asking anything here davey. if you're gonna critisize something, at least provide some advice on how to make it better ( although he's not asking html questions here ) .. otherwise that comment is worthless to anyone.

lol, and again, posting that code has a parse error isn't very helpful without a line number and pointing out what line that error is on. hahah .. i'll get off my soap box now.
__________________
Mike
sde is offline   Reply With Quote
Old 08-29-2004, 08:16 AM   #6 (permalink)
DavH27
PHP Pilgrim
 
DavH27's Avatar
 
Join Date: Aug 2004
Location: London
Posts: 167
DavH27 is on a distinguished road
there is only one elseif!

try testin the code - it will soon tell you which line is wrong

btw i was bein sarcastic n ... well... tryna be funny
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a
DavH27 is offline   Reply With Quote
Old 08-29-2004, 08:56 AM   #7 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,475
sde is on a distinguished road
that file includes other files and uses classes i don't use, so it is no use me trying to debug it unless i want to spend more time than i have creating all that.

here is what i came up with going through the script line by line. view the comments. i could not test it, but this should help.
PHP Code:
<?php
include("header.php");  
$index 0;    
//require_once("mainfile.php");    
$module_name basename(dirname(__FILE__));
 
function 
who_online() {   
  global 
$prefix$db;   
  
$sql "SELECT uname, guest FROM ".$prefix."_session WHERE guest = 0";   
  
$result $db->sql_query($sql);   
  
$member_online_num $db->sql_numrows($result);   
  
$who_online_now "";   
  
$i 1;
  
  
OpenTable();  
  
$count 0;  
  echo 
"<table border=\"1\" cellspacing=\"10\" cellpadding=\"10\">";
   
  while(
$session $db->sql_fetchrow($result)) {  
     
    if(isset(
$session["guest"]) and $session["guest"] == 0) {   
      
$sql ="select user_id from ".$prefix."_users where username='$session[uname]'";
      
      list(
$user_id) = mysql_fetch_row(mysql_query($sql));
      
$count++;   
               
      if(
$count == 1) { echo "<tr>"; }
      
      if(
file_exists("/home/virtual/site13/fst/var/www/html/modules/Photo/memberphotos/$user_id.jpg")) {
        
$who_online_now .= "<TD><center><A HREF=\"modules.php?name=Your_Account&op=userinfo&username=$session[uname]\">
          <img src=\"modules/Photo/memberphotos/$user_id.jpg\" border=\"0\" alt=\"$session[uname]\">
          <br>$session[uname]</center></TD></a>\n"
;
        
        if(
$count == 3)   { echo "</tr>"$count=0; }   
      }
    }
  }

  if(
$count == 1) { echo "<td>&nbsp;</td><td>&nbsp;</td></tr>"; }
  if(
$count == 2) { echo "<td>&nbsp;</td></tr>"; }
  echo 
"</table>";
  
  
// up to here looks good, we printed and closed the user table
  // *************************
  // what is the rest of this for?
  // it looks like a bad copy and paste or something.
  
  // begin commenting out bad code
  /*
  $count++;   
  if($count == 1) { echo "<tr>"; }       
  $i++;
  
  }
  
  elseif(file_exists("/home/virtual/site13/fst/var/www/html/modules/Photo/memberphotos/$user_id.gif")) {
    $who_online_now .= "<TD><center><A HREF=\"modules.php?name=Your_Account&op=userinfo&username=$session[uname]\">
    <img src=\"modules/Photo/memberphotos/$user_id.gif\" border=\"0\" alt=\"$session[uname]\"><br>$session[uname]</center></TD></a>\n";
    if($count == 3)   { echo "</tr>"; }   
    if($count == 3)   { $count = 0; }   
  }
 }
}

if($count == 1) { echo "<td>&nbsp;</td><td>&nbsp;</td></tr>"; }
if($count == 2) { echo "<td>&nbsp;</td></tr>"; }
echo "</table>";
$i++;
    }
  }   
  
  }
  // end commenting out bad code
  */
  
 
return $who_online_now;   
}
// here the function is ended

$some_stuff who_online();  
echo 
"$some_stuff";
CloseTable();
include(
"footer.php");  
  
// } this closing brace does not belong here
?>
__________________
Mike
sde is offline   Reply With Quote
Old 08-29-2004, 11:19 AM   #8 (permalink)
DavH27
PHP Pilgrim
 
DavH27's Avatar
 
Join Date: Aug 2004
Location: London
Posts: 167
DavH27 is on a distinguished road
I think that bit you commented out was the actual 'meat' of the page's use :p

He wanted to dynamically create a cell for user photo.

SDE is very good at debugging! Just comment it out and no more errors!
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a
DavH27 is offline   Reply With Quote
Old 08-29-2004, 11:56 AM   #9 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,475
sde is on a distinguished road
Quote:
Originally posted by DavH27
I think that bit you commented out was the actual 'meat' of the page's use :p

He wanted to dynamically create a cell for user photo.
i hope you're being sarcastic again .. he was following my tutorial to do it. i welcome your input on what the so called 'meat' of the script was supposed to be doing. the commented out section looks pretty useless to me .. how about you?
__________________
Mike
sde is offline   Reply With Quote
Old 08-29-2004, 02:11 PM   #10 (permalink)
xtrax_22
Registered User
 
xtrax_22's Avatar
 
Join Date: Aug 2004
Posts: 8
xtrax_22 is on a distinguished road
Yes exaclty l was following the tutorial to make the tables around the user(s) photo's and just added some cellpadding while l was at it but the problem keeps persisting that as soon as l try to only set it to 3 across it breaks or doesnt show the table around the photo ..

I have taken the code you have already worked and still see the same problem is it shows the pictures but all in a row no table(s) are present ...


So how do l work it so its only goes three across...and then it just generates them as more needed..

ps sorry about last night had to go to bed had to get up for work!


xtrax_22
xtrax_22 is offline   Reply With Quote
Old 08-29-2004, 07:02 PM   #11 (permalink)
xtrax_22
Registered User
 
xtrax_22's Avatar
 
Join Date: Aug 2004
Posts: 8
xtrax_22 is on a distinguished road
Also the section you say is either worthless or a bad past job is a known function required for this to work as it needs it becuase not everyone will upload a JPG so it needs to reconize there format and the only other one we allow is the GIF format in the upload section

DavH27 was quiet right that the error was on the elsiif it was a typing error actually and should of been

}else{

then the IF statment but either way the code still dont work it grables the images but the tables are not set or present it just keeps adding the images in a perfect row instead of going


3 across and then randomly adding more Downward as needed..

Also to test this out yourself simply make a diretory and point to it there so it grabs the images

comment out the following lines

//include("footer.php");
//include("header.php");
//$module_name = basename(dirname(__FILE__));

this way you can see for your self why its not working hope this helps and l too am still working the code..

xtrax_22
xtrax_22 is offline   Reply With Quote
Old 08-29-2004, 09:41 PM   #12 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,475
sde is on a distinguished road
can you post me the results of a 'view source' once you view the html it generates?
__________________
Mike
sde is offline   Reply With Quote
Old 08-30-2004, 02:11 AM   #13 (permalink)
DavH27
PHP Pilgrim
 
DavH27's Avatar
 
Join Date: Aug 2004
Location: London
Posts: 167
DavH27 is on a distinguished road
All I saw in the commented bit was
PHP Code:
elseif(file_exists("/home/virtual/site13/fst/var/www/html/modules/Photo/memberphotos/$user_id.gif")) 
So I made an irrational assumption that was complete cobblers. Oops.
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a
DavH27 is offline   Reply With Quote
Old 08-30-2004, 04:50 AM   #14 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,475
sde is on a distinguished road
Quote:
Originally posted by xtrax_22
Also the section you say is either worthless or a bad past job is a known function required for this to work as it needs it becuase not everyone will upload a JPG so it needs to reconize there format and the only other one we allow is the GIF format in the upload section
try replacing the if(file_exists, and the line below it $whoseonline.= with this:
PHP Code:
$path "/home/virtual/site13/fst/var/www/html/modules/Photo/memberphotos/";
if(
file_exists($path.$userid.".jpg")){
  
$file=$path.$userid.".jpg";
}elseif(
$file_exists($path.$userid.".gif")){
  
$file=$path.$userid.".gif";
}

$who_online_now .= "<TD><center><A HREF=\"modules.php?name=Your_Account&op=userinfo&username=$session[uname]\">
          <img src=\"$file\" border=\"0\" alt=\"$session[uname]\">
          <br>$session[uname]</center></TD></a>\n"

leave the stuff i commented before commented out.
__________________
Mike
sde is offline   Reply With Quote
Old 08-30-2004, 08:11 PM   #15 (permalink)
xtrax_22
Registered User
 
xtrax_22's Avatar
 
Join Date: Aug 2004
Posts: 8
xtrax_22 is on a distinguished road
ok l made those changes but it still throws an error


Parse error: parse error in /home/virtual/site13/fst/var/www/html/tes1t.php on line 80


here is what we got so far

<?php
include("header.php");
$index = 0;
//require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));

function who_online() {
global $prefix, $db;
$sql = "SELECT uname, guest FROM ".$prefix."_session WHERE guest = 0";
$result = $db->sql_query($sql);
$member_online_num = $db->sql_numrows($result);
$who_online_now = "";
$i = 1;

OpenTable();
$count = 0;
echo "<table border=\"1\" cellspacing=\"10\" cellpadding=\"10\">";

while($session = $db->sql_fetchrow($result)) {

if(isset($session["guest"]) and $session["guest"] == 0) {
$sql ="select user_id from ".$prefix."_users where username='$session[uname]'";

list($user_id) = mysql_fetch_row(mysql_query($sql));
$count++;

if($count == 1) { echo "<tr>"; }

$path = "/home/virtual/site13/fst/var/www/html/modules/Photo/memberphotos/";
if(file_exists($path.$userid.".jpg")){
$file=$path.$userid.".jpg";
}elseif($file_exists($path.$userid.".gif")){
$file=$path.$userid.".gif";
}
$who_online_now .= "<TD><center><A HREF=\"modules.php?name=Your_Account&op=userinfo&u sername=$session[uname]\"><img src=\"$file\" border=\"0\" alt=\"$session[uname]\"><br>$session[uname]</center></TD></a>\n";

if($count == 3) { echo "</tr>"; $count=0; }
}
}
}

if($count == 1) { echo "<td>&nbsp;</td><td>&nbsp;</td></tr>"; }
if($count == 2) { echo "<td>&nbsp;</td></tr>"; }
echo "</table>";

// up to here looks good, we printed and closed the user table
// *************************
// what is the rest of this for?
// it looks like a bad copy and paste or something.

// begin commenting out bad code
/*
$count++;
if($count == 1) { echo "<tr>"; }
$i++;

}

elseif(file_exists("/home/virtual/site13/fst/var/www/html/modules/Photo/memberphotos/$user_id.gif")) {
$who_online_now .= "<TD><center><A HREF=\"modules.php?name=Your_Account&op=userinfo&u sername=$session[uname]\">
<img src=\"modules/Photo/memberphotos/$user_id.gif\" border=\"0\" alt=\"$session[uname]\"><br>$session[uname]</center></TD></a>\n";
if($count == 3) { echo "</tr>"; }
if($count == 3) { $count = 0; }
}
}
}

if($count == 1) { echo "<td>&nbsp;</td><td>&nbsp;</td></tr>"; }
if($count == 2) { echo "<td>&nbsp;</td></tr>"; }
echo "</table>";
$i++;
}
}

}
// end commenting out bad code
*/

return $who_online_now;
//}
// here the function is ended

$some_stuff = who_online();
echo "$some_stuff";
CloseTable();
include("footer.php");

// } this closing brace does not belong here
?>

Now there is no prictures present and no tables its a blank page its not outputting anything!


XtraX
xtrax_22 is offline   Reply With Quote
Reply

Bookmarks