Jump to content

Psycho

Moderators
  • Posts

    12,146
  • Joined

  • Last visited

  • Days Won

    127

Everything posted by Psycho

  1. You need to learn how to do JOINS in your queries. NEVER do looping queries - it is terribly inefficient and a resouorce hog. Also you will do yourself a great favor by using descriptive variable names. This "should" get what you want. I can't test it becuause I don't have your table structures, but the logic is sound. <?php //Only 1 query needed $query = "SELECT COUNT(*) as votecount, candidates.id as c_id, candidates.name as c_name, regions.id as r_id, regions.name as r_name FROM newvotes JOIN candidates ON newvotes.answerid = candidates.id JOIN regions ON newvotes.regionid = regions.id GROUP BY candidates.id, regions.id ORDER BY candidates.name"; //Run the query $result = mysql_query($query) or die(mysql_error()); //Display the results $current_candidate = ''; while ($record = mysql_fetch_assoc($result)) { if ($current_candidate!=$record['c_name']) { $current_candidate==$record['c_name']; echo "<b>$current_candidate (".$record['c_id'].")</b>\n"; } echo " --- Region: " . $record['r_name'] . "(".$record['r_id']."), "; echo "Count: " . $record['votecount'] . "<br>\n"; } ?>
  2. Change $prevSelectedbirthmonth withthe default value you want. <?php for($i = 1; $i <= 12; $i++) { $selected = ($prevSelectedbirthmonth==$i)?' selected="selected"':''; echo ($i < 10) ? '<option value="0'.$i.'"'.$selected.'>0'.$i.'</option>' : '<option value="'.$i.'">'.$i.'</option>'; } ?>
  3. Hmm, I don't use printf much, this uses str_pad echo "<option value=\"{$optVal}\"{$selected}>" . str_pad($optVal, 2, '0', STR_PAD_LEFT) . "</option>";
  4. <select id="day" class="input" name="DateOfBirth_Day"> <?php for ($optVal=1; $optVal<32; $optVal++) { $selected = ($day==$optVal)?' selected="selected"':''; echo "<option value=\"{$optVal}\"{$selected}>" . printf('%02s', $optVal) . "</option>"; } ?> </select>
  5. <?php if ($handle = opendir('/home/ectackle/public_html/uploader/uploaded_files/')) { while (false !== ($file = readdir($handle))) { if (preg_match('/\.jpg$/', $file)) { echo "<a href='$file' onclick='return hs.expand(this)' class='highslide'>\n"; echo "<img src='show_image.php?filename=$file&width=100&height=100' alt=''/>\n"; echo "</a>\n"; } } closedir($handle); } ?>
  6. You were not being a jerk (and it was not my intention to be one either). I just wanted to emphasize that stating ALL of your requirements up front prevents a lot of rework and gets you a solution faster. It would ahve been just as much work for me to provide all of your requirements instead of having to go back and rework it.
  7. From my experience adding that tot he actual field is not worth the time, effort or greater propensity of error. Just put the symbol right in front of the field Example: __________ Salary £ [__________]
  8. Does that background color have to be part of the image? You could just put the image in a DIV with the color. I know it's not what you asked for, but just a thought. EDIT: This should be what you want: http://us.php.net/manual/en/function.imagecopymerge.php
  9. <?php case "250GSMAGL1": $Cover_package = "250 GSM Artboard Gloss Laminated 1 Side"; $Covpackage = 1.18; if ($quantity == 500) { $Covpackage2 = 70; } else if ($quantity == 1000) { $Covpackage2 = 130; } break; ?> Of course depending on your needs and requirements you could do something with arrays or functions. But, not enough information given to provide much else.
  10. You should really be handling the user type withint he database instead of hard coding it like this. But here you go: function get_admin($user) { switch (strtoupper($user)) { case 'STEPPIO': $bgi = '1'; break; case 'FRANK': $bgi = '1'; break; case 'KARL': $bgi = '1'; break; case 'SAM': $bgi = '1'; break; case 'KRIS': $bgi = '1'; break; default: $bgi = '2'; } $_SESSION['admin'] = $bgi; return $_SESSION['admin']; }
  11. I really like helping people out, but it irks me when someone gives requirements for a solution they need, then when provided a solution, they change the requirements. I don't meant to be a jerk, but it seems rude to me when someone does that. I'm sure that was not your intention, but it is always appreciated to get the full requirements up front instead of usign the forum for design. validName = /^[a-z0-9]+([\ ]?[a-z0-9])*$/i
  12. Get rid of the first half of your page and change the second query to sort by featured instead of making it a WHERE requirement. FYI: Your IF/ELSE to determine the page needs some validation to ensure it is a number. ALWAYS validate user input whether it is coming from GET or POST. <?php function showdirectoryfree($category) { if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } $max_results = 5; $from = (($page * $max_results) - $max_results); $query = "SELECT * FROM accounts WHERE category='$category' ORDER BY featured, companyname LIMIT $from, $max_results"; $result = mysql_query($query) or die (mysql_error()); while($row = mysql_fetch_array($result)) { echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\" class=\"bodyFont\">"; echo "<tr>"; echo "<td><b><span class=\"companyNameFont\">" . $row['companyname'] . "</span></b></td>"; echo "</tr>"; echo "<tr>"; echo "<td>" . $row['address'] . ", " . $row['postcode'] . "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>Tel: <b>" . $row['telephone'] . "</b></td>"; echo "</tr>"; echo "<tr>"; echo "<td colspan=\"2\" bgcolor=\"#FFFFFF\"><a href=\"http://www.multimap.com/map/browse.cgi?client=public&search_result=&db=pc&lang=&keepicon=true&pc=". $row['postcode'] ."&advanced=&client=public&addr2=&quicksearch=" . $row['postcode'] . "&addr3=&addr1=\" target=\"blank\">Map/Directions</a> - <a href=\"/marketplace/sendemail/sendemail.php?emailto=" . $row['username'] . "\" onClick=\"return popup(this, 'notes')\">Send E-Mail</a></td>"; echo "</tr>"; echo "<tr>"; echo "<td align=\"left\"><hr width=\"100%\" size=\"1\" noshade=\"noshade\"/></td>"; echo "</tr>"; echo "</table>"; } $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM accounts WHERE category='$category'"),0); $total_pages = ceil($total_results / $max_results); echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" id=\"pagenumberBox\" class=\"bodyFont\">\n"; echo "<tr>\n"; echo "<td align=\"center\">\n"; if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev&category=$category\">Previous</a>\n"; } for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i \n"; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i&category=$category\">$i</a>\n"; } } if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next&category=$category\">Next</a>\n"; } echo "</td>\n"; echo "</tr>\n"; echo "<tr><td align=\"center\"><a href=\"/marketplace/index.php\">Return to Marketplace</a></td></tr>\n"; echo "</table>\n"; } ?>
  13. What IS the function showing? Is it shawing A time/date? Are you running this off a remote web server? If so, that server may very well be in a different time zone than you are. If you need the time to always be in YOUR time zone you will need to offset the current time accordingly. If you need the time to be in the USER'S time zone you would need to know that user's time zone in order to offset the time for each user.
  14. Or shorthand <?php $value = ($_SESSION['sessionval']==true) ? true : false; ?>
  15. Yes, they are doing the same thing. In the first example, the URL has specified the directory, but not the file, so the web server will attempt to load the "default" file in that directory based upon the default list. Usually something like: index.php, default.php, index.htm, etc. So the first one is actually referring to something like: index.php?state=logout The second example has identified the file (page.php) in addition to the parameters
  16. You want to prevent 55% of all users from accessing your site? Interesting. You could use the $_SERVER['HTTP_USER_AGENT'] predefined variable to determine the browser.
  17. Would you not want to trim the leading and trailing spaces off? Anyway, here is what you asked for: <html> <head> <script type="text/javascript"> function validate(inputStr) { var inputAry = inputStr.split('\,'); var outputAry = new Array(); validName = /^[a-z0-9]+[a-z0-9\ ]*[a-z0-9]+$/i for(var i=0; i<inputAry.length; i++) { if (validName.test(inputAry[i])) { outputAry[outputAry.length] = inputAry[i]; } } var outputStr = outputAry.join(','); return outputStr; } </script> </head> <body> Input:<br> <textarea id="input">player1, player2, player3,player4</textarea><br><br> Input:<br> <textarea id="output"></textarea><br><br> <button onclick="document.getElementById('output').value=validate(document.getElementById('input').value);">Test</button> </body> </html>
  18. Or include all "sections" in one form and use DHTML to change from one section/slider to another. You can eitehr continue to do the validation via AJAx for each sectiona independently and/or do it within the JavaScript.
  19. I don't see where $_SESSION['mls'] is used in that code at all (or any session values for that matter). So, how would you know the value has been altered when you don't even use it?
  20. I have an email validation expression that works, but I want to see if there is a way to refine one part and/or add one additional check. Here is the expression: /^[\w\+-]+([\.]?[\w\+-])*@[a-zA-Z0-9]{2,}([\.-]?[a-zA-Z0-9]{2,})*\.[a-zA-Z]{2,4}$/ The BOLD blue section ensures the username consists of 1 or more valid characters (alpha, numeric, '_', '+', '-') The blue section allows the user to have zero or more sub elements (separated w/ a period) with the same valid characters The BOLD red section ensures the domail consists of 2 or more valid characters (alps, numeric) The red section allows the domain to have zero or more sub domains (separated w/ a period or '-') and the same valid characters [yes, the dash is not a sub-domain delimiter, but it is not acceptable at the begining or end of a domain just like the period] The BOLD green section ensures the TLD consists of 2 to 4 acceptable characters (alpha or numeric) So, my question are: 1) Can the blue sections be combined more efficiently into one such that the usrename can accept a period, but not at the beginning or end, and cannot appear in succession? 2) Can the red section be combined into one such that a period or dash cannot be at the beginning or end - and they cannot appear in succession of each other? 3) How can I add a minimum/maximum check to the entirety of the blue section and/or the (red + green sections)? I want to ensure the username is between 1-64 characters and the domain is between 5-255 characters. Currently for #3 I am using a second regex test as follows: /^(.{1,64})@(.{4,255})$/
  21. It would be very helpful if you were specific in your questions. mgallforever, gave you a solution for your first question as posed, but then you changed the request. I then gave you a solution but you now say it does not meet your needs because of a requiremetn that you did not state. You state that you want to know "whick link" was clicked on that page. Does that mean there are multiple links on that page that go to the same palce? It would be helpful if you explained what you are trying to accomplish. One "possible" solution would be to not have those links go directly to the intended page. instead have them go to separate intermediary pages: Instead of: <a href="nextpage.php">Link 1</a> <a href="nextpage.php">Link 2</a> Use this: <a href="nextpage1.php">Link 1</a> <a href="nextpage1.php">Link 2</a> And then for those pages (nextpage1.php & nextpage2.php): include(nextpage.php) You could then add code on those pages to 1) verify they are coming from the appropriate page and 2) know which link they clicked.
  22. That's because $row will never be empty. If there are no records that code never goes inside the first IF loop. Also there is some duplicity in that code.: Try this: <?php $q = mysql_query($sql) or die("Error running query:".mysql_error()); if($row = mysql_fetch_array($q)) { echo "<img src='http://www.runningprofiles.com/members/images/thumbs/". $pid . "." . $row['ext'] . "'"; } else { echo "<img src='http://www.runningprofiles.com/members/images/noimage.jpg>"; } ?> Edit: Since you do this if($q && mysql_num_rows($q) > 0) { This is kind of irrelevant if(!empty($row)) {
  23. Sure, put a variable on the URL of the link and check it on the receiving page: LINK: <a href="somepage.php?switch=true">Click Me</a> PROCESSING PAGE: <?php if ($_GET['switch']=='true') { //Link was clicked } else { //Link was NOT clicked } ?> This is not a 100% guarantee, since the user can type the url and the varialbe as well, but would be OK for most usage.
  24. Really? that makes no sense, because your loop is continually adding to the $keys and $values arrays. The way you had it before would first process all the values from the first array - then it would process all the values from the first & second arrays. You really haven't provided enough information to help you.
  25. Sorry, but I'm not going to invest a ton of time doing all this for you. this forum is for people who want help with their code. You can incorporate as many questions as you want, just create the code to pull and display the question and answers. I only put one question in repeated multiple times to concentrate on the functionality you asked for. Good luck.
×
×
  • 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.