-
Posts
3,145 -
Joined
-
Last visited
-
Days Won
37
Everything posted by cyberRobot
-
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%'"; } //... ?>
-
When searching by $make, what do you get? Does it display "Cannot run query.", "Sorry no canoes or kayaks can be found..", etc.?
-
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" /> ...
-
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/>'; ?>
-
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.
-
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...
-
You need to assign the result of number_format() back into the variable. <?php //... $shippingCost = number_format($shippingCost,2); //... ?>
-
How to convert the foreach loop in array using php?
cyberRobot replied to Xname's topic in PHP Coding Help
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 -
How to convert the foreach loop in array using php?
cyberRobot replied to Xname's topic in PHP Coding Help
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. -
How to convert the foreach loop in array using php?
cyberRobot replied to Xname's topic in PHP Coding Help
As mentioned in Reply #2, Xname looks to be doing something more complicated than my example...and the one mentioned in the original post. -
How to convert the foreach loop in array using php?
cyberRobot replied to Xname's topic in PHP Coding Help
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 ) -
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"; } ?>
-
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?
-
How to convert the foreach loop in array using php?
cyberRobot replied to Xname's topic in PHP Coding Help
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); ?> -
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){ //... ?>
-
Assuming that you don't want negative pricing, you could change the code to: <?php //... if(is_numeric($price) && $price > 0) { //... ?>
-
What is the error? If you display $arr and $dep to the screen to see if they contain what you expect?
-
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.
-
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.
-
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>"; ?>
-
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
-
Yep, anything that could potentially be tampered with by the user should be treated with caution. (GET / POST variables, cookies, etc.)
-
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
-
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'];
-
Google Custom Search is free, as long as you don't mind ads. http://www.google.com/cse/