Jump to content

IceHawk

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Everything posted by IceHawk

  1. If you're using my while loop, there's a slight mistake I just noticed. If you replace $n = $i + 1; with; $n = $i++ + 1; Then you should be good to go.
  2. If you're doing that to every single row in the table regardless of the columns current value then you would just need to do; update [table] set [column] = 0
  3. The basic query you're looking for is; select * from magazines order by issue_id asc or select * from magazines order by issue_id desc The first will order the results on issue_id is ascending order, the second in descending order.
  4. May I recomend the below method instead; [code] $query = "select user_points from users where user_username = '$username'"; $result = mysql_query($query); list($old_points) = mysql_fetch_row($result); $points = $old_points - 1000; $query = "UPDATE users SET user_points = '$points' WHERE user_username = '$user_name'"; $result = mysql_query($query); [/code] Replacing the needless while loop with list($old_points) = mysql_fetch_row($result) saves some lines. And specifying in the query to only select the column you're working with will save time on the query as well. A possible cause of your error I see is that in the first query you use $username, but in the update you use $user_name. Not sure which one holds the actual username you're using though, but you will want to double check that.
  5. Where is $_GET['orderid'] coming from exactly? The form you provided does not carry any field named 'orderid' so even if orderid is set in $_GET when submitting the form, it will not be carried over. Try adding a hidden field to the form named 'orderid' and pass in the value of $_GET['orderid'] to it and try again. This is causing $_GET['orderid'] to be blank, which is probably causing the queries to throw an error.
  6. Where is $nrows being set? Based just off what you posted here, $nrows doesn't exist so the loop will never run. You would need to do something like ; $nrows = mysql_fetch_rows($sql); Or you could do; [code] $sql = mysql_query("SELECT * FROM Players ORDER BY Points DESC LIMIT $from, $max_results"); while($row = mysql_fetch_array($sql)){     $n = $i +1;        //add 1 so that numbers don't start with 0                  // Build your formatted results here.     echo("<tr bgcolor=".$bgcolor."><td>");     echo($row["Name"]);     echo("</td><td>");     echo($row["Nationality"]);     echo("</td><td>");     echo($row["Points"]);     echo("</td></tr>"); } [/code] With the above, the loop will run for each row returned by the query, and each row will be entered into $row for you. So there is no need for the for loop.
  7. Depending on the change you're trying to make you can simply write a query to do it and run it from inside PHPMyAdmin. If you're modifying a lot of rows, that's generally the best way to do it. If you provide more info I can help with the query if needed.
  8. I would recomend the following. [code] $link =mysql_connect($hostname,$username, $password) OR DIE ("Unable to connect to database! Please try again later."); mysql_select_db($dbname); $arr_b = array("x500y500","x510y500"); $arr_r = array("x500y510","x500y520","x510y510","x510y520"); foreach($arr_b as $coord){     $res = mysql_query("select ct.*, cr.* from coordsTaken ct, coordsReserved cr where cr.xyPOS=ct.xyPOS and ct.xyPOS='$coord'");     if(!$res || !mysql_num_rows($res)){         echo "Bad Coordinate";     }else echo "Good Coordinate"; } foreach($arr_r as $coord){     $res = mysql_query("select ct.*, cr.* from coordsTaken ct, coordsReserved cr where cr.xyPOS=ct.xyPOS and ct.xyPOS='$coord'");     if(!$res || !mysql_num_rows($res)){         echo "Bad Coordinate";     }else echo "Good Coordinate"; } mysql_close($link); [/code] Combining the queries will save on the query count and is much faster. The more you can do in a query, the better. It's much more efficient to have the DB do the work then the code. foreach loops are also much faster than for loops. The way you structured the for loop is also inefficient. [code] for ($i=0; $i < count($arr_b); $i++){ [/code] he problem with this is that after every iteration, count($arr_b) will be re-evaluated. So if the array is very large, you will be re-evaluating a constant value needlessly (unless the size of the array is modified in the loop). Much more efficient to do something such as; [code] $size = count($arr_b); for ($i=0; $i < $size; $i++){ [/code] That way count($arr_b) is only evaluated once. With small arrays this isn't an issue, but if the array is large, it can add processing time.
×
×
  • 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.