Chezshire Posted July 18, 2008 Share Posted July 18, 2008 I'm trying the following PHPfreaks tutorial "Multi-column Results (http://www.phpfreaks.com/forums/index.php/topic,95426.0.html)" and i'm getting a "Parse error: parse error, unexpected T_STRING in /home/content/z/a/n/zanland/html/xpg/cerebra/modelNew1.php on line 18" Can anyone help me to understand this and resolve it? Line error #18 if($result && mysql_num_rows($result) > 0) Full code <table cellspacing="3" cellpadding="3"> <?php $sql = "SELECT codename FROM cerebra ORDER BY codename"; $result = mysql_query($sql) or trigger_error(mysql_error,E_USER_ERROR); if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 3; while($row = mysql_fetch_assoc($result)){ //here's the key. Use a while loop to repeat through the code { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; // make sure we have a valid product if($codename != "" && $codename != null) echo "<td>$codename</td>"; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; } ?> </tr> </table> Quote Link to comment Share on other sites More sharing options...
.josh Posted July 18, 2008 Share Posted July 18, 2008 if(mysql_num_rows($result) > 0) Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 18, 2008 Share Posted July 18, 2008 I'm not quite sure how you're getting that error, that shouldn't be caused by that line. I do notice that you've got a stray opening brace here though: while($row = mysql_fetch_assoc($result)){//This one is unclosed. I suspect caused by a copy/paste mistake //here's the key. Use a while loop to repeat through the code { Try: <table cellspacing="3" cellpadding="3"> <?php $query = "SELECT codename FROM cerebra ORDER BY codename"; $result = mysql_query($query) or die("There was a problem with the SQL query: " . mysql_error()); if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 3; while($row = mysql_fetch_array($result)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; // make sure we have a valid product if($codename != "" && $codename != null) echo "<td>$codename</td>"; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; } ?> </tr> </table> Quote Link to comment Share on other sites More sharing options...
.josh Posted July 18, 2008 Share Posted July 18, 2008 hey also you need ()'s after mysql_error $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); Quote Link to comment Share on other sites More sharing options...
Chezshire Posted July 18, 2008 Author Share Posted July 18, 2008 Thank you both for the suggestions, unfortunately i have implimented them (to the best of my understanding) and my attempts are met with the following error: Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/content/z/a/n/zanland/html/xpg/cerebra/modelNew1.php on line 15 Offending line: $query = "SELECT codename FROM cerebra ORDER BY codename"; Full Code: <table cellspacing="3" cellpadding="3"> <?php $query = "SELECT codename FROM cerebra ORDER BY codename"; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 3; while($row = mysql_fetch_array($result)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; // make sure we have a valid product if($codename != "" && $codename != null) echo "<td>$codename</td>"; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; } ?> </tr> </table> <?php include("../mods.php"); include("../footer.php"); ?> Quote Link to comment Share on other sites More sharing options...
.josh Posted July 19, 2008 Share Posted July 19, 2008 How can that be your full code if the error says line 15 and you're saying line 15 is that $query = "..." which is line 3 in your code block? Quote Link to comment Share on other sites More sharing options...
Chezshire Posted July 19, 2008 Author Share Posted July 19, 2008 Hello - I'm loading the area which is conflicting/having problems. This is the very full code block - the first ten lines are the generic Inserts and stuff like that: <?php include("../functions.php"); include("../header.php"); ?> <h1 class='spaceafter'>CHARACTER CREATION - Models Taken</h1> <hr color='#050F1D' size='5'> <table cellspacing="3" cellpadding="3"> <?php $query = "SELECT codename FROM cerebra ORDER BY codename"; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 3; while($row = mysql_fetch_array($result)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; // make sure we have a valid product if($codename != "" && $codename != null) echo "<td>$codename</td>"; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; } ?> </tr> </table> <?php include("../mods.php"); include("../footer.php"); ?> I don't understand why i'm getting this error, as the following code, which is one horribly long column works fine (outside of the images on loading correctly yet) <?php include("../functions.php"); include("../header.php"); ?> <h1 class='spaceafter'>CHARACTER CREATION - Models Taken</h1> <hr color='#050F1D' size='5'> <table width='97%' cellpadding='6' cellspacing='0' cellborder='0'> <TR> <TD align="left"> <?php $sql = "SELECT id, modelname, codename FROM cerebra ORDER BY modelname"; $result = mysql_query($sql) or trigger_error(mysql_error,E_USER_ERROR); while($row = mysql_fetch_assoc($result)){ //here's the key. Use a while loop to repeat through the code echo '<p />'; echo '<p /> <img src="/cerebra/images/'.$char_id.'-.jpg" width="60" height="75" border="0"'.$row['image'].'" '; echo '<br> '.$row['modelname']; echo ' as '.$row['codename']; //these two lines (or any lines up to the closing brace) will be repeated for each row returned by the query } ?> </TD> </TR> </table> <?php include("../mods.php"); include("../footer.php"); Quote Link to comment Share on other sites More sharing options...
.josh Posted July 19, 2008 Share Posted July 19, 2008 I don't really understand why you are getting that error either... I ran the codeblock on my test server and I do not get that error. I mean, I got lots of other errors because I don't have those files to include...maybe there is something in those included files that's breaking it? But you do say that your 2nd code block works just fine...so man, I really don't know... Quote Link to comment Share on other sites More sharing options...
Chezshire Posted July 19, 2008 Author Share Posted July 19, 2008 I tried clearing all the extra/non related data and i still get the same error message -- it's driving me nuts. Quote Link to comment Share on other sites More sharing options...
vikramjeet.singla Posted July 19, 2008 Share Posted July 19, 2008 can you double check your code in "functions.php" and "header.php".... Quote Link to comment Share on other sites More sharing options...
Chezshire Posted July 19, 2008 Author Share Posted July 19, 2008 Thank you for the wonderful suggestion. that is what I am now trying to do, but it is a little beyond me in places i fear, but I'm trying cause that thats how we learn (I keep telling myself that.) I've added the two includes if you or anyone else wants to take a look or borrow code. This is the Header PHP if you care to do a test - it'd be appreciated <?php header("Content-type: text/html; charset=utf-8"); if (!function_exists("microtime_float")) { include("functions.php"); } if (!isset($siteName)) { include("config.php"); } if (!isset($section)) { $section = ""; } if (!isset($hideHeaders)) { $hideHeaders = ""; } $current_time = microtime_float(); $time = microtime_float() - $current_time; echo "\n\n<!-- Time at Line 8: $time seconds -->\n\n"; if ($section == "home") { $pageTitle = "An X-Men Roleplaying PBeM"; } if ($section == "cerebra" && !isset($pageTitle)) { $pageTitle = "Welcome to Cerebra"; } if ($section == "rules" && !isset($pageTitle)) { $pageTitle = "Rules and Policies"; } if ($section && !isset($pageTitle)) { $pageTitle = ucfirst($section); } ?><html> <head> <title><?php echo $siteName . " » " . $pageTitle; ?></title> <link rel="icon" href="/favicon.ico" type="image/x-icon"> <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"> <script src="/js/prototype.js" type="text/javascript"></script> <script src="/js/tooltip-v0.2.js" type="text/javascript"></script> <script src="/js/WordCounter.js" type="text/javascript"></script> <SCRIPT LANGUAGE="JavaScript" type="text/javascript"> <!-- HIDE FROM OLDER BROWSERS // Detect if browser is Netscape 3 + or IE 4 +. bName = navigator.appName; bVer = parseInt(navigator.appVersion); if ((bName == "Netscape" && bVer >= 3) || (bName == "Microsoft Internet Explorer" && bVer >= 4)) { br = "n3"; } else { br = "n2"; } // end if var myGlobalHandlers = { onCreate: function() { Element.show('systemWorking'); }, onComplete: function() { if (Ajax.activeRequestCount == 0) { Element.hide('systemWorking'); } } }; Ajax.Responders.register(myGlobalHandlers); var timer = null; function cb_update(cerebra_target){ if (timer) { var x = clearTimeout(timer); } timer = setTimeout("cerebra_research('" + cerebra_target + "')",500); } // end function cb_update function cerebra_research(cerebra_target) { // an extra line <?php $options = array("cb_status", "cb_approval", "cb_inplay", "cb_keyword", "cb_type", "cb_onlineonly", "cb_affiliation"); FOREACH ($options as $thisOpt) { echo "var $thisOpt = \$F('$thisOpt');\n"; } // end FOREACH ?> if (cb_keyword == 'Enter Keyword') { cb_keyword = ""; } var url = 'http://www.xpg.us/cerebra_records.php?<?php FOREACH ($options as $thisOpt) { echo "$thisOpt='+$thisOpt"; if ($thisOpt != "cb_affiliation") { echo "+'&"; } } // end FOREACH ?>; // an extra line var aj = new Ajax.Updater(cerebra_target, url, { method: 'get' , evalScripts: true }); } // end cerebra research function function populate_thread(thread, expand) { if (expand == true) { var url = 'http://www.xpg.us/thread_show.php?thread='+thread + "&expand=true"; } else { var url = 'http://www.xpg.us/thread_show.php?thread='+thread; } var aj = new Ajax.Updater( {success:'thread_' + thread}, url, { method: 'get', evalScripts: true }); } // end populate thread function function lock_thread(thread) { var url = 'http://www.xpg.us/thread_tools.php?lock='+thread; var aj = new Ajax.Updater( 'lock_' + thread, url, { method: 'get' }); } // end populate thread function function unlock_thread(thread) { var url = 'http://www.xpg.us/thread_tools.php?unlock='+thread; var aj = new Ajax.Updater( 'lock_' + thread, url, { method: 'get' }); } // end populate thread function function delete_thread(thread, title) { input_box=confirm('Really delete thread, "'+ title + '"?\nTHIS ACTION CANNOT BE UNDONE!'); if (input_box==true) { var url = 'http://www.xpg.us/thread_tools.php?delete='+thread; var aj = new Ajax.Updater( 'thread_' + thread, url, { method: 'get' }); } // end if confirmed } // end populate thread function function newImage(arg) { if (document.images) { rslt = new Image(); rslt.src = arg; return rslt; } } // DONE HIDING --> function openimage(imageName,iWidth,iHeight,scrollChoice) { var features = 'width=' + iWidth + ',height=' + iHeight + ',resizable=yes,fullscreen=no,status=no,toolbar=no,scrollbars=' + scrollChoice; var windowName = 'imageView'; if (iWidth==800 && iHeight==625) { windowName = 'floorPlanView'; } pressWin = window.open(imageName,windowName,features); } </SCRIPT> <link href="/style.css" rel="styleSheet" type="text/css"> <style type="text/css"> .nav_top { position:fixed; _position:absolute; top:0; _top:expression(eval(document.body.scrollTop)); left:0; } .nav_bottom { position:fixed; _position:absolute; bottom:0; _top:expression(document.body.scrollTop+document.body.clientHeight-this.clientHeight); } </style> </head> <?php if ($hideHeaders) { echo "<body STYLE=\"background-color: #000000\" text='white' link='#3399FF' vlink='#3399FF' alink='#FFFFFF'"; if (!isset($bodyScript)) { $bodyScript = ""; } if ($bodyScript) { echo " $bodyScript"; } echo ">\n"; } else { echo "<body STYLE=\"background: url('/newnav/sidebar_fill.jpg') repeat-y; background-color: #000000\" text='white' link='#3399FF' vlink='#3399FF' alink='#FFFFFF'"; if (!isset($bodyScript)) { $bodyScript = ""; } if ($bodyScript) { echo " $bodyScript"; } echo ">\n"; echo "<!-- $PHP_SELF -->\n"; if ($PHP_SELF != "/cerebra.php") { ?><div style="display: none; z-index: 1; position: absolute; right: 10px; top: 10px;" id='systemWorking' ><p class='fineprint'><img src='/images/indicator.black.gif' align='middle' ALT=''> Loading...</p></div> <?php } // end if not cerebra ?> <!-- INSERT NAVIGATION --> <?php include("newnav.php"); ?> <!-- END NAVIGATION --> <table cellspacing="0" cellpadding="10" style="border: 2px solid #050F1D" width="100%"><tr><td width='250' HEIGHT='400'></td><td valign="top"> <?php } // end if hiding headers $time = microtime_float() - $current_time; echo "\n\n<!-- TOTAL HEADER TIME: $time seconds -->\n\n"; ?> <!-- BEGIN CONTENT --> Quote Link to comment Share on other sites More sharing options...
Chezshire Posted July 19, 2008 Author Share Posted July 19, 2008 I tried pulling the three column text out and posting it as it's own thing and i still got the same weird error incidentally. I have no clue of what i'm doing - i'm so so so at a loss right now. But this is how we learn (it's becoming my montra). This is the functions php /include: [i]This is the functions PHP if you want to try a test to see if you spot anything [/i][code]<?php include("config.php"); global $siteName; $db = mysql_connect("mysql93.secureserver.net","xpgseattle","mutation1"); mysql_select_db("xpgseattle",$db); // ==================== // MICROTIME FUNCTION // ==================== function microtime_float(){ list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } // end function // this section was supposed to be a new way to track higlighted posts, but I don't know if it's worthwhile anymore $hlThreads = array(); $evThreads = array(); if (isset($_COOKIE["hlPosts"])) { list($hlTimestamp, $hlTemp, $evTemp) = explode("\n",$_COOKIE["hlPosts"]); $hlThreads = explode(",",$hlTemp); $evThreads = explode(",",$evTemp); } // end if highlighted threads cookie is set // =============================================== // =============== Subsection navigation // =============================================== $subSections["institute"] = array("courses" => "Courses", "extracuriculum" => "Extracuriculum", "schoolRules" => "Rules, Policies & Regulations", "schedules" => "Schedules", "squadrons" => "Squadrons"); function showSections($whichSec) { global $subSections; echo "<p>"; $tempy=0; FOREACH ($subSections[$whichSec] as $usePage=>$label) { echo "<a href='$usePage.php'>$label</a>"; $tempy++; if ($tempy < count($subSections[$whichSec])) { echo " • "; } } // end FOREACH echo "</p>\n"; } // end function // =============================================== // =============== subSubsection navigation // =============================================== $subSubSections["institute"] = array("courses" => "Courses", "extracuriculum" => "Extracuriculum", "schoolRules" => "Rules, Policies & Regulations", "schedules" => "Schedules", "squadrons" => "Squadrons"); $subSubSections["squadrons"] = array("squadrons" => "Squadrons", "alpha" => "Alpha", "beta" => "Beta", "delta" => "Delta", "kappa" => "Kappa", "epsilon" => "Epsilon", "omega" => "Omega"); $subSubSections["powers"] = array("detection" => "detection", "energyControl" => "energyControl", "energyEmission" => "energyEmission", "illusion" => "illusion", "lifeformControl" => "lifeformControl", "matterControl" => "matterControl", "matterConversion" => "matterConversion", "matterConversion" => "matterConversion", "mentalEnhancement" => "mentalEnhancement", "physicalEnhancement" => "physicalEnhancement", "powerControl" => "powerControl", "selfAlteration" => "selfAlteration", "travel" => "Travel"); function showSubSections($whichSec) { global $subSubSections; echo "<p>"; $tempy=0; FOREACH ($subSubSections[$whichSec] as $usePage=>$label) { echo "<a href='$usePage.php'>$label</a>"; $tempy++; if ($tempy < count($subSubSections[$whichSec])) { echo " • "; } } // end FOREACH echo "</p>\n"; } // end function // =============================================== // =============== APPROVE VARIABLES // =============================================== function approveVars($vars) { FOREACH ($vars as $thisVar) { global ${$thisVar}; ${$thisVar} = ""; if (isset($_REQUEST[$thisVar])) { ${$thisVar} = $_REQUEST[$thisVar]; } if (isset($_POST[$thisVar])) { ${$thisVar} = $_POST[$thisVar]; } if (${$thisVar} == "undefined") { ${$thisVar} = ""; } if (${$thisVar} == "null") { ${$thisVar} = ""; } } // end FOREACH } // end function // =============================================== // =============== CONVERT HEX COLOR TO RGB // =============================================== function html2rgb($color) { if ($color[0] == '#') { $color = substr($color, 1); } if (strlen($color) == 6) { list($r, $g, $b) = array($color[0].$color[1], $color[2].$color[3], $color[4].$color[5]); } else if (strlen($color) == 3) { list($r, $g, $b) = array($color[0], $color[1], $color[2]); } else { return false; } // end if length $r = hexdec($r); $g = hexdec($g); $b = hexdec($b); return array($r, $g, $b); } // end html2rgb // =============================================== // =============== CHECK FOR HIGHLIGHTED POSTS // =============================================== function checkHL() { global $pref, $login, $dateLimit; global $hlTimestamp, $hlThreads, $evThreads; $charArray = array(); $criteria = ""; $addon = ""; // date limit is how many days to look back to determine if a thread // features your characters. // we'll use a manual datelimit if it's set (so we can see highlighting in chronicles) // but for most purposes, we won't need nearly that much time, and will // set the default to a weeks (If they ain't mentioned you in a week, you ain't in it, honey) if (!isset($dateLimit)) { $dateLimit = 14; } $useLimit = $dateLimit; echo "<!-- Date Limit: $dateLimit -->\n"; // if highlighting is not turned on for this user, or they're not logged in... // return two empty arrays for HL and EV if (!$pref["highlightposts"] || $pref["highlightposts"] == "none" || !$login) { return array(array(), array()); } // end if not logged in or not highlighting // at this point, they're logged in and have some need for highlighting // first, get their list of characters and set up search criteria to find them // in MYSQL tables $theseChars = getAllChars($login); FOREACH ($theseChars as $char) { $criterion = "(featuring REGEXP BINARY '$char')"; array_push($charArray, $criterion); } // end foreach // now we've got our list. If there are any criteria in it, we'll compress it and // prepare it for insertion into an SQL query. $newVars = ", (tags = \"Everyone\") AS evHL"; $criteria = "(tags = \"Everyone\")"; if (count($charArray)) { $newVars = $newVars . ", (" . implode(" OR ", $charArray) . ") AS hl"; $criteria .= " OR " . implode(" OR ", $charArray); } else { $newVars = $newVars . ", 0 AS hl"; } // end if any characters to show $cookieAddon = ""; if ($hlTimestamp) { $cookieAddon = "AND dateadded > $hlTimestamp"; } // this section searches for threads featuring this user's characters and puts them in a list. // it only brings back a list of threads that should be highlighted, which should speed up the // process compared to the old way $hlTemp = "SELECT thread$newVars from board WHERE ($criteria) AND approved <> '' AND approved IS NOT NULL AND TO_DAYS(NOW()) - TO_DAYS(dateadded) <= $useLimit $cookieAddon GROUP BY thread"; echo "\n\n<!-- SQL (highlighting): $hlTemp -->\n\n"; $resultTemp = mysql_query($hlTemp); if (mysql_num_rows($resultTemp)) { // echo "<!--ROWS: " . mysql_num_rows($resultTemp) . " -->\n"; WHILE ($hlCheck = mysql_fetch_assoc($resultTemp)) { $thread = $hlCheck["thread"]; if ($hlCheck["evHL"] && !in_array($thread, $evThreads)) { array_push($evThreads, $thread); } else if ($hlCheck["hl"] && !in_array($thread, $hlThreads)) { array_push($hlThreads, $thread); } // end if any highlighted posts in the last [however many they set] } // end WHILE highlight checking $newTimestamp = date('YmdHis'); $hlTemp = implode(",",$hlThreads); $evTemp = implode(",",$evThreads); $cookieContents = "$newTimestamp\n$hlTemp\n$evTemp"; $duration = 31536000; // one year setcookie ("hlPosts", $cookieContents, time() + $duration, "/",".xpg.us"); // echo "<!-- SET COOKIE: $cookieContents -->\n"; } // end if there were new posts to add to the list return array($hlThreads, $evThreads); } // end function // =============================================== // =============== HIGHLIGHT POST? // =============================================== function hlPost($id) { global $login; global $pref; $charArray = array(); $theseChars = getAllChars($login); FOREACH ($theseChars as $char) { $criterion = "(featuring REGEXP BINARY '$char') OR (tags REGEXP BINARY '$char')"; array_push($charArray, $criterion); } // end foreach // now we've got our list. If there are any criteria in it, we'll compress it and // prepare it for insertion into an SQL query. $newVars = "(tags = \"Everyone\" OR featuring=\"Everyone\") AS evHL"; if (count($charArray)) { $newVars .= ", (" . implode(" OR ", $charArray) . ") AS hl"; } else { $newVars .= ", 0 AS hl"; } // end if any characters to show $hlSQL = "SELECT $newVars from board WHERE id=$id"; echo "<!-- HLSQL: $hlSQL -->\n"; $hlCheck = readDatabase($hlSQL); if ($hlCheck["evHL"]) { return "ev"; } else if ($hlCheck["hl"]) { return "hl"; } else { return ""; } } // end function // =============================================== // =============== READ DATABASE FUNCTION // =============================================== function readDatabase ($queryName) { global $db; $result=mysql_query($queryName, $db) OR error_log("SQL ERROR FROM " . $_SERVER["PHP_SELF"] . ": " . mysql_error() . " -- $queryName", 0); $myrow = mysql_fetch_assoc($result); return $myrow; } // end FUNCTION // =============================================== // =============== SET UP GLOBAL FILE STUFF // =============================================== $basefile = "/home/content/z/a/n/zanland/html/xpg"; $PHP_SELF = $_SERVER["PHP_SELF"]; $thisPage = preg_replace("/^\/+/","",$PHP_SELF); $parsed_URL=explode("/",$thisPage); if (!isset($section)) { $section=""; $subSection=""; $section = preg_replace("/\.php$/","",$parsed_URL[0]); if (isset($parsed_URL[0]) && isset($parsed_URL[1])) { $subSection = preg_replace("/\.php$/","",$parsed_URL[1]); } } // end if no section set manually // =============================================== // =============== CHECK FOR LOGIN STATUS // =============================================== $moderator=""; $login=""; if(!isset($_SERVER["REQUEST_URI"])) { $_SERVER["REQUEST_URI"] = substr($_SERVER["argv"][0], strpos($_SERVER["argv"][0], ';') + 1); } $jumpto=preg_replace("/\&/","^",$_SERVER["REQUEST_URI"]); $jumpto=preg_replace("/\?/","{",$jumpto); $pref=array(); $prefFields = array("startpage", "chronological", "mostrecentfirst", "litegraphics", "highlightposts","autoexpand","postsperpage","primarychar","summarylimit"); FOREACH ($prefFields as $thisField) { $pref[$thisField] = ""; } if (isset($_COOKIE["XPGlogin"])) { list($login, $lastlogin) = explode("|",$_COOKIE["XPGlogin"]); $loginTest = readDatabase("SELECT id,username,name,moderator,prefs from login where id=$login AND lastlogin=$lastlogin"); $moderator = $loginTest["moderator"]; $login = $loginTest["id"]; $prefs = $loginTest["prefs"]; if ($prefs) { $prefs = preg_replace("/\n/","|",$prefs); $myPrefs = explode("|",trim($prefs)); FOREACH ($myPrefs as $field) { $thisPref = explode("^",$field); if (isset($thisPref[1])) { $pref[$thisPref[0]] = trim($thisPref[1]); } } // end FOREACH } // end if prefs } // end if cookie at all! if (isset($restricted)) { if (!$login) { header("location: /login.php?jumpto=$jumpto"); die; } if (!$moderator && $restricted=="admin") { errorPage("Only administrators may access this area of the $siteName site."); } } // end if restricted // keeps track of this user's last visit as a logged-in user of XPG if ($login) { $result=mysql_query("UPDATE login SET lastlogin=lastlogin, lastvisit=\"$rightNow\", lastmodified=lastmodified, dateadded=dateadded where id=\"$login\"",$db); } // end if // =============================================== // =============== TRUNCATE LONG STRINGS // =============================================== function shortenText($text,$limit) { // shortens text to the first space before the length limit if (strlen($text) > $limit) { $tester = ""; $newLimit = $limit; WHILE ($tester != " " && $newLimit > 0) { $tester = substr($text,$newLimit,1); $newLimit = $newLimit-1; } // end WHILE $newLimit=$newLimit+1; if ($tester != " ") { $text = substr($text,0,$limit); } else { $text = substr($text,0,$newLimit); } } // end if too long // too much of a pain in the ass to deal with long HTML tags in the shortened text... $text = preg_replace("/<([bui])>([^<>]+)<\/([bui])>/","[$1]$2[/$3]",$text); $text = preg_replace("/<([bui])>([^<>]+)$/","[$1]$2[/$1]",$text); $text = preg_replace("/<[^<>\r\f\n]+>/","",$text); $text = preg_replace("/\[([bui])\]([^\[\]]+)\[\/([bui])\]/","<$1>$2</$3>",$text); return $text; } // end FUNCTION // =============================================== // =============== REFRESH WHO'S ONLINE // =============================================== function refreshOnline($format) { $onliners = array(); $onlinerAOL = array(); $onlinerYahoo = array(); $filename = '/home/content/z/a/n/zanland/html/xpg/online/onlineList.txt'; $lastMod=""; if (file_exists($filename)) { $lastMod = filemtime($filename); } $rightNow = mktime(); $refreshAlready = ""; $filenameLock = '/home/content/z/a/n/zanland/html/xpg/online/onlineLOCK.txt'; if (file_exists($filenameLock)) { $refreshAlready="true"; } if (isset($_REQUEST["forcerefresh"])) { $forcerefresh=$_REQUEST["forcerefresh"]; } else { $forcerefresh=""; } if ((($rightNow - $lastMod) > 300 || !$lastMod || $forcerefresh) && !$refreshAlready) { $handle = fopen ($filenameLock, "w+"); fwrite($handle, "Refreshing..."); fclose($handle); echo "\n\n<!-- Refreshing online list -->\n\n"; // updates the online list every five minutes $sqlonline = "SELECT login.id,login.username,login.aim,login.yahoo FROM login, cerebra WHERE (cerebra.approved = 'true' AND cerebra.player = login.id) AND (login.yahoo!='' OR login.aim!='') GROUP BY login.id"; $resultonline= mysql_query($sqlonline); WHILE ($player = mysql_fetch_assoc($resultonline)) { $goahead=""; // echo "<!-- CHECKING " . $player["username"] . ": " . date('g:i:s') . " -->\n"; if ($player["yahoo"]) { if (checkOnline("yahoo",$player["yahoo"])) { array_push($onlinerYahoo, $player["id"]); } } if ($player["aim"]) { if (checkOnline("aim",$player["aim"])) { array_push($onlinerAOL, $player["id"]); } } //this compiles the list of online players } // end WHILE if (count($onlinerYahoo)) { $nowYahoo = implode(",", $onlinerYahoo); } else { $nowYahoo=""; } if (count($onlinerAOL)) { $nowAOL = implode(",", $onlinerAOL); } else { $nowAOL=""; } $handle = fopen ($filename, "w+"); fwrite($handle, $nowYahoo . "\n" . $nowAOL); fclose($handle); unlink ($filenameLock); } else { $tempy = file($filename); if ($tempy) { $yahooOnline = $tempy[0]; $aolOnline = $tempy[1]; $onlinerYahoo = explode(",", trim($yahooOnline)); $onlinerAOL = explode(",", trim($aolOnline)); $onliners = array_merge($onlinerYahoo, $onlinerAOL); } // end if list exists } // end if updating the list if ($format != "") { return array($onlinerYahoo, $onlinerAOL); } else { return $onliners; } } // end function // =============================================== // =============== ERROR PAGE FUNCTION // =============================================== function errorPage($errorText) { global $basefile; $pageTitle="Error!"; include ("$basefile/header.php"); ?> <center> <table border="0" cellpadding="0" cellspacing="0" width="60%" height="400"> <tr><td align="center" valign="middle"> <h1>Error!</h2> <p><?php echo $errorText; ?></p></td></tr> </table></center> </form> <?php include ("$basefile/footer.php"); die; } // end function // =============================================== // =============== MESSAGE NOTIFICATION // =============================================== function notify($thread) { global $siteName; $message = readDatabase("SELECT * FROM board WHERE thread=$thread order by dateadded DESC limit 1"); $userid = $message["userid"]; $postId = $message["id"]; $charid = $message["charid"]; $dateadded = $message["dateadded"]; $notifResult= mysql_query("SELECT userid FROM board WHERE thread=$thread AND notification = 'true' AND dateadded < $dateadded AND userid != $userid GROUP BY userid"); $notifList = array(); WHILE ($tempy = mysql_fetch_assoc($notifResult)) { array_push($notifList, $tempy["userid"]); } // end WHILE if (count($notifList)) { // let's not waste our time with the rest if there's nobody to notify $directURL = "http://www.xpg.us/messages/display.php?id=$postId"; $subject = $message["subject"]; $author = getName($message["userid"]); $threadName = getThreadName($thread); if ($charid) { $character = getChar($charid); } else { $character = ""; $subject = "[OOC] $subject"; } FOREACH ($notifList as $thisOne) { $thisUser = readDatabase("SELECT email,username FROM login WHERE id=$thisOne"); $thisMessage = "A new message has been posted to the $siteName website. Thread: $threadName Message Subject: $subject\n"; if ($character) { $thisMessage .= "Character: $character\n"; } $thisMessage .= "Posted by: $author"; $thisMessage .= "\n\n$directURL\n\nVisit the URL above to read the new message."; ini_set("sendmail_from", "xpg_mod <xpg_mod@yahoo.com>"); ini_set("SMTP", "mail.xpg.us"); mail($thisUser["email"], "[$siteName] New Message: \"$subject\"", "$thisMessage", "Return-Path: xpg_mod <xpg_mod@yahoo.com>\nErrors-To: xpg_mod <xpg_mod@yahoo.com>\nFrom: xpg_mod <xpg_mod@yahoo.com>\nReply-To: donotreply@xpg.us\nX-Mailer: PHP/" . phpversion()); $diditwork = mysql_query("UPDATE board SET notification='made', lastmodified=lastmodified WHERE userid=$thisOne AND thread=$thread AND notification='true'"); } // END WHILE Login } // end if there's anyone to notify } // end FUNCTION // =============== REINSTATE NOTIFICATION function reinstateNotification($thread) { global $login; $reinstated="FALSE"; if ($login) { $notifyTest = readDatabase("SELECT id,notification from board WHERE userid=$login AND thread=$thread ORDER BY dateadded DESC LIMIT 1"); if ($notifyTest["notification"]=="made") { $reinstate = mysql_query("UPDATE board set lastmodified=lastmodified, notification=\"true\" where userid=$login AND thread=$thread AND notification=\"made\""); $reinstated="true"; } echo "<!-- Reinstated notification? $reinstated -->\n"; } else { echo "<!-- Reinstated notification? Not Logged in -->\n"; } // end if logged in } // end function // =============================================== // =============== INSERT IMAGE FUNCTION // =============================================== // this function checks an image's size and determines whether // to place a full-size version or one linked with a javascript new window function insertImage($filename, $maxWidth, $maxHeight, $alignment) { global $basefile; // the maximum size for the larger image is: $maxZoom = 1000; $fullpath="$basefile/$filename"; if (file_exists($fullpath)) { $size = getimagesize ("$fullpath"); if ($maxHeight=='square') { $square = "true"; $maxHeight=""; } else { $square = ""; } if (($size[0] <= $maxWidth || !$maxWidth) && ($size[1] <= $maxHeight || !$maxHeight)) { echo "<img src=\"/$filename\" $size[3] border=\"0\""; if ($alignment) { echo " align=\"$alignment\""; } echo ">\n"; } else { if ($maxZoom >= $size[0] && $maxZoom >= $size[1] ) { $zoomHeight = $size[1]+25; $zoomWidth = $size[0]+25; $imgWidth = $size[0]; $imgHeight = $size[1]; } else { if ($size[0] > $size[1]) { // if it's wide $zoomWidth=$maxZoom+25; $zoomHeight= floor($maxZoom * $size[1] / $size[0])+25; } else if ($size[0] < $size[1]) { // if it's tall $zoomHeight = $maxZoom+25; $zoomWidth = floor($maxZoom * $size[0] / $size[1])+25; } else if ($size[0] == $size[1]) { $zoomHeight=$maxZoom+25; $zoomWidth=$maxZoom+25; } // end dimensions for popup $imgWidth = $zoomWidth-25; } // end size check //$zoomHeight= $zoomHeight+25; //$zoomWidth= $zoomWidth+25; if ($maxWidth) { $resizedWidth = $maxWidth; $resizedHeight = floor($maxWidth * $size[1]/$size[0]); } if ($maxHeight) { $resizedHeight = $maxHeight; $resizedWidth = floor($maxHeight * $size[0]/$size[1]); } echo "<a href=\"javascript:openimage('/display.php?width=$imgWidth&img=$filename',$zoomWidth,$zoomHeight,false)\" title=\"Click for a closer look at this image\" onmouseover=\"window.status='Click for a closer look at this image'\">"; if ($square) { echo "<img src=\"/resizer.php?width=$maxWidth&height=square&img=$filename\" width=$resizedWidth height=$resizedWidth border=\"0\""; } else { echo "<img src=\"/resizer.php?width=$maxWidth&height=$maxHeight&img=$filename\" width=$resizedWidth height=$resizedHeight border=\"0\""; } // end if not square if ($alignment) { echo " align=\"$alignment\""; } echo "></a>"; } //end if too big } // end if exists } // end FUNCTION [/code] Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 19, 2008 Share Posted July 19, 2008 I notice that you assign the query to $query, but then execute the query $sql. That would give you an error, but not the same one we had previously. I can only guess that you've not told us the error has changed. If you run just this code and nothing else: <?php $query = "SELECT codename FROM cerebra ORDER BY codename"; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 3; while($row = mysql_fetch_array($result)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; // make sure we have a valid product if($codename != "" && $codename != null) echo "<td>$codename</td>"; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; } ?> Do you still get a syntax error? If you do, I give up. You should get an error - something related to not having a database selected. If you get that error, then try adding in your includes and see whta happens. Quote Link to comment Share on other sites More sharing options...
Chezshire Posted July 19, 2008 Author Share Posted July 19, 2008 Thanks for the comments Ben - I thought that I'd said I was getting a 'error' when trying to apply the three column layout to the page (I stripped out the other elements to concentrate just on getting the three columns -- the idea being to work on one thing at a time). I'm not sure what you mean exactly when you say ' notice that you assign the query to $query, but then execute the query $sql.' but I won't dispute - I'm going to try and google to find an explanation of what your saying here so I can understand more of what your saying which is a little (a lot?) over my head. URL for Test: http://www.xpg.us/cerebra/modelNew1.php I get this error when I run the code as you asked: Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/content/z/a/n/zanland/html/xpg/cerebra/modelNew1.php on line 15 Code Run: <?php $query = "SELECT codename FROM cerebra ORDER BY codename"; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 3; while($row = mysql_fetch_array($result)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; // make sure we have a valid product if($codename != "" && $codename != null) echo "<td>$codename</td>"; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; } ?> Quote Link to comment Share on other sites More sharing options...
.josh Posted July 19, 2008 Share Posted July 19, 2008 Thanks for the comments Ben - I thought that I'd said I was getting a 'error' when trying to apply the three column layout to the page (I stripped out the other elements to concentrate just on getting the three columns -- the idea being to work on one thing at a time). I'm not sure what you mean exactly when you say ' notice that you assign the query to $query, but then execute the query $sql.' but I won't dispute - I'm going to try and google to find an explanation of what your saying here so I can understand more of what your saying which is a little (a lot?) over my head. What he means is that here: $query = "SELECT codename FROM cerebra ORDER BY codename"; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); your query string is assigned to $query but in your mysql_query you use $sql instead of $query. Okay well I ran the latest code block and still no parse error. I got several errors due to no db connection so I added that into it with a test table, and get a completely blank page (no errors). I assume my page is blank due to not having columns in my table called codename or max_columns. My next guess is...maybe you have some data in your vars that is somehow breaking your code, like quote marks? Quote Link to comment Share on other sites More sharing options...
Chezshire Posted July 19, 2008 Author Share Posted July 19, 2008 Thank you GingerBot and Crayon Violent (what a pretty color Even though I am still stumbling I really appreciate your willingness to look at my dumb-assed problem. The code I'm using for the 3 column layout is from a tutorial on PHP freaks. Does it need to be run in php 5.something maybe? I'm using php 4.3 I believe. I adjusted the $query (thanks for the for the further explanation Crayon and thanks GingerBot for the guidance) and I'm still getting the same error on the same line 'Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/content/z/a/n/zanland/html/xpg/cerebra/modelNew3.php on line 2' This is the unchanged code of that line $query = "SELECT id FROM cerebra ORDER BY id"; I also tried this (Changing the double quotes to single quotes) $query = "SELECT id FROM cerebra ORDER BY id"; Here is the current code (using double quote marks as in the first excerpt) <?php $query = "SELECT id FROM cerebra ORDER BY id"; $result = mysql_query($query) or trigger_error(mysql_error(),E_USER_ERROR); if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 3; while($row = mysql_fetch_array($result)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; // make sure we have a valid product if($id != "" && $id != null) echo "<td>$id</td>"; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; } ?> So should i try turning all the quote marks from double to singles, play around with combinations there of, etc? Is that the suggestion Crayon Violent? Also, I don't understand how you would get a different result then I would if you are copying and pasting what I've pasted up. And the final question, i thought that an error message had to do with what is in the code to the point that the error message references, or somewhere before that. Thus my error is contained in one of the two following lines: <?php $query = "SELECT id FROM cerebra ORDER BY id"; demo url here http://www.xpg.us/cerebra/modelNew3.php :'( Quote Link to comment Share on other sites More sharing options...
corbin Posted July 19, 2008 Share Posted July 19, 2008 You haven't been coding in Word, have you? This sounds like a case of evil-fancy-quotes. Quote Link to comment Share on other sites More sharing options...
Chezshire Posted July 19, 2008 Author Share Posted July 19, 2008 Hello Corbin, Thank you for your question, it's very intelligent, and I know this because my freind Zan who is a PHP developer and lets me use his server to play on as I work to understanding PHP explained at long an tedious length why i should never use word. And i work on a mac so i use 'TextEdit' for word processing because it loads in a flash. I use TextWrangler to do my php and html. But I'm planning to get BBedit (this weekend probably) to do my coding since it is becoming a burning passion (along with posing simple problem to PHPfreaks that should be solveable but for some unknown reason aren't it seems b Joking aside, I checked to make sure i didn't have any sort of smart quotes going on, and i do not (I work as a graphic designer/illustrator and since a good friend of my explained to me at length why you never use 'smart quotes' which are the curly quotes, I don't. But i did check and i don't seem to have any hidden characters -- which doesn't mean that I don't have any, only that i can't find them. Could someone who says they've gotten the above code to work please post the code, from the server/php that they got to run her so i can try that? I promise i will do a straight cut and paste. Thanks so much as always. Thank you! Also - IF i want to put a reference link to this site to promote it, who do i ask for permission to do as such? Is that ok to do? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 19, 2008 Share Posted July 19, 2008 Ok, so I've run the code above with only two modifications - an included database connection and an echo of a table tag. Giving code: <?php include('test_db_connection.php'); $query = "SELECT id FROM cerebra ORDER BY id"; $result = mysql_query($query) or trigger_error(mysql_error(),E_USER_ERROR); echo '<table>'; if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 3; while($row = mysql_fetch_array($result)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; // make sure we have a valid product if($id != "" && $id != null) echo "<td>$id</td>"; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; } ?> Using the structure: CREATE TABLE `cerebra` ( `id` int(2) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Dumping data for table `cerebra` -- INSERT INTO `cerebra` (`id`) VALUES (1), (2), (3), (4), (5), (6), (7), (, (9), (10); I receive the expected 3 column table layout. E.G. No errors. I can't see anything version specific in the above code. Quote Link to comment Share on other sites More sharing options...
Chezshire Posted July 19, 2008 Author Share Posted July 19, 2008 Thanks G-Bot I looked at my database and my ID is set up as follows: `id` int` 6` Not null` IS the problem that my table has the id set as an INT? And that my length/values is set to 6? Could this be because i've set my database up wacky without knowing it? Quote Link to comment Share on other sites More sharing options...
Chezshire Posted July 19, 2008 Author Share Posted July 19, 2008 I just noticed this at the top of my database ( i really am new to all of this stuff - but i'm having fun... frustratred fun) it says 'QL query: ALTER TABLE `cerebra` CHANGE `id` `id` INT( 6 ) NOT NULL AUTO_INCREMENT' So thats how i have that row of the table set up which is a little different then what you did. Could that be the cause? Quote Link to comment Share on other sites More sharing options...
.josh Posted July 19, 2008 Share Posted July 19, 2008 No the problem is PHP is trying to parse your actual script and somewhere along the lines an unexpected thing happened that has to do with your actual syntax. Examples are missing quotes, extra quotes, missing or extra ;'s missing/extra opening or closing tags extra/missing opening/closing brackets. Extra/missing opening/closing ()'s or []'s or {}'s. Double typed or missing operands, commas, missing arguments for functions. Think of parse errors as the grammar police of PHP. There's something wrong with your code's grammar. Now these code chunks seem to work for all of us so there's got to be something specific to you that's doing it. That's why I mentioned your database data (because we don't have that). Or perhaps this file is being included in another file? It's got to be something specific to your situation that we can't duplicate. Quote Link to comment Share on other sites More sharing options...
Chezshire Posted July 19, 2008 Author Share Posted July 19, 2008 No the problem is PHP is trying to parse your actual script and somewhere along the lines an unexpected thing happened that has to do with your actual syntax. Examples are missing quotes, extra quotes, missing or extra ;'s missing/extra opening or closing tags extra/missing opening/closing brackets. Extra/missing opening/closing ()'s or []'s or {}'s. Double typed or missing operands, commas, missing arguments for functions. Think of parse errors as the grammar police of PHP. There's something wrong with your code's grammar. Now these code chunks seem to work for all of us so there's got to be something specific to you that's doing it. That's why I mentioned your database data (because we don't have that). Or perhaps this file is being included in another file? It's got to be something specific to your situation that we can't duplicate. So not to sound dumb, and i know this will sound dumb so I apologize but uhm... what does 'parse' mean in this context? Does it mean to execute? And if it means 'to execute' why not say 'execute' instead of 'parse' which seems like a very obscure term (to me - no offense but i often glitch on things when i can't understand some obscure phrase of language) thansk for the explanations and i'm working on it and I am also very very very thankful for all of your help, and explanations - this is very fascinating to me. I don't watch tv anymore - i watch code - i'm a code-potato now. Unfortunately i'm a very 'mashed' code potato it seems (laughs) Quote Link to comment Share on other sites More sharing options...
.josh Posted July 20, 2008 Share Posted July 20, 2008 Most people use "parse" and "execute" interchangeably (including myself, most of the time). But technically they are not the same thing. Parsing is a "phase" or "part" of the execution process. It is the act of breaking down the code into its blocks, expressions, etc.. so when you see a "parse" error, that means that during the part of execution when PHP is trying to parse the script, it runs into an error. Quote Link to comment Share on other sites More sharing options...
Chezshire Posted July 20, 2008 Author Share Posted July 20, 2008 Hi -- I know this is silly, but if any of you still have the file up on a server from when you did your tests, could i get the url to look at or the actual PHP test that you did (e-mailed would be cool) so i can look at somethings. A friend suggested that i might not be saving the file correctly and that would explain the reason for the code not working. He told me i needed to save it as a unix abom something and I'm exploring that now - but it'd be nice to see how it works on another server if it's up. Thank you once again! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.