jcbones
Staff Alumni-
Posts
2,653 -
Joined
-
Last visited
-
Days Won
8
Everything posted by jcbones
-
I think you are over analyzing this. $_SESSION is an array .PERIOD(.) It is treated just like any other array. $myarray['hosts'][0][0] = 'hosta'; //is equal to: $_SESSION['hosts'][0][0] = 'hosta'; The only difference is, the first array is only valid in the runtime, and the second is stored on the server to be accessed later.
-
Did you try my query posted above? REPLACE the SQL variable in your last script you posted with this one. $sql = "SELECT a.username,a.comment,b.id,c.avatar FROM (user_comments as a JOIN accounts as c USING(username)) JOIN `user_friends_list` as b ON (b.friend = a.username) WHERE (b.username = '$username' $friend AND b.status = 1) ORDER BY a.id DESC"; It has been tested (with the data you provided in your dump), and it does work. It returns the right avatar, for the right username on the right comment.
-
So does your competitors account id follow them through all of the tables?
-
A viable option, if the OP is using linux. This would make all of the users get gold at the same time. Then all you need to do is pass the database timestamp to a countdown script, and echo the gold out.
-
This should get you started, be aware, I know it doesn't function 100% correctly. <<This is where you come into play. Consider it a simple tutorial, much more needs to be considered before the final implementation. <?php session_start(); $timestamp = time(); $time = 120; //120 seconds in 2 minutes. $collectGold = 10; //10 pieces of gold every 2 minutes. $gold = (isset($_SESSION['gold'])) ? $_SESSION['gold'] : 10; //If the gold session is set, collect it, otherwise set the starting value of gold. if(isset($_SESSION['ts'])) { //if timestamp is in the session. $slice = ($timestamp - $_SESSION['ts']); //timestamp minus the last page refresh. //Need to work on the following two lines to get the Gold to figure right. $gold += ($slice > $time) ?(int)($collectGold * ($slice / $time)) : 0; //if the timer runs out, increment gold based on a calculation(in case the timer has been out more than 2 minutes). $gold = floor($gold / 10) * 10; //clean up the gold, rounding down to the nearest ten if necessary. $diff = $time - $slice; //get our time difference. } if(!isset($_SESSION['ts']) || $diff > $time || $diff < 0) { //if the timestamp is NOT in session, or the difference is greater than the max timer amount, reset the timer, and the timestamp into the session. $diff = $time; $_SESSION['ts'] = $timestamp; } $_SESSION['gold'] = $gold; //collect the gold to the session. //Below is demonstration of output. Seconds could be passed to Javascript. $diff; //$diff holds seconds less than 3600 (1 hour); $hours = floor($diff / 3600) . ' : '; $diff = $diff % 3600; $minutes = floor($diff / 60) . ' : '; $diff = $diff % 60; $seconds = $diff; ?> <div id="strclock">Clock Here!</div> <div id="gold">Your current inventory is: <?php echo $gold; ?> pieces of Gold!</div> <script type="text/javascript"> var hour = <?php echo floor($hours); ?>; var min = <?php echo floor($minutes); ?>; var sec = <?php echo floor($seconds); ?> function countdown() { if(sec <= 0 && min > 0) { sec = 59; min -= 1; } else if(min <= 0 && sec <= 0) { min = 0; sec = 0; } else { sec -= 1; } if(min <= 0 && hour > 0) { min = 59; hour -= 1; } if(hour == 0 && min == 0 && sec == 0) { document.getElementById('strclock').innerHTML = 'You have more Gold, refresh to collect.'; } else { var pat = /^[0-9]{1}$/; sec = (pat.test(sec) == true) ? '0'+sec : sec; min = (pat.test(min) == true) ? '0'+min : min; hour = (pat.test(hour) == true) ? '0'+hour : hour; document.getElementById('strclock').innerHTML = hour+":"+min+":"+sec; } setTimeout("countdown()",1000); } countdown(); </script>
-
For simplicities sake, I think you should use the simpleImage class. if( isset($_POST['submit']) ) { include('SimpleImage.php'); $image = new SimpleImage(); $image->load($_FILES['uploaded_image']['tmp_name']); $image->resize(150,150); $image->save($filename); }
-
This would work better if you used ID's to make the table connections. Since you are using Username as the connection, you need to do two things. 1. Make sure all of the Collations are the same. 2. Make sure all of the spellings are the same (including case, Even though the collation may be case insensitive, it still will not work if the case is different). <<<Dunno why, had me stumped for a few minutes. $sql = "SELECT a.username,a.comment,b.id,c.avatar FROM (user_comments as a JOIN accounts as c USING(username)) JOIN `user_friends_list` as b ON (b.friend = a.username) WHERE (b.username = '$username' $friend AND b.status = 1) ORDER BY a.id DESC"; Edit: If you want to group the messages by author, change the ORDER BY clause to "b.id".
-
I would use move_uploaded_file(). But the answer to your question is: $path1= "images/posters/blue.jpg"; $path2= "images/posters/tree.jpg"; $path3= "images/posters/sky.jpg";
-
Transferring data from one table to another? *EDITED*
jcbones replied to Far Cry's topic in PHP Coding Help
You want to transfer all of the users Id's $sql = "INSERT INTO Status(id) SELECT id FROM users"; -
Try this as a TEST. <?php include "connect.php"; $username = mysql_real_escape_string($_GET['username']); //If friend is set, then query for it, otherwise return all of the friends comments. $friend = (isset($_GET['friend'])) ? ' AND b.friend = \'' . mysql_real_escape_string($_GET['friend']) . '\' ' : NULL; $sql = "SELECT a.username,a.comment,b.friend FROM user_comments as a,`user_friends_list` as b WHERE (a.username = b.friend AND b.status = '1') AND (b.username = '$username' $friend) ORDER BY a.id DESC"; $result = mysql_query($sql); $user_xml = "<?xml version=\"1.0\"?>\n"; $user_xml .= "<myroots>\n"; $user_xml .= "<profileinfo>\n"; if(mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { $user_xml .= "<username>" . $row['username'] . "</username>\n"; $user_xml .= "<comments>" . $row['comment'] . "</comments>\n"; } } $user_xml .= "</profileinfo>\n"; $user_xml .= "</myroots>\n"; echo $user_xml; ?>
-
Post your table structures, and we can get it sorted.
-
Try this: <?phpsession_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'myusername'); define('DB_PASSWORD', 'mypassword'); define('DB_DATABASE', 'mydatabasename'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $login = clean($_GET['login']); $password = clean($_GET['password']); if($login == '') { $errmsg_arr[] = 'Login ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'PS ID missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $qry="SELECT members FROM members WHERE login='$login' AND passwd='$password'"; $result=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error());if(mysql_num_rows($result) > 0) {$row = mysql_fetch_row($result); echo $row[0]; }else {echo 'Username and/or Password not found.';}}?>
-
You need to make sure both the login and password are set in the URL(address bar). Perhaps you are sending them using POST and not GET.
-
How are you getting: $nickname, $height, $weight,$hometown?
-
Post your database table structures for those two tables. I'll get the query sorted out, and re-write the getBio function for you.
-
Is the table headers printing?
-
Anyway you want it. Couple with this which understands these formats echo date('Y-m-d',strtotime('30.12.2010'));
-
Well, javascript would make it not work that way. That is the plain HTML way of doing it. I would try it using the onSubmit event handler (or onBlur), and getting the value of the input field correctly. You are trying to get the input value by searching the options of a dropdown box. Or just post it in the javascript section, they may be more helpful.
-
Make sure there is no whitespace before the opening PHP tag (<?php) in LOGINS.php
-
<form name='form' action='' method='get'><input type='text' class='input_text' id='#{id}_input' size='8' name='page' value='' /> <input type='submit' value='Go' name='submit' class='input_submit add_folder' id='#{id}_submit'/></form>
-
getting error when inserting field with (')
jcbones replied to flemingmike's topic in PHP Coding Help
To a database? mysql_real_escape_string() -
OK, all looks like it is on the right track. 1. remove ".php" from all the links in the getBioMenu() function. 2. All variables that are in functions, must have them passed to the function through an argument, by declaring them inside the function, or by declaring them global, http://www.php.net/manual/en/language.functions.php 3. Alot of the functions have only one argument, yet you are passing them two arguments. At this point, I think your page is OK, you need to work on the functions. Or, you could just pass the variable $row as an argument to getBio() as it contains the data from the user you are looking at currently. If you set your query as: $query = "SELECT * FROM `efed_bio` AS bio WHERE bio.username = '$username'"; Then you will get everything from that user, putting it to the functions as the full array($row), you can extract it inside the function, and have all of your variables that you need to work with. EX: function getBio($arr) { echo 'My style is ' . $arr['style']; //or extract($arr); echo 'My style is ' . $style; } //calling the function: getBio($row); I hope that makes sense to you.
-
You are missing a bunch of functions that you are calling. You need to make sure that function list has a path to your script (with includes). Everything seems to be working up to a point. The getBioMenu function is still a little hosed, as it isn't accepting the username, and the path is a little off(as your site is using mod_rewrite). function getBioMenu($siteurl,$username) { ?> <div class="mwtabsdiv"> <a href="<? echo $siteurl; ?>/bio?username=<? echo $username; ?>" class="mwtabslink">Biography</a> <a href="<? echo $siteurl; ?>/bio?page=gallery&username=<? echo $username; ?>/gallery" class="mwtabslink">Gallery</a> <a href="<? echo $siteurl; ?>/bio?page=news&username=<? echo $username; ?>/news" class="mwtabslink">News</a> <a href="<? echo $siteurl; ?>/bio?page=segments&username=<? echo $username; ?>/segments" class="mwtabslink">Segments</a> <a href="<? echo $siteurl; ?>/bio?page=matches&username=<? echo $username; ?>/matches" class="mwtabslink">Matches</a> <a href="<? echo $siteurl; ?>/bio?page=chronology&username=<? echo $username; ?>/chronology" class="mwtabslink">Chronology</a> </div> <? } Your main script should look something like: <?php $page = (isset($_GET['page'])) ? strip_tags($_GET['page']) : NULL; if(isset($_GET['username']) && $_GET['username'] != '') { $username = mysql_real_escape_string($_GET['username']); $query = "SELECT username, charactername, id, style_id AS style FROM `efed_bio` WHERE bio.username = '$username'"; $result = mysql_query($query); if(mysql_num_rows($result) > 0) { $row = mysql_fetch_assoc($result); $row = array_map('cleanquerydata',$row); extract($row,EXTR_SKIP); } } ?> <h1><?php echo $charactername; ?>'s Biography</h1> <?php echo getBioMenu('http://kansasoutlawwrestling.com',$username); //***NOTE***Make sure the functions below Exist in the scope of this script: //If the GET page variable is biography, display the biography page switch($page) { case 'biography': echo getBiopgrahy($style,$id); break; case 'gallery': echo getGallery($style,$id); break; case 'news': echo getNews($$id); break; case 'segments': echo getBioSegments($id,S); break; case 'matches': echo getBioSegments($id,M); break; case 'chronology': echo getChronology($id); break; default: echo getBio($style,$id); } ?>
-
I noticed this: So you need to define a page in your URL. Your function getBioMenu should look something like: function getBioMenu($siteurl,$username) { ?> <div class="mwtabsdiv"> <a href="<? echo $siteurl; ?>/bio.php?username=<? echo $username; ?>" class="mwtabslink">Biography</a> <a href="<? echo $siteurl; ?>/bio.php?page=gallery&username=<? echo $username; ?>/gallery" class="mwtabslink">Gallery</a> <a href="<? echo $siteurl; ?>/bio.php?page=news&username=<? echo $username; ?>/news" class="mwtabslink">News</a> <a href="<? echo $siteurl; ?>/bio.php?page=segments&username=<? echo $username; ?>/segments" class="mwtabslink">Segments</a> <a href="<? echo $siteurl; ?>/bio.php?page=matches&username=<? echo $username; ?>/matches" class="mwtabslink">Matches</a> <a href="<? echo $siteurl; ?>/bio.php?page=chronology&username=<? echo $username; ?>/chronology" class="mwtabslink">Chronology</a> </div> <? } Then change: <?php echo getBioMenu($style,$username); ?> //To: <?php echo getBioMenu('http://kansasoutlawwrestling.com',$username); ?> Then at the top of the page, put this line of code: $page = (isset($_GET['page'])) ? strip_tags($_GET['page']) : NULL; After all of that, check to make sure your getHistory() function is available to the script. As a last measure to help insure database integrity. $username = $_GET['username']; //Should be: $username = mysql_real_escape_string($_GET['username']);
-
sorry screwed up, typing fast. bio.username = '$username' should be username = '$username' (remove the bio. )