Jump to content

GingerRobot

Staff Alumni
  • Posts

    4,082
  • Joined

  • Last visited

Everything posted by GingerRobot

  1. Seems to be working ok for me on your page. Do i take it that you fixed it?
  2. Hmm, im a bit rusty on more advanced mysql functions...and im fairly sure this can be achieved in a single query. But you could try something like: <?php $sql = mysql_query("SELECT `username`,COUNT(`username`) FROM `yourtable` GROUP BY `username` HAVING COUNT(`username`) > 1") or die(mysql_error()); //this will find each of the duplicated values for the username, but (i think) will only return one of the values for it - e.g, in the results, you will only find username1 once - so we then cycle through the results to pull the rest of the info from the database while($row = mysql_fetch_assoc($sql)){ $sql2 = mysql_query("SELECT * FROM `yourtable` WHERE `username`='$row[username]'") or die mysql_error()); while($row2 = mysql_fetch_assoc($sql2)){ echo "$row2[id] || $row2[username] || $row2[email] <br />"; } } ?> Im not 100% sure this'll work - i've hardly used group and having clauses, but its worth a go. As i say, someone else will probably be able to show you a single query for doing this too.
  3. Hmm, try: <?php $first = 0; $last = 0; $first_found = 'no'; for($x=0;$x<=count($array);$x++){ if(!empty($array[$x])){ if($first_found=='no'){ $first_found='yes'; $first = $x; } if($x > $last) $last = $x; } } $min = $array($first); $max = $array($last); ?> Completely untested, and perhaps slightly rushed...i want to watch the apprentice. But hopefully it'll work.
  4. Thorpe is right here - if you're just checking to see if a character exists in a string, use strpos() - it's faster.
  5. I think all you need to do is get rid of some single quotes around 'country' in your query: <?php $query = "SELECT country, COUNT(latedeals) FROM properties WHERE latedeals NOT LIKE '' GROUP BY country ORDER BY RAND() LIMIT 25"; ?> When referring to table names, columns etc, you should either place nothing around the word, or use backticks(`). You'll need to use backticks if the name is a reserved word in mysql.
  6. Ok, just from a quick glance, would i be right in saying you're not getting this table_name from the database? In which case, you need to check your query. The best way is to put the query into a string, so you can echo it out. And dont forget the or die statement: <?php $query = "SELECT * FROM abc_tables INNER JOIN ad_order on abc_tables.table_id = ad_order.cust_id WHERE ad_order.order_id=$ad_num limit 1",$db_link); $get_tablename = mysql_query($query) or die(mysql_error()); echo $query; ?> That way, you can see exactly what query is being done.
  7. Yes, you must put session_start() at the top of everypage that makes use of the $_SESSION superglobal array. So therefore, if you are checking if someone is logged in, for instance, then every page will need session_start. If the page does nothing at all with sessions, you dont need it.
  8. Ok firstly, i would suggest that you echo your $msg variable instead of trying to email it. I would imagine your problem lies with your email rather than the variables.
  9. To answer your unrelated question, yes it is completely possible. You do it by passing variables in the url string. The best way to explain is through example i think. Say you have a link: http://www.yoursite.com/index.php?id=1 Then, in index.php: <?php $id = $_GET['id']; ?> Say you need to pass two variables, you simply add an & sign in between : http://www.yoursite.com/index.php?id=1&foo=bar As for your php file, yes - you save it and view the page. And it doesn't matter what you save it as. You will, of course, need to save all of the text files to get it to work too. You'll need to keep the names of those text files the same as the ones used in the php script, or modify the script.
  10. You were on the right lines, but ive cleaned up the code you had to make it a bit shorter and easier to follow (hopefully!) <?php $query="SELECT * FROM cocktails"; $result=mysql_query($query); while($row = mysql_fetch_assoc($result)){ echo "id: $row[id] | name: $row[name]<br><br />"; $ingredients_explode=explode("|",$row[ingredients]); foreach($ingredients_explode AS $ingredient){ $ingredient_parts = explode(',',$ingredient); $parts = $ingredient_parts[0]; $ingredient_id = $ingredient_parts[1]; //Im not sure how youre getting that vodka is id 1 etc im guessing a database table - in which case, select from there where your id is $ingredient_id } } ?>
  11. Thats ok, everyone's got to start somewhere. I would suggest, however, that you try and learn a few bits of php and mysql using some tutorials, before you attempt to expand on this script. There are some beginner tutorials here: http://www.phpfreaks.com/tutorial_cat/8/Basics-&-Beginner-Tutorials.php The second one looks like it could be what you're after - it looks like it includes all the basic mysql.
  12. Personally, i think you're far better off using Nhoj's method which simply uses a last active time to determine wether or not someone is online. By doing it with another table with users online, you'll just be adding to the amount of queries and processing that needs to be done.
  13. Well, if you are going to be using a database, then you might as well store the information on all the files that have been uploaded in the database too. If you are able to use a database, they are much more usefull than text files - they are faster and easier to work with. Do you have any experience with mysql?
  14. Ok, i suggest you make a table in your database containing all of the categories, then to build your drop down box: <select name="category"> <?php $sql = mysql_query("SELECT * from `categories`") or die(mysql_error()); while($row = mysql_fetch_assoc($sql)){ echo '<option value="'.$row['category'].'">'.$row['category'].'</option>'; } ?> </select> Then just retreive the category from the post array: <?php $category = $_POST['category']; $sql = mysql_query("SELECT * FROM `photos` WHERE `category`='$category'") or die(mysql_error()); ?>
  15. I wouldn't rely on http_referrer to tell you if the form is being submitted from your own website. Firstly, some browsers can be configured not to send referring information. Some firewalls also do the same. You will therefore be blocking some legitimate users. And second, headers can be faked. If, as im guessing that you're wanting to secure your form input in this way, then dont. You'll need to check all of your form data to make sure its valid.
  16. Exactly the way you normally would. All disabling a text field does is prevent the user from inputing data. Just get it from the post or get arrays, depening on the method of your submission.
  17. Well whats actually happening at the moment? Also do you think you could modify your post and put [ code] [ /code] tags around it so we get syntax highlighting; makes it a lot easier to read. One little problem i can spot, however, is this part: if (!isset($_SESSION)) { session_start(); } You should put session_start() before any attempt to do anything at all with sessions. As far as i can tell, the way you've set it up at the moment will probably prevent the sessions from being set when the person trys to log in. so just change it to session_start(); on its own. No need for the if statement.
  18. I would say its really not that stable at all. Firefox can be configured to not send http_referer information, and ive also known some firewalls preventing it from being sent. I investigated using it when i was making a text based game as a means of preventing people sending malicous data from other sources; but it really wasn't a good idea. You will find that legitimate users will suffer.
  19. Your problem is with this part: <a href="/community"> Was community supposed to be a variable? Either way, if you use the same quotes as are containing the entire string to be echoed, you'll need to escape them with a backslash: <a href=\"community\">
  20. You should be using a login system along with sessions and a login check on any pages that require membership for this sort of thing. Thats if ive understood what you were saying anyway
  21. Without lookig at your code, i would imagine the error is because you've forgotten the semi colon at the end of the previous line.
  22. You can use $_SERVER["HTTP_REFERER"] to get the reffering URL. Beware though, this can be spoofed and should not be used for security purposes.
  23. If you definately want to show the number of characters in the string, rather than just having a fixed number of asterisks, then i think you'll need two functions, and do it something like: <?php $str = 'mystring'; $first_letters = substr($str, 0, 2); echo str_pad($first_letters, strlen($str), "*"); ?> If you were to go with just a fixed number of asterisks, you could use substr_replace on its own.
  24. You'll need to post at least the code in that line and the line before. The most likely problem is that you forgot to add an semi-colon at the end of your last line. But it could be something else, so as i say, could we see some code?
×
×
  • 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.