Jump to content

djfox

Members
  • Posts

    327
  • Joined

  • Last visited

    Never

Everything posted by djfox

  1. Ok, so I now have: <?php $query = "SELECT AVG(views) AS avg_views FROM image WHERE gallNum='$g'"; $result = mysql_query($query) or die(mysql_error()); mysql_fetch_assoc($result); echo "The average views is ".$result['avg_views']; ?> But the result is still blank.
  2. Ok, I gave it go according to what http://www.tizag.com/mysqlTutorial/mysqlavg.php showed. So I entered this: <?php $query = "SELECT gallNum, AVG(views) FROM image WHERE gallNum='$g' GROUP BY gallNum"; $result = mysql_query($query) or die(mysql_error()); echo "The average views is ".$row['AVG(views)']; ?> I get a blank as a result.
  3. What I want to do is have the code add up all the entries in the database and find the average from a field. Ie, the field name "views" in the table "submissions" and the entries in that field in that table are 234, 365, 264, 646, 354. Add up all of those and get the average number, which in this case is 373 (with the number rounded up to a whole number). I can do the rounding of the number up but I`m not sure how to tell the code to add up all of those numbers from a certain field in the database table.
  4. I would like a pop-up box to appear before the page is loaded and have two buttons on it. If the user clicks "yes", the page will load like normal. If they click "no", they should be redirected to the page they were on previously. How would I accomplish this? Or even if someone knows what this kind of code is called and could tell me, I could probably do some searching for it.
  5. I have this currently: mysql_query("UPDATE userdata SET regions_loc='$loc', regions_url='$url', regid='$regid' WHERE id='$logged'")or die ( mysql_error()); Are there ways to customize the error message that would print out?
  6. I replied before the edit. Ok, thanks, I`ll give it a try.
  7. It doesn`t work that way for this, I already tried.
  8. Here`s my code: <?php $res = mysql_query("SELECT bought FROM userdata WHERE id='$logged'"); $a = mysql_fetch_row($res); $it = explode(",", $a[0]); foreach ($it as $th) { $res2 = mysql_query("SELECT id, shortname, type, name, cost FROM clothing WHERE id='$th'"); $b = mysql_fetch_row($res2); mysql_free_result($res2); echo "$b[3] <br>"; } ?> I want the end results to be listed in the order of the id numbers (listed in both as $b[0] and $th). How do I tell my code to list the results in numerical order?
  9. Ok, thanks for the suggestions, guys. ^^
  10. I know how to do greater than, less than, and equal to with if () But what about something like "if $wt[2] can be found in the string of values entered in $pa[2]"? Example: Let`s say $pa[2] is "Normal" And let`s say $wt[2] is "Normal,Ice,Rock,Steel" How could I get if () to look for $pa[2] in $wt[2] ?
  11. I want my code to run a check to be sure that the entered fields are not the exact same (using numbers). What is the symbol for "not equal to"?
  12. Never mind, I think I got it.
  13. If you LIMIT 50, you can`t "browse" through the list then, can you? In your code, I see no way for a viewer to "browse" through the list. Btw, your code gave an error message.
  14. To see the page this is being done to: http://secrettrance.net/mlpcollection_main.php?g=97&sort=newest My first post: This copied and pasted code from another file works on the other file.
  15. For whatever reason, it seems as though my code can`t count. I`ve set the offset to be at 50, and it is displaying every single item from the table rather than just the 50. I`ve copied and pasted the code form another file which uses the same system and works successfully, but it still seems to have trouble counting on this file I`m trying to get this to work for. <a href="mlpcollection_main.php?g=<? echo "$g"; ?>&sort=newest">Newest</a> | <a href="mlpcollection_main.php?g=<? echo "$g"; ?>&sort=alpha">Alphabetical</a> <p> <?php if (isset($_GET['sort']) && $_GET['sort'] == "newest") { if(!$offset) $offset=0; $recent = 0; $res = mysql_query("SELECT id, image, date, date2, name, descr, type, gen, cond, owner FROM ponycol WHERE owner='$g' ORDER BY id DESC")or die( mysql_error() ); while( $row = mysql_fetch_row($res) ){ if( $recent >= $offset && $recent < ($offset + 50 )){ echo "<a href='mlpcollection.php?id=$row[0]'>$row[4]</a><br>"; } } $recent = $recent + 1; } ?> <p> <table border=0 width=100%> <tr> <td><?php if ($offset >= 50) { ?><b><a href="mlpcollection_main.php?g=<? echo $g ?>&sort=<? echo "$sort"; ?>&offset=<? echo $offset - 50 ?>"><img src="<? echo $butprev ?>" border=0></a></b> <?php } ?> <td><div align=right> <b><a href="mlpcollection_main.php?g=<? echo $g ?>&sort=<? echo "$sort"; ?>&offset=<? echo $offset + 50 ?>"><img src="<? echo $butnext ?>" border=0></a></b> </div> </table> The Next/Previous counts show up properly, they add/subtract the correct number from the correct field. Break-down: Instead of showing just 50 items, it shows every single item in the table.
  16. Each item in the drop down menu needs to have different colours. This person I`m building a mini site for does not know html colour codes, so I want the colours to be visible in a drop down menu so that he can change the colours of his font to whatever he wants. But he needs to see what the colours are.
  17. I figured it had something to do with php. I did look on their site and they only give basic "Put the link here for the page you want PayPal to redirect people to" which doesn`t do anything for the specifics.
  18. We`ve all seen them - the sites that allow you to use PayPal to pay for your subscription to a website and it`s all done instantly. But how? How would my site know that the payment was successfully sent through PayPal and for how many months was paid for?
  19. They are logged out randomly. Stupid me forgot to post the code: <?php // Defines DEFINE('SESSION_MAGIC','sadhjasklsad2342'); // Initialization @session_start(); @ob_start(); /* Redirects to another page */ function Redirect($to) { @session_write_close(); @ob_end_clean(); @header("Location: $to"); } /* Deletes existing session */ function RemoveSession() { $_SESSION = array(); if (isset($_COOKIE[session_name()])) { @setcookie(session_name(), '', time()+(60*60*24*365), '/'); } } /* Checks if user is logged in */ function isLoggedIn() { return(isset($_SESSION['magic']) && ($_SESSION['magic']==SESSION_MAGIC)); } /* read message count */ function CountMessages($id) { if ($res=mysql_query("SELECT * FROM messagedata WHERE recBoxID=$id AND isNew=1")) { $count=mysql_num_rows($res); mysql_free_result($res); return($count); } return 0; } /* Go login go! */ function Login($username,$password) { global $nmsg, $rows; $ok=false; if ($res=mysql_query("SELECT id,level,mailNum, echo_count, status, isHold, guildLim, adult, battle, showtime FROM userdata WHERE login='$username' AND password='$password'")) { if ($rows=mysql_fetch_row($res)) { $_SESSION['sess_name'] = $username; $_SESSION['pass'] = $password; $_SESSION['gal'] = $rows[0]; $_SESSION['mail'] = $rows[2]; $_SESSION['level2'] = $rows[1]; $_SESSION['echos'] = $rows[3]; $_SESSION['status'] = $rows[4]; $_SESSION['suspend'] = $rows[5]; $_SESSION['guildnum'] = $rows[6]; $_SESSION['adult'] = $rows[7]; $_SESSION['bat2'] = $rows[8]; $_SESSION['tim'] = $rows[9]; $_SESSION['magic'] = SESSION_MAGIC; $nmsg = CountMessages($rows[0]); $ok=true; } else { include('login_failed.php'); } mysql_free_result($res); } return($ok); } /* Terminates an existing session */ function Logout() { @RemoveSession(); @session_destroy(); } /* Escape array using mysql */ function Escape(&$arr) { if (Count($arr)>0) { foreach($arr as $k => $v) { if (is_array($v)) { Escape($arr[$k]); } else { if (function_exists('get_magic_quotes')) { if(!get_magic_quotes_gpc()) { $arr[$k] = stripslashes($v); } } $arr[$k] = mysql_real_escape_string($v); } } } } // ----------------------------------------------- // Main // ----------------------------------------------- Escape($_POST); Escape($_GET); Escape($_COOKIE); Escape($_REQUEST); Escape($_GLOBALS); Escape($_SERVER); ?> Note: For those who don`t already know, this was made by the first programmer who worked on my site years back. I have lost contact with the person long ago.
  20. Not loading any of the pages on the site (visiting).
  21. I have set for my login to last a long time but it seems like my coding doesn`t matter to the system. The time the site allows for the person to be logged in before unlogging them varies greatly. Examples of the most extremes: Sometimes, no matter how active I am, it`ll kick me off after 15 minutes. Other times, after shutting down my computer and then start it back up the next day, I`m still logged in. What would cause it to be so unstable like that?
  22. Wow, that takes care of it as well? I will have to build a shrine to you now.
  23. It IS a good thing. I certainly would have never figured this out. Thanks much for having patience with me and sticking with this to help me out!
×
×
  • 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.