Jump to content

PHP Newbie stumblin' around in the dark


Securus

Recommended Posts

I apologize that this is going to be a "Here's my code, help me make it right" post but I've been thrown onto the tracks by the people I work for to get a website more usable, and quickly.

 

I don't know php. I can read the code, and reverse engineer some of it, but that's about it.

 

What I have here is a profile that will also display other people related to that profile. Currently the other people who are related to the original profile are not linked and you can't access their seperate pages. What I attempted to do was add a link to the Name of the other persons profile. After a little troubleshooting I got that to work, but then, the images attached to the profile wouldn't display. So with my change activated, you can click a link and get to the other profiles but the picture wont display. Without my change, profile pictures display just fine but you can't click on anything to get to the related profiles.

 

<?

/****************************

BLAH Display

****************************/

include 'includes/BLAH_subs.php';

include "includes/head.html";


$lnum = $_REQUEST['r'];
$wherelit = $_REQUEST['w'];

$ttl = $_REQUEST['ttl'];
if(empty($ttl)) { $ttl = ''; }
          else { $ttl = stripslashes(urldecode($ttl)); }

$ttllit = urlencode($ttl);


$query = "SELECT *, (YEAR(CURDATE())-YEAR(dob)) - (RIGHT(CURDATE(),5)<RIGHT(dob,5)) AS age FROM children WHERE listingnumber='$lnum'";
$result = db_query($query,__LINE__ ,__FILE__);
$number = mysql_numrows($result);

if($number < 1) { do_error("No Entry for Listing # $lnum."); }

$row = mysql_fetch_assoc($result);
extract($row);


// find siblings

$query = "SELECT listingnumber, firstname FROM children WHERE rootchild='$rootchild'";
$result = db_query($query,__LINE__ ,__FILE__);
$number = mysql_numrows($result);

$siblist = array();
$names = array();

$i = 0;
while($i < $number) {
   list($ln,$fname) = mysql_fetch_row($result);
   if($ln == $lnum) { array_unshift($names, $fname); $i++; continue; }
   $names[] = $fname;
   $siblist[] = $ln;
   $i++;
}


$token = array();

$token['%LISTINGNUMBER%'] = $listingnumber;

$filename = str_replace('S','s',$filename);
$filename_hi = $filename . "_hi";
if(!empty($filename) && file_exists("/MY/PATH/TO/STUFF/$filename.jpg")) { $token['%FILENAME%'] = $filename; }
                else { $token['%FILENAME%'] = 'nopicture'; }


if(count($names) > 1) {
   $namstr = implode(", ", array_slice($names, 0, count($names)-1));
   $namstr .= ' and '.$names[count($names)-1];
   $token['%NAMELIST%'] = $namstr;
} else {
   $token['%NAMELIST%'] = $firstname;
}


$token['%FIRSTNAME%'] = $firstname;
$token['%SEX%'] = $gender[$sex];
$token['%RACE%'] = $races[$race];
$token['%SIBLINGS%'] = $sibgroupsize;
$token['%DOB%'] = date("m/d/Y", strtotime($dob));
$token['%AGE%'] = $age;

$token['%INTRODUCTION%'] = stripslashes($introduction);
$token['%CLOSERLOOK%'] = stripslashes($acloserlook);
$token['%HOWTOHELP%'] = stripslashes($howyoucanhelp);

$narrative = '';
if(!empty($introduction)) { $narrative .= '<p>' . stripslashes($introduction) . '</p>'; }
if(!empty($acloserlook)) { $narrative .= '<p>' .stripslashes($acloserlook) . '<p>'; }
if(!empty($howyoucanhelp)) { $narrative .= '<p>' .stripslashes($howyoucanhelp) . '<p>'; }
$token['%NARRATIVE%'] = $narrative;

$token['%PHYSICAL%'] = $levels[$physical];
$token['%EMOTIONAL%'] = $levels[$emotional];
$token['%MENTAL%'] = $levels[$mental];
$token['%LEARNING%'] = $levels[$learning];

if(($lastvideodate != '0000-00-00') and ($lastvideodate != '0000-01-01') and (file_exists("/MY/PATH/TO/STUFF/$filename_hi.mov"))) { $token['%VIDEOLINK%'] = "<br>See My Video!  <a href=STUFF/$filename.mov>Low Bandwidth Version</a>  <a href=STUFF/$filename_hi.mov>High Bandwidth Version</a>"; }
			elseif(($lastvideodate != '0000-00-00') and ($lastvideodate != '0000-01-01')) { $token['%VIDEOLINK%'] = "<br><a href=STUFF/$filename.mov>See My Video!</a>"; }
			else { $token['%VIDEOLINK%'] = ''; }


$sx = $gender[$sex];
$rc = $races[$race];
$ws = date("m/d/Y", strtotime($photolistdate));
$tu = date("m/d/Y", strtotime($lastupdate));
$pu = date("m/d/Y", strtotime($lastphotodate));
$pl = $levels[$physical];
$el = $levels[$emotional];
$ml = $levels[$mental];
$ll = $levels[$learning];

$token["%MYDATA%"] = "<table border=1 cellspacing=0 cellpadding=4 width=65%>
<tr><th colspan=4>$firstname - $listingnumber</th></tr>
<tr><td align=center colspan=2 width=50%>$sx</td><td align=center colspan=2 width=50%>$rc</td></tr>
<tr><td align=center colspan=2>$age years old</td><td align=center colspan=2>Waiting Since $ws</td></tr>
<tr><td align=center colspan=2>Story updated $tu</td><td align=center colspan=2>Photo updated $pu</td></tr>
<tr><th colspan=4><font size=2>Impairment Levels</font></th></tr>
<tr><th><font size=2>Physical</font></th><th><font size=2>Emotional</font></th><th><font size=2>Mental</font></th><th><font size=2>Learning</font></th></tr>
<tr><td align=center>$pl</td><td align=center>$el</td><td align=center>$ml</td><td align=center>$ll</td></tr>
</table><br><br>";


$token['%SIBDATA1%'] = '';
$token['%SIBDATA2%'] = '';
$token['%SIBDATA3%'] = '';
$token['%SIBDATA4%'] = '';
$token['%SIBDATA5%'] = '';
$token['%SIBDATA6%'] = '';


if(count($siblist) > 0) {
   for($x=0; $x<count($siblist); $x++) {

       $query = "SELECT *, (YEAR(CURDATE())-YEAR(dob)) - (RIGHT(CURDATE(),5)<RIGHT(dob,5)) AS age FROM children WHERE listingnumber='".$siblist[$x]."'";
       $result = db_query($query,__LINE__ ,__FILE__);
       $number = mysql_numrows($result);

       if($number < 1) { do_error("Cant Find Record for Sibling Listing Number ".$siblist[$x]); }
       if($number > 1) { do_error("Duplicate Entry for Sibling Listing Number ".$siblist[$x]); }

       $row = mysql_fetch_assoc($result);
       extract($row);

       $sx = $gender[$sex];
       $rc = $races[$race];
       $ws = date("m/d/Y", strtotime($photolistdate));
       $tu = date("m/d/Y", strtotime($lastupdate));
       $pu = date("m/d/Y", strtotime($lastphotodate));
       $pl = $levels[$physical];
       $el = $levels[$emotional];
       $ml = $levels[$mental];
       $ll = $levels[$learning];

       $y = $x+1;

       $token["%SIBDATA$y%"] = "<table border=1 cellspacing=0 cellpadding=4 width=65%>
<tr><th colspan=4>

//THIS IS THE ONLY THING I HAVE ADDED \/\/\/

<a href=display.php?r=$listingnumber> $firstname - $listingnumber</a>

//THIS IS THE ONLY THING I HAVE ADDED /\/\/\

</th></tr>
<tr><td align=center colspan=2 width=50%>$sx</td><td align=center colspan=2 width=50%>$rc</td></tr>
<tr><td align=center colspan=2>$age years old</td><td align=center colspan=2>Waiting Since $ws</td></tr>
<tr><td align=center colspan=2>Story updated $tu</td><td align=center colspan=2>Photo updated $pu</td></tr>
<tr><th colspan=4><font size=2>Impairment Levels</font></th></tr>
<tr><th><font size=2>Physical</font></th><th><font size=2>Emotional</font></th><th><font size=2>Mental</font></th><th><font size=2>Learning</font></th></tr>
<tr><td align=center>$pl</td><td align=center>$el</td><td align=center>$ml</td><td align=center>$ll</td></tr>
</table><br><br>";
   }
}



print qqprints('display.tpl');
print "<br><br>";

if(!empty($wherelit)) {

   $where = stripslashes(urldecode($wherelit));
   $query = "SELECT DISTINCT rootchild FROM children WHERE $where ORDER BY firstname";
   $result = db_query($query,__LINE__ ,__FILE__);
   $number = mysql_numrows($result);

   $lidx = array();
   $i = 0;
   while($i < $number) {
       $lidx[$i] = mysql_result($result,$i);
       $i++;
   }

   $prev = '';
   $next = '';
   for($i=0; $i<count($lidx); $i++) {
       if($lidx[$i] == $lnum) {
           if($i-1 >= 0) { $prev=$lidx[$i-1]; }
           if($i+1 < count($lidx)) { $next = $lidx[$i+1]; }
           break;
       }
   }

   $wlit = urlencode($where);

   $a = $i/$db_paginc;
   $b = (int)$a;
   $beg = $b*$db_paginc;

// print "$i - $a - $b - $beg<br><br>";

   if(!empty($prev)) { print "<a href=display.php?r=$prev&w=$wlit&ttl=$ttllit>Previous</a> | "; }
   print "<a href=dosearch.php?beg=$beg&w=$wlit&ttl=$ttllit>Return to Index</a>";
   if(!empty($next)) { print " | <a href=display.php?r=$next&w=$wlit&ttl=$ttllit>Next</a>"; }
   print "<br><br>";
}



include "includes/foot.html";

?>

 

This is the only line of code that I added to get the page to link to the other profiles:

 

<a href=display.php?r=$listingnumber> $firstname - $listingnumber</a>

 

And of that I only added the:

 

<a href=display.php?r=$listingnumber></a>

 

I'm afraid I had to remove some paths and names do to the nature of the work, but the code hasn't been changed anywhere else.

 

If you need me to supply more information please post and I'll see what I can do. I'm hoping it's just a simple syntax error.

 

Feel free to be brutal, I did not code this (though I am the current owner of it). So you are not going to hurt my feelings  ;D

 

Thank you for any help you can offer.

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.