Jump to content

cyberRobot

Moderators
  • Posts

    3,145
  • Joined

  • Last visited

  • Days Won

    37

Everything posted by cyberRobot

  1. After thinking about the query a little more, the problem is most likely due to the OR part. You're asking to get all results which match part of the make or model field. If one of those fields is blank, you'll get all results. Try changing the query to something like: <?php //... $sqlCombine = ''; $sql = "SELECT * FROM canoes WHERE "; if($make != '') { $sql .= "make LIKE '%$make%' "; $sqlCombine = ' OR '; } if($model != '') { $sql .= "{$sqlCombine}model LIKE '%$model%'"; } //... ?>
  2. When searching by $make, what do you get? Does it display "Cannot run query.", "Sorry no canoes or kayaks can be found..", etc.?
  3. Did you try displaying $make to verify that it contains what you expect? Are you getting any errors...what happens when you try searching with $make? FYI, the <label> tags won't work unless the id attribute is added to the corresponding input fields. For example: ... <label for="make">Make:</label><input type="text" name="make" id="make" /> ...
  4. You could try something like the following: <?php $uid_data = ''; $name_data = ''; $teamname_data = ''; $coins_data = ''; $cash_data = ''; for($i=0;$i<=25;$i++) { if($i%5==0) { $uid_data .= "<td>uid$i</td>"; $name_data .= "<td>name$i</td>"; $teamname_data .= "<td>teamname$i</td>"; $coins_data .= "<td>coins$i</td>"; $cash_data .= "<td>cash$i</td>"; } } print '<table>'; print "<tr><th scope='row'>U_Id</th>$uid_data</tr>"; print "<tr><th scope='row'>Name</th>$name_data</tr>"; print "<tr><th scope='row'>Teamname</th>$teamname_data</tr>"; print "<tr><th scope='row'>Coins</th>$coins_data</tr>"; print "<tr><th scope='row'>Cash</th>$cash_data</tr>"; print '</table><br/>'; ?>
  5. Does the table orientation matter? After thinking a little more, it would be easier to do something like: U_IdNameTeamnameCoinsCash uid1name1teamname1coins1cash1 uid2name2teamname2coins2cash2 ............... Also, the above setup would be better for large data sets. The other way could get too wide to fit on the screen.
  6. So instead of: U_Id: uid1 Name: name1 Teamname: teamname1 Coins: coins1 Cash: cash1 U_Id: uid2 Name: name2 Teamname: teamname2 Coins: coins2 Cash: cash2 ... Do you want? U_Id:uid1uid2... Name:name1name2... Teamname:teamname1teamname2... Coins:coins1coins2... Cash:cash1cash2...
  7. You need to assign the result of number_format() back into the variable. <?php //... $shippingCost = number_format($shippingCost,2); //... ?>
  8. Well it turns out that there is another option. Have you had a look at array_walk? http://php.net/manual/en/function.array-walk.php The function was mentioned by Barand in another post (Reply #11). http://www.phpfreaks.com/forums/index.php?topic=359090.0;all
  9. I only changed the code to demonstrate that the foreach loop should work. But based on the next part of the response, it sounds like you don't want to use a foreach loop... If the foreach loop gives you the desired results, why use a different solution? When performing the same task on the various elements in an array, a loop tends to be the best option.
  10. As mentioned in Reply #2, Xname looks to be doing something more complicated than my example...and the one mentioned in the original post.
  11. Other than the following errors, the code looks fine: <?php //... $result_array[] = $urls_links //<-- should be $url_links and is missing a semi-colon //... ?> But I would imagine this isn't your real code since you're getting results. The problem seems to be somewhere else in the code. With a few modifications to your example, the following gives me results from both elements in the $something array: <?php $result_array = array(); $something = array('http://www.google.com/','https://vimeo.com/'); foreach($something as $links) { $url_links = parse_url($links); $result_array[] = $url_links['host']; } print_r($result_array); ?> Output: Array ( [0] => www.google.com [1] => vimeo.com )
  12. Glad to hear. Note that since it sounds like $row->quantity will never be between 0 and 1, you could skip the second test: <?php //... if($row->quantity <= 0) { $output .= "~vooraf bestellen"; } else { $output .= "~op voorraad"; } ?>
  13. I'm pretty sure that preg_replace doesn't work like that. To use a comparison operator, you could do something like: <?php //... if($row->quantity <= 0) { $output .= "~vooraf bestellen"; } elseif($row->quantity >= 1) { $output .= "~op voorraad"; } ?> Will there ever be values between 0 and 1?
  14. Your code seems to work for me: <?php $something = array('A,B,C and D.', 'E,F,G and H.'); $any_array = array(); foreach($something as $anything) { $any_array[] = $anything; } print_r($any_array); ?> The output looks like: Array ( [0] => A,B,C and D. [1] => E,F,G and H. ) What does $something look like in your code? Also, is there something else that you're doing with the foreach loop? Right now the above code could be accomplished with a simple assignment operation: <?php $something = array('A,B,C and D.', 'E,F,G and H.'); $any_array = $something; print_r($any_array); ?>
  15. Never mind, I guess my suggestion doesn't really fix the problem. What are you doing with the global variable outside of the function? In your original post, the variable was inside the is_numeric if test: <?php //... if(is_numeric($price)){ global $currencyVars; //... ?> Does the duplicate label come from having it above the if? <?php //... global $currencyVars; if(is_numeric($price) && $price != 0){ //... ?>
  16. Assuming that you don't want negative pricing, you could change the code to: <?php //... if(is_numeric($price) && $price > 0) { //... ?>
  17. What is the error? If you display $arr and $dep to the screen to see if they contain what you expect?
  18. Have you looked into the "path" argument for setcookie? http://php.net/manual/en/function.setcookie.php The Parameters section for path talks about cookies being available for all sub-directories.
  19. That sounds like the text file wasn't imported. Did you double check that file() is pointing to the correct location? You could try adding the following line of code after the call to file(): <?php //... $lines = file('store.txt'); var_dump($lines); ...// ?> If it displays anything, you have the data from the text file. Otherwise, the content wasn't imported correctly. You should also check that the same variable is being used for the file(), sort(), and foreach() lines of code.
  20. You could use a switch statement: <?php //... echo "<tr bgcolor='"; switch($tank_name) { case 'Tank 1': echo 'yellow'; break; case 'Tank 2': echo 'red'; break; case 'Tank 3': echo 'blue'; break; } echo "'><td>$tank_name</td></tr>"; ?>
  21. Yep, that looks correct. Note that you'll still get numbers which are technically invalid, such as 0 or an ID that hasn't been used yet. That's where a solution like the one suggested by sunfighter in Reply 7 will be useful. Basically, you would [*]Make sure the ID is a number [*]If it's a number, make sure the ID is found in the database [*]If the ID was found, delete the record
  22. Yep, anything that could potentially be tampered with by the user should be treated with caution. (GET / POST variables, cookies, etc.)
  23. For what it's worth, you'll want to validate and sanitize any data that could be tampered with by visitors. In this example, the ID being passed could be modified to inject code into the SQL query. To prevent that, make sure the value contains an expected value. It sounds like the ID is supposed to be a number. You could use something like ctype_digit() to check that it is before querying the database: http://php.net/manual/en/function.ctype-digit.php If the ID contains text, do what you can to sanitize that value. Then use mysql_real_escape_string() on the variable before running the query: http://php.net/manual/en/function.mysql-real-escape-string.php
  24. The problem is probably caused be the following: $id=$_GET['ID']; Your anchor tag creates a GET variable which is lower case: <a href='remove_rec.php?id= Try $id=$_GET['id'];
  25. Google Custom Search is free, as long as you don't mind ads. http://www.google.com/cse/
×
×
  • 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.