Jump to content

metalblend

Members
  • Posts

    89
  • Joined

  • Last visited

    Never

Posts posted by metalblend

  1. ..read the error message: duplicate key

     

    A primary|index key\'d column cannot have duplicate entries, meaning that if you\'ve used a 0 for your id column, 0 cannot be inserted again. If this is an auto_increment\'ing column, you don\'t even need to set the id column, as MySQL will insert the next value automatically. Use a different value for id each time you insert into the database.

     

    Hope that helps.

  2. ..not too sure if this bit of code will speed the process, but is shorter and (in my opinion) the safer way to go:

    <?php
    
     $id=mysql_connect(\'host\',\'username\',\'password\') or die(mysql_error());
    
     mysql_select_db(\'databasename\',$id) or die(mysql_error());
    
     $rs = mysql_query(\'SELECT name FROM table_name\',$id) or die(mysql_error());
    
    
    
     while($row = mysql_fetch_array($rs,MYSQL_ASSOC))
    
       echo \'<option value=\'\' . $row[\'name\'] . \'\'>\' . $row[\'name\'] . \'</option>\';
    
    ?>

     

    Hope that helps.

  3. Using the method I gave earlier:

    <?php
    
     $query = mysql_query("SELECT username,class,level FROM sh_player WHERE dead=\'0\'");
    
     $total = mysql_num_rows($query);
    
    
    
     echo \'<table><tr><td><b><font size="2" face="verdana" color="#6699CC">Name</font></td><td>\';
    
     echo \'<font size="2" face="verdana" color="#6699CC"><b>Class</font></td><td>\';
    
     echo \'<font size="2" face="verdana" color="#6699CC"><b>Level</b></font></td></tr>\';
    
    
    
     while($row = mysql_fetch_array($query,MYSQL_ASSOC)
    
     {
    
       echo \'<tr><td><font size="2" face="verdana" color="#6699CC">\' . $row[\'username\'] . \'</font></td><td>\';
    
       echo \'<font size="2" face="verdana" color="#6699CC">\' . $row[\'class\'] . \'</font></td><td>\';
    
       echo \'<font size="2" face="verdana" color="#6699CC">\' . $row[\'level\'] . \'</font></td></tr>\';
    
     }
    
    
    
     echo \'</table>\';
    
    ?>

     

    or using your mysql_result() method (which still results in more code):

    <?php
    
     $query = mysql_query("SELECT username,class,level FROM sh_player WHERE dead=\'0\'");
    
     $total = mysql_num_rows($query);
    
    
    
     echo \'<table><tr><td><b><font size="2" face="verdana" color="#6699CC">Name</font></td><td>\';
    
     echo \'<font size="2" face="verdana" color="#6699CC"><b>Class</font></td><td>\';
    
     echo \'<font size="2" face="verdana" color="#6699CC"><b>Level</b></font></td></tr>\';
    
    
    
     for($i=0;$i<$total;$i++)
    
     {
    
       $username = mysql_result($query,$i,\'username\');
    
       $class    = mysql_result($query,$i,\'class\');
    
       $level    = mysql_result($query,$i,\'level\');
    
       echo \'<tr><td><font size="2" face="verdana" color="#6699CC">\' . $username . \'</font></td><td>\';
    
       echo \'<font size="2" face="verdana" color="#6699CC">\' . $class . \'</font></td><td>\';
    
       echo \'<font size="2" face="verdana" color="#6699CC">\' . $level . \'</font></td></tr>\';
    
     }
    
    
    
     echo \'</table>\';
    
    ?>

     

    Hope that helps.

  4. You are using 3 queries:

    SELECT username FROM sh_player WHERE dead=\'0\'
    
    SELECT class FROM sh_player WHERE dead=\'0\'
    
    SELECT level FROM sh_player WHERE dead=\'0\'

     

    A quicker method, for both the script and the server, is to use 1 query to return all of the results:

    SELECT username,class,level FROM sh_player WHERE dead=\'0\'

    then loop through the results.

     

    You\'ve made it harder than it needs to be.. look into that.

  5. Actually there are a few things wrong.. try this:

    <?php
    
     $query = mysql_query("SELECT username,class,level FROM sh_player WHERE dead=\'0\'");
    
     $total = mysql_num_rows($query);
    
    
    
     echo \'<table><tr><td><b><font size="2" face="verdana" color="#6699CC">Name</font></td><td>\';
    
     echo \'<font size="2" face="verdana" color="#6699CC"><b>Class</font></td><td>\';
    
     echo \'<font size="2" face="verdana" color="#6699CC"><b>Level</b></font></td></tr>\';
    
    
    
     while($row = mysql_fetch_array($query,MYSQL_ASSOC)
    
     {
    
       echo \'<tr><td><font size="2" face="verdana" color="#6699CC">\' . $row[\'username\'] . \'</font></td><td>\';
    
       echo \'<font size="2" face="verdana" color="#6699CC">\' . $row[\'class\'] . \'</font></td><td>\';
    
       echo \'<font size="2" face="verdana" color="#6699CC">\' . $row[\'level\'] . \'</font></td></tr>\';
    
     }
    
    
    
     echo \'</table>\';
    
    ?>

     

    Hope that helps.

  6. Remember, ORDER BY is fairly new to UPDATE queries (introduced in 4.0.0).. be sure your host has MySQL 4 or later.

     

    Other than that, there are no syntax errors in your query.

  7. Just for reference, the error :

    Warning: Supplied argument is not a valid MySQL result resource

     

    means one thing.. you tried to retrieve results where the query returned FALSE (failed). With knowledge of the built-in MySQL functions you\'ll notice that when you query the database, you will get 1 of 2 possibilities returned:

     

    a) a mysql result resource/link

    B) FALSE [boolean]

     

    A simple way to avoid getting this error is to perform some error checking before attempting to retrieve the results:

     

    if ($result != FALSE) {
    
     #do this
    
    } else {
    
     # do this [error]
    
    }

     

    This method will save you debugging time in the future.. probably a good idea to start doing it.

     

    Hope that helps.

  8. I\'ve never seen this topic discussed before.. from what I\'ve learned, MySQL is technically an open-source relational database system. The differences are marginal, but I stand on the RDBMS side.

  9. Wow.. this query is indeed corrupt, but in a small way. The brackets {/} should be parenthesis (). The correct way of implementing this (without possible error) would be:

    CREATE TABLE `news` ( `id` int( 10 ) NOT NULL auto_increment, `title` varchar( 100 ) NOT NULL , `text` text NOT NULL , PRIMARY KEY ( id ) )

     

    Hope that helps.

  10. The server which hosts the file most likely has the directive register_globals off, which is the new configuration for PHP 4.2.0 and later. Read more about the alternative here: http://www.php.net/manual/en/reserved.variables.php

     

    I have configured your code to work fine on my server.. it runs a rather old version of PHP, which is why I have to use $HTTP_{method}_VARS method more commonly used. ;)

     

    Here\'s the working copy.. fill out the form and the source is displayed on the next page: http://code.phirebrush.com/ref/httpvars.php

     

    Hopefully you find what sections you need to remove.. if not, let us know.

     

    Hope that helps.

  11. Try this:

    $mysql = mysql_connect("localhost", "doomflam_admin", "PASSWORD") or die("Could Not Connect To Database!");
    
    mysql_select_db("doomflam_forum",$mysql) or die("Unable To Locate Database!");
    
    $query = "SELECT username FROM phpbb_users";
    
    $setquery = mysql_query($query) or die("Query failed!");
    
    
    
    if (mysql_num_rows($setquery)>0)
    
    {
    
     while ($res = mysql_fetch_array($setquery))
    
     {
    
       print $res[\'username\']."<br>rn";
    
     }
    
    }
    
    else
    
    {
    
     print "There are no entries!";
    
    }

     

    Hope that helps.

     

    You can break it down if you need to customize it.. let us know if you need more help.

     

    edit // posted late.. either method will work. :)

×
×
  • 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.