Jump to content

XenoPhage

Members
  • Posts

    99
  • Joined

  • Last visited

    Never

Everything posted by XenoPhage

  1. [!--quoteo(post=352303:date=Mar 6 2006, 06:10 PM:name=Buyocat)--][div class=\'quotetop\']QUOTE(Buyocat @ Mar 6 2006, 06:10 PM) [snapback]352303[/snapback][/div][div class=\'quotemain\'][!--quotec--] Ken, that's strange because I was justing using something and had to strip slash it in order to get rid of the slashes... wonder what is different between our systems. [/quote] Check get_magic_quotes_gpc() ... It may be on for you, but off for Masna.. That would explain it. :)
  2. [!--quoteo(post=352366:date=Mar 6 2006, 10:02 PM:name=tonbah)--][div class=\'quotetop\']QUOTE(tonbah @ Mar 6 2006, 10:02 PM) [snapback]352366[/snapback][/div][div class=\'quotemain\'][!--quotec--] I have two tables scores and users the scores table has coulmns of auto_id, ID, First name, last name, date, course, rating, slope, score, and diff the users table has columns of ID, First Name, Last name, username, password, avg_diff, and handicp Each row in the scores table represnts one round by a player [/quote] Hrm.. the design sounds fairly solid. Although, I'd remove the first name and last name from the scores table as it's a duplication of data. If you need the name, just do a join when you select the data... Something like this : SELECT u.firstname, u.lastname, s.date, s.score FROM scores AS s LEFT JOIN users AS u ON u.ID=s.ID; Anyways, with the exception of that, the database looks pretty good. Give the dual SQL calls a shot and see if it's too slow. If it is, then you at least have something to start with, and you can make it better from there.. :)
  3. [!--quoteo(post=352284:date=Mar 6 2006, 05:22 PM:name=php_b34st)--][div class=\'quotetop\']QUOTE(php_b34st @ Mar 6 2006, 05:22 PM) [snapback]352284[/snapback][/div][div class=\'quotemain\'][!--quotec--] You could either enable mysqli() in your php.ini (it is disabled by default) by removing the colon in front if it. or try connecting using the method i posted earlier. [/quote] Make sure you restart apache after editing php.ini... (assuming you're using apache)
  4. [!--quoteo(post=352276:date=Mar 6 2006, 05:17 PM:name=tonbah)--][div class=\'quotetop\']QUOTE(tonbah @ Mar 6 2006, 05:17 PM) [snapback]352276[/snapback][/div][div class=\'quotemain\'][!--quotec--] Is there anyway to store the avg_diff and do both of these at the same time? or do I need to run one and then run the other for each user? [/quote] You might be able to do it with subselects, but I'm not positive. And for subselects you'll need at least MySQL 4.1... It's not that slow, so putting it in 2 queries shouldn't hurt much..
  5. [!--quoteo(post=352271:date=Mar 6 2006, 05:13 PM:name=ibda12u)--][div class=\'quotetop\']QUOTE(ibda12u @ Mar 6 2006, 05:13 PM) [snapback]352271[/snapback][/div][div class=\'quotemain\'][!--quotec--] I think that's the direction I'm looking for. I'm not super strong with explode and in_array yet (something to read up on. But I guess I'd like my code to at all the numbers in the array, and then allow access based on that. Ex. suppose a page has an access lvl requiring 12. My user has a 1,12,34 all in his level field. So I could explode that data into an array. Then have my access script check to see if 12 is in the array? [/quote] That would work.. Of course, you lose some SQL functionality this way as the database will have no idea that there are multiple values in that column. The proper "SQL way" to do this is to create an additional table with the mappings.
  6. [!--quoteo(post=352270:date=Mar 6 2006, 05:12 PM:name=PcGamerz13)--][div class=\'quotetop\']QUOTE(PcGamerz13 @ Mar 6 2006, 05:12 PM) [snapback]352270[/snapback][/div][div class=\'quotemain\'][!--quotec--] $row[2] won't word wrap in $Message = wordwrap($row[2], 25, "<br />\n"); it shows my mail just got word wrapped [/quote] I'm not sure I understand.. If you look at the raw output from the program, are there <br /> tags where $row[2] is displayed? ie, is it just not displaying it in the browser?
  7. [!--quoteo(post=352267:date=Mar 6 2006, 05:09 PM:name=ADRlAN)--][div class=\'quotetop\']QUOTE(ADRlAN @ Mar 6 2006, 05:09 PM) [snapback]352267[/snapback][/div][div class=\'quotemain\'][!--quotec--] I removed the @ and i run the script and i get this error : Fatal error: Cannot instantiate non-existent class: mysqli in /home/content/n/o/l/nolimit3/html/register.php on line 16 on line 16 is $db=new mysqli('host,'championships','passwd','championships'); it stucks here.if i echoed anything after it still dosen`t show. [/quote] Do you have PHP 5 ? Sounds like whatever version you do have doesn't support mysqli() ...
  8. [!--quoteo(post=352261:date=Mar 6 2006, 05:02 PM:name=tonbah)--][div class=\'quotetop\']QUOTE(tonbah @ Mar 6 2006, 05:02 PM) [snapback]352261[/snapback][/div][div class=\'quotemain\'][!--quotec--] UPDATE users SET avg_diff = AVG(diff) WHERE ID =123456 MySQL said: #1111 - Invalid use of group function [/quote] Yep, AVG() needs a GROUP BY ... Try this : [code] SELECT AVG(diff) FROM users WHERE ID=123456 GROUP BY ID; and then UPDATE users SET avg_diff = <answer from above> WHERE ID=123456; [/code]
  9. [!--quoteo(post=352257:date=Mar 6 2006, 05:01 PM:name=ADRlAN)--][div class=\'quotetop\']QUOTE(ADRlAN @ Mar 6 2006, 05:01 PM) [snapback]352257[/snapback][/div][div class=\'quotemain\'][!--quotec--] still i don`t get anything,no success nor nothing.if I echo anything after @ $db=new mysqli(host','championships','passwd','championships'); it dosen`t appear,if I echoed anywhere before that statement it works.something is here I think:( guys tell me the exact way to make another connection:( [/quote] Check your error log... I'm betting that @ symbol has something to do with it.. (Why is it there?)
  10. [!--quoteo(post=352242:date=Mar 6 2006, 04:46 PM:name=smith.james0)--][div class=\'quotetop\']QUOTE(smith.james0 @ Mar 6 2006, 04:46 PM) [snapback]352242[/snapback][/div][div class=\'quotemain\'][!--quotec--] I will have to change the &. I am running it on IE, latest one! James [/quote] ok... But are you using apache or iis on the local machine? If you're using IE, I expect that IIS is running on the local machine with some form of PHP installed.. There should be no difference between that and on the web at large. I don't remember any php.ini settings that handle whether or not you can handle GET requests...
  11. Maybe I'm missing something here, but I see a lot of code moving through here that just makes my head ache. Trying to keep HTML, Javascript, AND PHP together in the same file is asking for trouble.. And I see a lot of craziness with SQL statements too.. For instance, I see something like this : [code] <?php    $test = 'Hello';    $test2 = 'World'; ?> <html> <head></head> <body> <h1><?php echo "$test" ?> <?php echo "$test2" ?></h2> </body> </html> [/code] UGH! Ugly! Why not use something like Smarty templates and make this much more readable? [code] <?php    // Create a new smarty template and set up the globals for it    include('Smarty.class.php');    $smarty = new Smarty;    $smarty->compile_dir = "/usr2/smarty/templates_c";    $smarty->cache_dir = "/usr2/smarty/cache";    $smarty->config_dir = "/usr2/smarty/config";    $smarty->template_dir = dirname($_SERVER['PATH_TRANSLATED']) . '/templates';    $test = 'Hello';    $test2 = 'World';    $smarty->assign('test', $test);    $smarty->assign('test2', $test2);    $smarty->display('helloworld.tpl'); ?> [/code] And then in your template : [code] <html>    <head>    </head>    <body>       <h1>{$test} {$test2}</h1>    </body> </html> [/code] Yep, there's more initial code, BUT.. The big payoff here is being able to use the same templates for multiple pages, being able to easily change the template without impacting the main PHP code, and just plain READABILITY! In fact, the savvy coder will move the initial setup for smarty into a function and just include it at the beginning of the program. I spend most of my time here trying to differentiate the PHP from the HTML in most of these posts.. And SQL... I see a lot of this : [code]    $query = 'SELECT id, name, code FROM users WHERE id=' . $id_val . ' AND name=' . $name_val . ' ORDER BY code'; [/code] Aside from being ugly, this can be relatively unsafe.. Add some safety in here. Besides sanitizing your variables, use sprintf and force the type : [code]       $query = sprintf('SELECT id, name, code FROM users WHERE id=%d AND name="%s" ORDER BY code', $id_val, $name_val); [/code] There. The developer can quickly note that id is apparently a decimal value whereas name is obviously a string. Quite simply, using some strict coding guidelines, commenting, and keeping the various languages separate will help tremendously when debugging!
  12. [!--quoteo(post=352236:date=Mar 6 2006, 04:41 PM:name=tonbah)--][div class=\'quotetop\']QUOTE(tonbah @ Mar 6 2006, 04:41 PM) [snapback]352236[/snapback][/div][div class=\'quotemain\'][!--quotec--] Then I want to average all of the diff from the player and store it in the user database with their username. Then I want to take that number and mulitply it by.96 and store it in the user database as "handicp". Each time I have tried to use AVG it either tells me that I am using grouping wrong or it outputs the info but I am not able to store it. Is it possible to do this while the player is logged on to the website? Or could I do it as a series of commands in MySQL? [/quote] Code! I need code! :) Seriously, post the code you're using so we can take a crack at fixing it.. :)
  13. [!--quoteo(post=352231:date=Mar 6 2006, 04:34 PM:name=ADRlAN)--][div class=\'quotetop\']QUOTE(ADRlAN @ Mar 6 2006, 04:34 PM) [snapback]352231[/snapback][/div][div class=\'quotemain\'][!--quotec--] $query="insert into register values ('".$username."','".$username."','".$status."')"; that is the script.i get $username and $status from an external html script,that is not the problem.the problem is here.let`s consider the connection to the databse is done good,,what can be the problem?i get no errors,just a blank page when the script runs and no information is added 2 the database. the database name is championships and the table name is register. HELP GUYS:( PLEASE [/quote] Well, your logic says not to print anything if there's a problem.. :) Try adding a print statement and take a look at the query.. Maybe there's a query problem?
  14. Ok, there are all sorts of issues here. As it stands right now, that code shouldn't display much output at all as displayLogin() is never called. In fact, I don't believe it will display anything at all. I think something is missing here because $logged_in isn't even defined until the end of the code you posted, and that's needed to make displayLogin() work.. Is $testvalue intended to be temporary? If not, most of the confirmUser() code won't get run because you return a value towards the beginning. Once it hits a return, it jumps back to the calling function and continues execution. Is this something I can get shell access to? I can provide much more assistance that way... If so, PM me with the info and I can take a look...
  15. [!--quoteo(post=352225:date=Mar 6 2006, 04:12 PM:name=smith.james0)--][div class=\'quotetop\']QUOTE(smith.james0 @ Mar 6 2006, 04:12 PM) [snapback]352225[/snapback][/div][div class=\'quotemain\'][!--quotec--] It works on the web just not on my local machine. [/quote] Ok, 2 things. First, you should not be using a straight & in your image tag. These should always be entered using the HTML entity code of &amp; Second, I don't think I understand your question. You say it doesn't work on your local machine. Are you running it via a web browser on your local machine, or just via commandline?
  16. Are the breaks not being added to the HTML output?
  17. [!--quoteo(post=352153:date=Mar 6 2006, 01:50 PM:name=ShibSta)--][div class=\'quotetop\']QUOTE(ShibSta @ Mar 6 2006, 01:50 PM) [snapback]352153[/snapback][/div][div class=\'quotemain\'][!--quotec--] Which would this code use if all values were the same? [/quote] Simulate the values and try it out.. :) It should run through the first if() statement if all 3 values are equal. But, it shouldn't matter unless you're looking to make sure one person gets the hit before everyone else.. *grin* So, as an example, the hits will work out like this : 0 0 0 1 0 0 1 1 0 1 1 1 2 1 1 2 2 1 2 2 2 etc.
  18. [!--quoteo(post=352160:date=Mar 6 2006, 01:55 PM:name=tinuviel)--][div class=\'quotetop\']QUOTE(tinuviel @ Mar 6 2006, 01:55 PM) [snapback]352160[/snapback][/div][div class=\'quotemain\'][!--quotec--] Why is this happening? I ran some tests with the $testvalue, and it never works when the entire $sql, $result2 part of the funcion is placed anywhere in the file other than where it is, but when leaving it where it is, it doesn't return the value to the place I want it at. Does this make sense? Any help is much appreciated. [/quote] The code you posted should work. I think there's something else going on here. If you can echo $testvalue before the return and it's correct, but it's no longer correct directly after the return, then something very wierd is happening. $testvalue is not a global, correct? Can you post the whole script?
  19. [!--quoteo(post=352070:date=Mar 6 2006, 09:11 AM:name=ShibSta)--][div class=\'quotetop\']QUOTE(ShibSta @ Mar 6 2006, 09:11 AM) [snapback]352070[/snapback][/div][div class=\'quotemain\'][!--quotec--] [code]$count1 = mysql_query("SELECT * FROM s") or die(mysql_error()); $unique1 = mysql_num_rows($count1); $count2 = mysql_query("SELECT * FROM s1") or die(mysql_error()); $unique2 = mysql_num_rows($count2); $count3 = mysql_query("SELECT * FROM g") or die(mysql_error()); $unique3 = mysql_num_rows($count3);[/code] [/quote] First things first. If you're interested in the slowest loading page possible, the above is fine. However, I would recommend, instead, that you allow MySQL to do the counting for you. Observe : [code] list($unique1) = mysql_fetch_array(mysql_query('SELECT COUNT(*) FROM s')); [/code] Or, to break it out into edible chunks : [code]$query = 'SELECT COUNT(*) FROM s'; $count1 = mysql_query($query) or die(mysql_error()); list($unique1) = mysql_fetch_array($count1); mysql_free_result($count1); [/code] [!--quoteo(post=352070:date=Mar 6 2006, 09:11 AM:name=ShibSta)--][div class=\'quotetop\']QUOTE(ShibSta @ Mar 6 2006, 09:11 AM) [snapback]352070[/snapback][/div][div class=\'quotemain\'][!--quotec--] My goal: When somone go to this page it grabs the 3 values from the database and defines the values to the varibles $unique1, $unique2, $unique3. I then want the PHP script to find what have the 3 varibles has the lowest value and then execute the correct include and header:location. [/quote] Hrm.. Just off the top of my head : [code] if (($unique1 <= $unique2) && ($unique1 <= unique3)) {    # unique1 is the lowest } else if (($unique2 <= $unique1) && ($unique2 <= unique3)) {    # unique2 is the lowest } else if (($unique3 <= $unique1) && ($unique3 <= unique2)) {    # unique3 is the lowest } else {    # You should never reach this point } [/code]
  20. [code]$res=mysql_query(" SELECT COUNT(*) as cnt FROM table WHERE country='Portugal' and rentaltype='holiday rental' and foto='y'");     $row=mysql_fetch_assoc($res); mysql_free_result($res); $pgl=$row['cnt'];[/code] mysql_free_result should be called on the result object, not the array created with mysql_fetch_assoc.. Use the above code instead.
  21. Use a counter... [code] $counter = 0; while ($rows = mysql_fetch_array($result)) {    if ($counter == 4) {       $counter = 0;       print "</tr><tr>\n";    }    print "<td>" . $rows[0] . "</td>\n";    $counter++; } [/code] Note : You need to adjust accordingly if you intersperse php with html.. (Personally, I use smarty templates)
  22. Mail going to a junk folder is likely a function of the spam prevention mechanisms in place for that site. To minimize your chances of ending up in the junk folder, you need to make sure all of your headers are populated correctly and your mail follows, as closely as possible, any applicable mail RFCs. This is not a function of PHP, per se. Therefore, any code posted may or may not help you.
  23. [code]$r = mysql_query($q)or die(mysql_error()); $row = mysql_fetch_assoc($r); while($row = mysql_fetch_assoc($r)) { [/code] You have the above code. The reason you lose the first record is because of that first call to mysql_fetch_assoc. Change the code to this : [code]$r = mysql_query($q)or die(mysql_error()); while($row = mysql_fetch_assoc($r)) { [/code]
  24. As an aside, there is some decent paginator code here : [a href=\"http://tkap.org/paginator/\" target=\"_blank\"]http://tkap.org/paginator/[/a] I've used this in several project and it comes in quite handy...
  25. Try this : [code]$sql_item = sprintf('INSERT INTO Order_Item (orderID, quantity,price) VALUES (%d,%d,%f)', $orderID, $value, $row['price']); print "QUERY - $sql_item"; $result = mysql_query($sql_item,$connect) or die("sql_item: ".mysql_error($connect));[/code] This assumes that the first 2 values are decimal values, and the last is a float. If not, you need to adjust accordingly. (%s for string, %f for float, etc) The print line above should display the query at it was built. That should give you an indication as to what the problem is. The most common problem with these is that one of the values is uninitialized and prints nothing.
×
×
  • 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.