Jump to content

hitman6003

Members
  • Posts

    1,807
  • Joined

  • Last visited

Posts posted by hitman6003

  1. First off, that post is from 2002...MySQL, at that time, was still in version 4 (maybe even late version 3, I don't remember).  Since then it has made leaps and bounds.  It is a perfectly viable enterprise database, and usually the only thing that people have against it is misinformation and ignorance.

     

    That is not to say it doesn't have weaknesses.  For example, SQL server has indexed views, MySQL does not.  On the other hand, why do you need an indexed view and how often are you really going to use it?  What MySQL lacks in *generally* seldom used features it more than makes up for in performance...especially on "low end" hardware.

     

    The major gripe that most people have, and it's primarily administrators, is that mysql has spotty support for triggers.  Developers most commonly complain about the lack of a native XML data type support.

  2. This should give you a start:

     

    <?php
    
    $num_columns = 3;
    
    $array = range(0, 100);
    
    echo '
    <table>';
    
    for ($i = 0; $i <= count($array); $i += $num_columns) {
    $j = 1;
    
    echo '
    	<tr>';
    while ($j <= $num_columns) {
    	if (array_key_exists($i + $j, $array)) {
    		echo '
    		<td>' . $array[$i + $j] . "</td>";
    
    	} else {
    		echo '
    		<td> </td>';
    	}
    
    	$j++;
    
    }
    
    echo '
    	</tr>';
    
    }
    
    echo '
    </table>';

  3. <?php
    //Open images directory
    $dir = dir("../images");
    
    // this shouldn't be in the while loop
    $per_row = 3;
    
    echo '
    <table>
    	<tr>';
    
    $i = 0;
    
    // create the rows
    while (($file = $dir->read()) !== false) {
    $i++;
    
    // close and start another row if the correct number has been displayed
    if ($i % $per_row == 0) {
    	echo '
    	</tr>
    	<tr>';
    }
    
    echo '
    		<td><img src="../images/' . $file . '" alt="my image" /></td>';
    
    }
    
    // finish the current row
    while ($i % $per_row != 0) {
    echo '
    		<td> </td>';
    }
    
    echo '
    	</tr>
    </table>';
    }
    
    $dir->close();
    
    
    ?>

  4. You don't need 'useritem' in the table list when you specify an inner join...

     

    SELECT useritem.Quantity, item.Size 
    FROM item 
      INNER JOIN useritem ON item.ItemID = useritem.ItemID
    WHERE useritem.UserID='" . $_SESSION['Current_User'] . "' AND useritem.`Where`='1'

     

    Also, using reserved words for column names is a really bad idea...it just makes life more difficult in the long run. 

     

    Is useritem.where a numeric datatype (int, mediumint, smallint, etc), or is it a character type?  If it's the latter, and it only contains numbers, change it.  If it's the former, then you don't have to put the 1 in your query in quotes...MySQL only does a type conversion on it (it sees it as string because of the quotes and then converts it to match the column type), which is an extra, unnecessary operation.

  5. You just need a "!" (not) in front.

     

    If you did that you would return all other rows from the database...potentially MANY.

     

    Use his second suggestion, however mysql_num_rows will not return null, but will return 0 if no matching rows were found.

     

    You could also use a COUNT(username) query...

     

    $query = "SELECT COUNT(username) FROM users WHERE username = '" . $username . "'";
    $result = mysql_query($query) or die(mysql_error());
    
    if (mysql_result($result, 0) > 0) {
      echo 'That username exists';
    } else {
      echo 'That username is free';
    }

  6. This should get you started...

     

    <?php
    
    $query = "SELECT topics_topic FROM table ORDER BY topics_topic";
    $result = mysql_query($query) or die(mysql_error());
    
    // loop the result
    foreach ($result as $row) {
    // get the first letter
    $first = strtolower(substr($row['topics_topic'], 0, 1));
    
    // make sure the first letter is a letter
    if (str_pos('abcdefghijklmnopqrstuvwxyz', $first) !== false) {
    	// place it in the correct position in the array
    	$data[$first][] = $row['topics_topic'];
    }
    }
    
    // sort by keys
    ksort($data);
    
    // the number of columns you want
    $num_columns = 4;
    
    // start the table
    echo '
    <table>';
    
    // loop through the results
    foreach ($data as $letter => $topics) {
    // display the row with the letter
    echo '
    	<tr>
    		<th colspan="4">' . $letter . '</th>
    	</tr>
    	<tr>';
    
    $i = 0;
    
    // display the topic title in a td
    foreach ($topics as $topic) {
    	// if $num_columns tds have been echo'd start a new row
    	if ($i == $num_columns) {
    		echo '
    	</tr>
    	<tr>';
    
    		$i = 0;
    
    	}
    
    	echo '
    		<td>' . $topic . '</td>';
    
    	$i++;
    
    }
    
    // finish off the current row 
    while ($i < $num_columns) {
    	echo '
    		<td>nbsp;</td>';
    	$i++;
    }
    
    echo '
    	</tr>';
    }
    
    // finish off the table
    echo '
    </table>';

  7. Whenever you are having problems with a query there should always be two things you do before anything else...

     

    1) echo out your query...

    $query = "update players set bankaccount=$newbank[name] where id=$stat[id]";
    echo $query;
    mysql_query($query);

     

    2) show the mysql error(s)...

    $query = "update players set bankaccount=$newbank[name] where id=$stat[id]";
    echo $query;
    mysql_query($query) or die(mysql_error());

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