Jump to content

widget

Members
  • Posts

    148
  • Joined

  • Last visited

Everything posted by widget

  1. Sorry Zane There is a table of item a user has in their shop. They can click a button next to the pricing field in their shop that will set the price for them by searching the database of all users shops for that item, retrieving the cheapest price and setting their price $1 less. The trouble is, when it comes across an item that noone else has in stock it doesnt know what to do and simply just uses the previous items price.
  2. Heres the setup Virtual pet site, users shop. They can click on an icon that will price their item 1 point less than the lowest existing. Trouble is, if no-one else has that item in stock, the icon prices the item the same price as the previous item listed. Example Chocolate Bar $1 Red Hat $1 <--- theres none of these in any other shop therefor it needs to return $0 Here is my code. $findResults = mysql_query("SELECT * FROM usershops_items2 WHERE price > '0' AND item_id = '$find_item2[id]' ORDER BY price ASC LIMIT 1"); while ($getResults = mysql_fetch_array($findResults)) { $cheap = $getResults[price]; $cheap2 = $cheap -1; } $cheap = "<span onclick=\"MM_setTextOfTextfield('item_price[$id]','','$cheap2')\"><img src=images/items/item_747.gif width=24 height=24></span>"; I have tried adding in if statements in different places but nothing works.
  3. Thank you for your advice although I managed to get it working with the below code. Theres probably a much neater way to do it though. $sql_query = "SELECT id,item_name FROM items2 WHERE item_type = 'intel_inc'"; $result = mysql_query($sql_query); if(mysql_num_rows($result)) { while($row = mysql_fetch_row($result)) { $books_id = $row[0]; $find_pet = fetch("SELECT item_id FROM read2 WHERE pet_id = '$id' AND item_id = '$books_id'"); $pets_books_id = $find_pet[item_id]; if ($pets_books_id == $books_id) { ?> <style> .book2 img{ opacity:1.0; filter:alpha(opacity=100); /* For IE8 and earlier */ </style> <? echo ("<div class='book book2'><a href=/books/$books_id.php><img src='$base_url/images/items/item_$books_id.gif' width='64px' height='64px'><br>$row[1]</a> </div> "); } else { ?> <style> .book3 img{ opacity:0.2; filter:alpha(opacity=20); /* For IE8 and earlier */ </style> <? echo ("<div class='book book3'><img src='$base_url/images/items/item_$books_id.gif' width='64px' height='64px'><br>$row[1] </div> "); } } } //if no fields exist else { echo "no values in the database"; } ?>
  4. Using mysql and php 5 Table 1 is a list of books. Table 2 is a list of userids and the books read. USER_ID | ITEM_ID ________________ 1 | 345 1 | 456 2 | 345 2 | 457 2 | 347 My page displays images (opaque) of all books available from Table 1 In the while statement that displays the books, I would like to check Table 2 for a match and if the user has read it, the image is not opaque and also contains a link. I have no clue on the best way to do this. Below is my code so far. $sql_query = "SELECT id,item_name FROM items2 WHERE item_type = 'intel_inc'"; $result = mysql_query($sql_query); if(mysql_num_rows($result)) { while($row = mysql_fetch_row($result)) { $get_books_read = mysql_query("SELECT item_id FROM read2 WHERE user_id = '$id'"); if( IF THERE IS A MATCH ) { echo ("<div class='book_yes'><img src='$base_url/images/items/item_$row[0].gif' width='64px' height='64px'><br>$row[1]</div> "); } else { echo ("<div class='book_no'><a href='#'><img src='$base_url/images/items/item_$row[0].gif' width='64px' height='64px'><br>$row[1]</a></div> "); } } } //if no fields exist else { echo "no values in the database"; } Thanks in advance for any help offered.
  5. Hi Guys My site has a shout box, now and again people post inappropriate content and if a moderator is not online to mute them it doesnt look good for other users. I have written a snippet of code to report an offender. My goal is that if 3 different people report an offender the site auto mutes them. (manual mute function already exists for moderators) I setup a table that records the reporters name the offenders name the post id the message content and the time stamp. I have never been good at counting num rows etc and need some help in what direction to go in. My current code that inserts the reported content. mysql_query("INSERT INTO `chicka_pets`.`records_sbreports` (`id`, `offender`, `reporter`, `post_id`, `post_content`, `timestamp`) VALUES ('', '$offender', '$username', '$id', '$sbmessage', '$timestamp')"); I am guessing that somewhere after that I need some sort of count numrows on the post id where reporter is NOT the same and then an if numrows >2 set offender to mute my problem is how to do the num rows bit where the reporters are unique? Any help is much appreciated
  6. Thank you so much num rows worked a treat Just in case anyone else has a similar problem here tis the code <FORM ACTION="<?php echo $_SERVER['PHP_SELF']; ?>" METHOD=get> <input type="text" name="band" value="<?php echo $_GET['band']; ?>" /> <input type="text" name="bust" value="<?php echo $_GET['bust']; ?>" /> <INPUT TYPE=submit VALUE="Calculate"> </FORM> <?php if(isset( $_GET['band']) && isset($_GET['bust']) ){ $band = $_GET['band']; $bust = $_GET['bust']; $query = sprintf("SELECT size FROM bra_calculator WHERE band='%s' AND bust='%s'", mysql_real_escape_string($band), mysql_real_escape_string($bust)); $result = mysql_query($query); $num_rows = mysql_num_rows($result); if (!$num_rows) { echo "N/A"; } else { while ($row = mysql_fetch_assoc($result)) { echo "$row[size]"; } } mysql_free_result($result); }
  7. Sadly that just displays N/A before submitting the form but thank you for your help
  8. I have written a bra calculator, when the user enters their measurements their bra size is displayed however as the code I have used to do this came from a help tutorial I do not understand how it was constructed as I am quite a newb. The form works perfectly when returning data however if there is no size for a particular measurement it just displays nothing. I would like it to display N/A I have tried adding various if elses but without success. Any help is much appreciated <FORM ACTION="<?php echo $_SERVER['PHP_SELF']; ?>" METHOD=get> <input type="text" name="band" value="<?php echo $_GET['band']; ?>" /> <input type="text" name="bust" value="<?php echo $_GET['bust']; ?>" /> <INPUT TYPE=submit VALUE="Calculate"> </FORM> <?php $band = $_GET['band']; $bust = $_GET['bust']; $query = sprintf("SELECT size FROM bra_calculator WHERE band='%s' AND bust='%s'", mysql_real_escape_string($band), mysql_real_escape_string($bust)); $result = mysql_query($query); if (!$result) { echo "no"; } else { while ($row = mysql_fetch_assoc($result)) { echo $row['size']; } } mysql_free_result($result); ?>
  9. eh I dont understand it - think I will move on to another alternative
  10. hmm I have to go out for a bit but will try this as soon as I am back - I have never gotten into sessions before so should be interesting. Thanks
  11. what's your opinion on using javascript such as... <script type="text/javascript"> function myfunc () { var frm = document.getElementById("foo"); frm.submit(); } window.onload = myfunc; </script>
  12. this works but I was looking for a way to auto redirect them back to PageA and not have them click a button but after lots of reading I think this is impossible.
  13. with your example I can replicate it simply by adding die("You have won a fantastic prize!!!!"); but I don't know if this is good coding practice as I am only following what I am being shown.
  14. thank you - that code works but I need it to redirect the user back to page A and display the message, for example at the top of the page.
  15. Hi all, I am in need of a bit of advice on the best way to display a message on screen to a user. This is a little difficult to explain so please bare with me. I am using php5 and mysql My worry is to do with XSS etc Current Scenario My website is a pet gaming site where often a user is able to claim a free gift or prize. User clicks a button or link on Page A to claim a free gift. This redirects the user to Page B where all the magic happens and the gift is chosen and then redirects the user back to Page A without them even seeing what happened with a message of "Congrats you won a blah blah" Now my problem is, the way the message is handled. Page A Code <a href=$base_url/PageB.php>link</a> Page B Code die(header(error("PageA.php","message here"))); Result URL is $base_url/PageA.php&error=message here I am concerned that a malicious user could inject the error= variable what would be the best way to do this without having to have the information in the URL?
  16. im running the cron job and refreshing the page as it happens and getting the error
  17. Heres a doosey - well for me anyway. I have a cron file to clear out high scores and award a trophy to the top 3 players. Now if I run the Bubble Pop cron job (top code) it works fine however if I run the Pyramid one(bottom code) it throws back an error at me Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/kabooc/public_html/ghetto_cron.inc.php on line 384 Line 384 is if(mysql_num_rows($result)) Both are the exact same code bar the second one has a WHERE clause. if ($run['Bubblepop']) { $sql_query = "SELECT username,MAX(score) as total FROM highscores_bubblepop GROUP BY username ORDER BY 'total' DESC LIMIT 0 , 3"; //store the SQL query in the result variable $result = mysql_query($sql_query); if(mysql_num_rows($result)) { $x =110; while($row = mysql_fetch_row($result)) { mysql_query("INSERT INTO trophy (user_name, trophy_id) VALUES ('$row[0]','$x')"); mysql_query("INSERT INTO records (record_type, record_entry, userid) VALUES ('Bubble Pop Trophy','$row[0] was awarded a $x trophy','1')"); $x ++; } } mysql_query("DELETE FROM highscores_bubblepop"); } if ($run['Trophy Pyramid Solitaire']) { $sql_query = "SELECT username,MAX(score) as total FROM highscores WHERE gameID = '106' GROUP BY username ORDER BY 'total' DESC LIMIT 0 , 3"; //store the SQL query in the result variable $result = mysql_query($sql_query); if(mysql_num_rows($result)) { $x =101; while($row = mysql_fetch_row($result)) { mysql_query("INSERT INTO trophy (user_name, trophy_id) VALUES ('$row[0]','$x')"); mysql_query("INSERT INTO records (record_type, record_entry, userid) VALUES ('Trophy Pyramid Solitaire','$row[0] was awarded a $x trophy','1')"); $x ++; } } } I have looked through google and most errors I find the solution is to... double check database tables - done check spelling - done check connection - done is there an alternative way to do what I am trying and what is it? or is there some sort of blatantly obvious error and im just not seeing it?
  18. I worked it out $sql_query = "SELECT username,MAX(score) as total FROM highscores_bubblepop group by username ORDER BY `total` DESC LIMIT 0 , 10"; Had to order by total not score and it now works perfectly. Hopefully this helps others as I know its taken me a long long time to find the answer Thank you all who helped
  19. Is anyone able to shed some light on this?
  20. Hi me again! I now have beta testers on the site and it seems its not working as it should after all $sql_query = "SELECT username,MAX(score) as total FROM highscores_bubblepop group by username ORDER BY `score` DESC LIMIT 0 , 50"; //store the SQL query in the result variable $result = mysql_query($sql_query); if(mysql_num_rows($result)) { //output as long as there are still available fields $x =1; while($row = mysql_fetch_row($result)) { $current_avatar = fetch("SELECT * FROM members_profiles2 WHERE username = '$row[1]'"); echo ("<div class=\"game_high_scores_content\" style=\"background-image: URL($base_url/images/avatars/$current_avatar[avatar].gif);\">$row[0] Scored $row[1]</div>"); $x ++; } } //if no fields exist else { echo "no values in the database"; } mysql_close($con); Result 2random4me Scored 2097 lollypopchicka Scored 1541 loulou2370 Scored 603 plutoheart Scored 1662 maryann1950 Scored 2126 twinkle Scored 386 faeryofavalon Scored 632
  21. woot nvm i added ORDER BY `score` DESC $sql_query = "SELECT username,MAX(score) as total FROM highscores_bubblepop group by username ORDER BY `score` DESC LIMIT 0 , 50"; joe Scored 777 lollypopchicka Scored 269 fred Scored 115 I could kiss you!!! thank you soo much I have been trying to fix this problem for years on and off.
  22. ohheeeeeeee that kinda worked fred Scored 115 joe Scored 777 lollypopchicka Scored 269 how can we display highest score 1st?
  23. That kinda works How would I then only include a players top score or 1 distinct entry? Query $sql_query = "SELECT distinct `username`,`score` FROM `highscores_bubblepop` ORDER BY `username`,`score` DESC LIMIT 0 , 50"; Results fred Scored 115 fred Scored 111 joe Scored 777 joe Scored 234 lollypopchicka Scored 269 lollypopchicka Scored 262 On a personal note I just read your blog entry on selling your Mac, priceless!!
  24. order by score and username give the below results fred Scored 111 fred Scored 115 joe Scored 234 lollypopchicka Scored 262 lollypopchicka Scored 269 joe Scored 777 $sql_query = "SELECT distinct `username`,`score` FROM `highscores_bubblepop` ORDER BY `score`,`username` DESC LIMIT 0 , 50";
×
×
  • 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.