Jump to content

amg182

Members
  • Posts

    130
  • Joined

  • Last visited

Everything posted by amg182

  1. <select name='drop'> <option "Input" value="choose from list"></option> <?php $combo = "SELECT field FROM table"; $result = mysql_query($combo) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo "<option value='". $row['field'] ."'>". $row['field'] ."</option>"; } ?> </select> Hope this helps
  2. Not sure if this is possible, but if anyone knows it's you guys. Can I echo out the logged in user profile name of a windows PC onto a webpage? for example "Welcome John Desktop". I can get it to echo out the PC Name but not the user currently logged in. Any help would be greatly received. Thanks in anticipation.
  3. Cheers guys, that worked a treat! Merry Xmas to you all. Aidan
  4. Hi guys. I need to destroy a session when a user leaves a particular page. I tried using session_destroy() at the end of the page but its not possible, because my page has pagination. i.e. abc.php?page=1 etc... So, I need to destroy a session when a user leaves abc.php page. Thanks in advance Aidan
  5. If you want some form of validation for your postcode consider this one way of doing it. It ensure the correct format is entered i.e Letter Numbers etc....(Uk Postcodes) function IsPostcode($postcode) { $postcode = strtoupper(str_replace(' ','',$postcode)); if(preg_match("/^[A-Z]{1,2}[0-9]{2,3}[A-Z]{2}$/",$postcode) || preg_match("/^[A-Z]{1,2}[0-9]{1}[A-Z]{1}[0-9]{1}[A-Z]{2}$/",$postcode) || preg_match("/^GIR0[A-Z]{2}$/",$postcode)) return true; else return false; } $codevalid=$postcode; if (IsPostcode($codevalid)) echo "Valid"; else echo "Invalid"; Hope this helps.
  6. Need much more info... are you referring to a mysql database table?
  7. You are a true gentleman! This is a great way to show error messages! Once again thank you ever so much, I really appreciate it- A credit to the forum!
  8. hi again. How would i go about placing one alert messagee if one or more fields are left blank/empty? i.e. A message saying "Please fill in ALL fields" I can manage to do it for each input field but obiviously not practical if there are 5+ fields left blank otherwise the user is bombarded wiht alert messages! Thanks again
  9. Thanks a million nogray! Worked a treat! Much appreciated
  10. Hi guys, any help with this would be much appreciated. I have some JS validating my form to check that the fields are not empty/balnk- if they are it will highlight the fields (using css classes). It is working fine but only highlights one empty field at a time. Is it possible to get it to highlight all the fields that are empty/blank? For example. If the user forgets to fill in 2 fields, it will highlight one field at a time. If the user then inputs something to that field and tries to submit it will then highlight the next filed. Instead, is it possible to have it highlight ALL empty fields? function validateForm() { var x=document.forms["advert"]["name"].value; if (x=="") { //changes class of li_25 to error class in order to highlight field document.getElementById("li_25").className = "error"; return false; } var x=document.forms["advert"]["email"].value; if (x=="") { document.getElementById("li_36").className = "error"; return false; } var x=document.forms["advert"]["age"].value; if (x=="") { document.getElementById("li_17").className = "error"; return false; } } Thanks guys
  11. Hi teynon. That worked a treat! Thanks a million mate!
  12. Hi. Complete beginer with java.... Is it possible to change a html class depening on variable using javascript. For example if a user left a form input blank then javascript would change the css class to highlight it red. Here is what i am working with: function validateForm() { var x=document.forms["form"]["fieldname"].value; if (x==null || x=="") { alert("Fields in red need to be filled in"); var class ="class='error'"; return false; } } Thanks guys
  13. Thanks Pikachu2000. This is much more effecient! I was going about this totally wrong. Oh well, its a learning curve...as you can see i have a lot to learn. Thanks again! A credit to the forum.
  14. I am trying to echo out a particular comment depending on what is entered witihn a form(text input). So if someone enters a value between 1-1000 it would echo out "Under 1000". The problem i have is that i users can enter a value between 0 - 100,000. Ideally i would like the text echo out to the nearest thousand so if someone entered 5400 it would echo out "under 6000". Any ideas? Thanks again.
  15. Thanks for reply, worked a treat. How could i add this to the array ? (5,10,'under 10') Thanks again
  16. Hi. I have an multidemesional array that looks like this: $numbers=array("1"=>'under 5',"2"=>'under 5',"3"=>'under 5',"4"=>'under 5'); Is it possible to write the array like this?(without using loops) $numbers=array("1-4"=>'under 5'); or even: $numbers=array("1,2,3,4"=>'under 5'); Thanks in advance.
  17. Oh I see, thanks. I will just have to move around my queries to sort my variables from top to bottom... Cheers guys. Appreciate it
  18. Apologies for such a silly question.... Been away from php for a long time... How can i call a variable from a position above where the variable is set? I need a variable to echo out near the top of my page but its defined near the bottom of my script. As you can see i am tryin to echo the amount of rows found from the query below. <?php echo $num_rows; $query = "SELECT Name, FROM table"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ $num_rows = mysql_num_rows( $result ); } ?> Thanks in advance
  19. Hi guys. Pleased to report back that by indexing the columns and making sure field types were the same worked a treat!(Thanks DavidAM) Before indexing Query took 0.0897 sec) after indexing Query took 0.0011 sec) This has restored the performance of the page back to its good old speedy self. Guys you are a credit to this forum, thank you!
  20. Thanks a million guys, some really useful information here. I will look into running the query from the database and see how it goes. Will post back results! mjdamato: I am using the where clause just for testing reasons. I meant to remove it before posting. Thanks again
  21. Hi guys. I have a SQL query running within my php. But if i add and inner join to link another table, it slows the performance(refresh, loading time) of the page by at least 2-3 seconds... I am working from localhost wampp serever. Should this happen when using inner Join? $sql="SELECT * FROM cars INNER JOIN postcodes ON postcodes.Pcode=cars.Location where id>='1'" Thanks in anticipation
  22. Legend! Floor +1 did the trick! Thank you so much, was going crazy trying to use ceil....
  23. Hi guys. I would like one of my varaibles ($VAR1) to have a paricular value depending on another variables value($VAR2). Example would be: if $VAR2 is between 0 - 9 then $VAR1 will =1 if $VAR2 is between 10 - 19 then $VAR1 will =2 if $VAR2 is between 20 - 29 then $VAR1 will =3 if $VAR2 is between 30 - 39 then $VAR1 will =3 etc.... As you can see it is for every VAR1 increment of 10 i would like to increase VAR2 by 1. i did try: $var1=ceil($var2 / 10); But this will only work if i have values of 1-10, 10-20, 30-40 etc... I hope this makes sense....
  24. thanks for replies. I have a form containg up to 13 select fields(comboboxes). I am writing an if statement to say if the comboboxs contains a value then disable it, otherwise leave it enabled. Here is the actual code i am working with: if ( $select1 != "" ) { $cond="disabled"; } else { $cond='onChange="filters.submit();"'; } ..... <form name="filters" id="filters" action="index.php?" method="post"> <td><Select name='select1' id=" <?php echo $cond; ?>> <option value..... Rather than write this if statement 13 times, i thought i would use a function instead. Sorry i over complicated things earlier, thought i would strip the code down to make it easier to interpret.(Done the opposite probably)
  25. Hi Guys. I am trying to call variables inside a function: Here is what i am trying to do, but doesnt like it? function disable($var1,$var2) { if ( $var1 == "" ) { $var2="disabled"; } } disable("$form", "$select"); Cheers
×
×
  • 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.