
Mutley
Members-
Posts
765 -
Joined
-
Last visited
Everything posted by Mutley
-
How would I do a > or < with a negative number? Is it simply -3 for example but would this confuse it to think subtract 3?
-
I don't know a thing about AJAX. The event that needs the number is in a file with loads more code. I'm slightly confused by your question, sorry. ???
-
It's for a Leaderboard. They have a number assigned to their position but this isn't stored in a database, it's simply by looping a count (e.g. $count = 0; $count++) when the results are displayed. When a certain event happens I want this number to be stored in the database but the file the event in isn't linked to this Leaderboard, so I can't pass the $count over in anyway (like POST/GET or whatever). Thanks, Nick.
-
I'm wanting to find and echo the row position in a table when they are put into order and there is a certain where clause. For example, I want to find what row position it is where ID = 7... ordered by `joindate`. This might bring up 10 results, where the row with the above ID (7) is 5th in the results. How do I echo "5"? I hope that makes sense. Thanks, Nick.
-
Thanks guys. If I have 20+ fields though, would this mean making a function for every field to echo it? Can't I just list them inside 1 function and call them individually from outside of it?
-
Here's my code: <?php function getGames($where) { $res = mysql_query("SELECT gameID, name FROM site_games WHERE $where"); while($row = mysql_fetch_array($res)) { $gameID = $row['gameID']; $name = $row['name']; } } getGames('gameID = 1'); echo $name;// Echo from the variable out of the function ?> I think I know why it's wrong, I imagine the echo has to be inside the function?
-
I had an idea instead of coding the same query to get certain fields over and over again, to do a function with the query in just once, then displaying the results by calling the function and echoing the fields/results. However it doesn't seem that this is possible. If I echo the fields inside the function, they display but anything outside the function, does not. Is there a way around this or another possible method to do the same technique?
-
I wish to be able to put the following in my address bar: images/sigs/USERNAME/sig.png then for it to activate the following instead.... images/sigs/sig.png?user=USERNAME It's for a dynamic image... in forums I cannot use dynamic images (if they have a ? variable in the URL, they need to be clean). I figure this would be a work around. Thanks, Nick.
-
I have a query that I want to order by a total score. It adds up 4 fields for every user of that team. However it doesn't order them by highest total score, just randomly. $sql = "SELECT t.team_id, t.level, t.name, t.initials, t.owner, l.user_id, SUM(l.2playerpts) AS vr2playerpts, SUM(l.4playerpts) AS vr4playerpts,SUM(l.6playerpts) AS vr6playerpts, SUM(l.8playerpts) AS vr8playerpts, l.wins, l.losses, u.user_id, u.team_id FROM teams t INNER JOIN users u ON u.team_id = t.team_id INNER JOIN leaderboard l ON l.user_id = u.user_id GROUP BY t.team_id ORDER BY (SUM(l.2playerpts) + SUM(l.4playerpts) + SUM(l.6playerpts) + SUM(l.8playerpts)) AND t.level DESC"; Any ideas? I've tried removing the SUM statement and also using the AS statement versions but still seems random. Thanks, Nick.
-
Firstly, the script cuts off items where $unlock != 0, it seems to be stopping the loop continuing. Secondly, it won't work if $unlock == "1000_bronze" for example, it won't perform the IF statement further down that echos "Locked". $sql = "SELECT prod_id, slot, points, manufacture, name, description, stock, price, `unlock` FROM products WHERE slot = '$cat' AND grade=0 ORDER BY $orderby"; $result = mysql_query($sql); if(mysql_num_rows($result)!=0) { // (3) while(list($prod_id, $slot, $points, $manufacture, $name, $description, $stock, $price, $unlock) = mysql_fetch_row($result)) { // (4) ?> <tr> <td><center><img src="images/products/<?=$prod_id?>.jpg" alt="<?=$name?>" border="1" /></center></td> <td align="center"> <b><?=$manufacture?><br /> <font style="color:#FF6600; font-size:larger;"><a name="<?=$prod_id?>"><?=$name?></a></font></b><br /> <img src="images/manufactures/<?=$manufacture?>.gif" alt="<?=$manufacture?>" /> </td> <td style="background-color:#EAEAEA; padding:5px;"><?=$description?></td> <td align="center"> <? if($stock < '3') { $status = "ff0000"; } else { $status = "009933"; } $result_qty = mysql_query("SELECT COUNT(*) AS qty_sold FROM own WHERE prod_id = '$prod_id'"); while($row_qty = mysql_fetch_array( $result_qty )) { $qty_sold = $row_qty["qty_sold"]; } //---------------------------------------- // Check if the product is locked by achivement //---------------------------------------- if($unlock != '0') { $result = mysql_query("SELECT '$unlock' AS `score` FROM achievements WHERE user_id = '$user_id'"); while($row = mysql_fetch_array( $result )) { $score = $row["score"]; } //---------------------------------------- // Achievements Below //---------------------------------------- if($unlock == "1000_bronze" && $score == "1000") { $unlocked == '1'; } else { $unlocked == '0';} if($unlock == "1000_silver" && $score == "1000") { $unlocked == '1'; } else { $unlocked == '0';} if($unlock == "1000_gold" && $score == "1000") { $unlocked == '1'; } else { $unlocked == '0';} if($unlock == "3_tourn" && $score == "3") { $unlocked == '1'; } else { $unlocked == '0';} } else { $unlocked == '1'; } ?> <font style="color:#<?=$status?>; font-size:larger;"><b><?=$stock?></b></font> <br /> <font style="font-size:x-small">Qty Sold:<br /> <?=$qty_sold?></font> </td> <td align="center"><b>£<?=$price?></b></td> <td align="center"> <? if($unlocked == '0'){ echo "Locked"; }elseif($stock == '0') { echo "Out of Stock"; }else{ // Disable buy button if no stock or achievement ?> <form action="shop.php?cat=<?=$cat?>&buy=<?=$prod_id?>" method="post"> <input type="submit" name="submit" value="Buy" /> </form> <? }?> Any advice greatly appreciated.
-
I have a site where users can vote for articles. I would like to record every article that user votes, so you can simply go into their profile and see which articles they have voted on. How would I organise this? I was thinking of simply a row for each vote in a table, such as: voteID userID articleID time 1 43 9 135213512 2 12 3 135213512 But if there are hundreds of thousands of votes, wouldn't this stuff the database and become slow? Thanks, Nick.
-
Argh, thanks! I hate it when it's missing something simple like that.
-
I can't get the following function to work, I've tested all the variables and data and they echo correctly, I can't see why it doesn't initiate. Thanks in advance!
-
I have a function it contains the following form: *snip* <div> <div style="float:left"> <form enctype="multipart/form-data" action="loadout2.php" method="post"> <input type="hidden" name="goprodid" value="<?=$prod_id?>" /> <input type="hidden" name="goownid" value="<?=$own_id?>" /> <input type="hidden" name="gochkmarket" value="<?=$market_id?>" /> <select name="partoptions" style="width:50px"> <option name="select" value="0" selected="selected"> </option> <option name="gorepair" value="1" <? if($stock=='0'){?>disabled="disabled"<? }else{ echo"";}?>>Repair (-£<?=round($y)?>)</option> <option name="goreplace" value="2" <? if($stock=='0'){?>disabled="disabled"<? }else{ echo"";}?>>Replace (-£<?=round($price)?>)</option> <option name="gobin" value="3">Bin (+£3)</option> <option name="gomarket" value="4" <? if($loadout=='1'){?>disabled="disabled"<? }else{ echo"";}?>><? if($market_id == '1'){ echo "Remove off Market"; }else{ echo "Sell on Market";}?></option> </select> </div> <div> <input type="submit" name="gosubmit" value="Go!" style="width:30px; font-size:xx-small" /> <? if($market_id == '1') { echo " <img src=\"images/restrict_market.png\" style=\"vertical-align:top\" alt=\"On Market\" /> "; } else { echo ""; } ?> </div> </div> <? echo "</td> </tr>"; }// End No Items } echo "</table></form> <br />"; } The problem is, the form can be repeated several times on a single page. When it is submitted, it always refers to the first form on the page. I don't understand why as the form is ended with </form> on each one, so why does it think it's the same form everytime? Is there an easy fix to this? Thanks, Nick.
-
How do I allows spaces in a preg_match, currently it does a-z A-Z 0-9 _ - preg_match('/^[a-zA-Z0-9_-]+$/', $theword) Thanks, Nick.
-
Anyone have thoughts on this problem? Regards.
-
Invalid use of group function. ???
-
If I change the alias for the SUMs it doesn't recognize them in the ORDER BY (it thinks their a field in the actual table). SELECT t.team_id, t.level, t.name, t.initials, t.owner, l.user_id, SUM(l.2playerpts) AS vr2playerpts, SUM(l.4playerpts) AS vr4playerpts,SUM(l.6playerpts) AS vr6playerpts, SUM(l.8playerpts) AS vr8playerpts, l.wins, l.losses, u.user_id, u.team_id FROM teams t INNER JOIN users u ON u.team_id = t.team_id INNER JOIN leaderboard l ON l.user_id = u.user_id GROUP BY t.team_id ORDER BY (2playerpts + 4playerpts + 6playerpts + 8playerpts) DESC So I did it like that^ but still no luck, it's like the 2playerpts is being grabbed from somewhere else but why doesn't my SUM aliases work in there?
-
SELECT t.team_id, t.level, t.name, t.initials, t.owner, l.user_id, SUM(l.2playerpts) AS 2playerpts, SUM(l.4playerpts) AS 4playerpts,SUM(l.6playerpts) AS 6playerpts, SUM(l.8playerpts) AS 8playerpts, l.wins, l.losses, u.user_id, u.team_id FROM teams t INNER JOIN users u ON u.team_id = t.team_id INNER JOIN leaderboard l ON l.user_id = u.user_id GROUP BY t.team_id ORDER BY (2playerpts + 4playerpts + 6playerpts + 8playerpts) DESC What's happening is it's not ordering in any order, it should have the calculated row with the biggest Total SUM at the top. I hope that makes sense. Thanks in advance.
-
So: <?php $diff = time() - ($oldtime + 7200); ?> Thanks for the speedy replies! I shall test it out.
-
I have a variable that contains a 12 figure unix time ($oldtime). This updates to the current time every 2 hours. What I wish to do with this, is display the time left... before it resets again, so it's counting down from 2 hours to 0, in which it then gets reset and it starts counting down all over again. How would I do this? Kind Regards, Nick.
-
Selecting an area of data before/after a match from a Database
Mutley replied to Mutley's topic in PHP Coding Help
Thanks a lot akitchin. Is the 'unassigned' $my_pointer variable supposed to have some other data in it? I'm not too sure what that variable is doing. Regards, Nick. -
Is there any resources that explain how to filter different things using preg_match? I just look at it and do not understand how it filters. preg_match('/^[a-zA-Z0-9_-]+$/', $this); What does it mean? Thanks. I see the lower/upper case Alphabetical characters and then 0-9 digits but what are the others?
-
Thanks, but if it shows true, it should show, if it isn't true, it doesn't show. I shouldn't need an else? ???