-
Posts
234 -
Joined
-
Last visited
-
Days Won
10
Community Answers
-
Sepodati's post in do-while not working as it should.. was marked as the answer
Your logic is flawed. The loop will only continue if the conditions evaluate to true. $headcount is not equal to 2 and $loopcount is not equal to 5, so the condition fails and the loop exists after the first go.
What I think you want is the loop to continue while $headcount is less than 2 or $loopcount is less than 5.
-
Sepodati's post in use keys from associative array in and update statement. was marked as the answer
You can use array_keys() to get the keys from order and then build your IN clause using implode
$key_string = implode(',', array_keys($order); $sql_update="update salesorders set ompOrderApproval= -1 where order_id in ({$key_string})"; -
Sepodati's post in Dynamic table by column was marked as the answer
Focusing on the math here, instead of counting from 100 to 1, you're going to count in two loops, based on the $columns value the user wants and the numbers of $rows (100/$columns) that are necessary.
So if you have 3 columns, you'll have 33.333 rows, which you round up to 34 rows. With 5 columns, you have 20 rows. Some of the final cells in the final row may be empty, since the columns may not evenly divide into 100.
Your outer "row" loop ($r) is going to count from 100 down to (100-$rows).
Your inner "column" loop ($c) is going to count from 0 to ($columns - 1).
For each column loop, you output the values related to ($r - ($c * $rows)). So the first time, you're showing (100 - (0 * 34)) = 100 in the first cell, (100 - (1 * 34)) = 66 in the second column and (100 - (2 * 34)) = 32 in the third column. You'll notice that should be 33, so you'll need to play with the math here as you sort this out. Probably need a +1 in some places and remember the rounded-up and rounded-down $rows value.
If ($r - ($c * $rows) < 1, then output a blank cell.
Combine those two loops and you output 34 * 3 cells, with some of the last ones being blank, when the user requests 3 columns.
There are probably much easier ways to do this with some fancy CSS or something, but from a purely math standpoint in determining rows & columns from arbitrary user input, that's how I'd do it.
-John
-
Sepodati's post in how do I exit script if there is no sql results and echo "no Results Found" was marked as the answer
Fix your data BEFORE it goes in the database so you don't have to do all that ltrim, rtrim, replace crap on the way out.
As for the loop, either check that there are rows returned, as mentioned above, or use this method:
if($row = odbc_fetch_array($result)) { echo "<table><tr>"; echo "<th>CustID</th>"; echo "<th>OrderId</th>"; echo "<th>Amount</th>"; echo "<th>TotalAmount</th></tr>"; do { echo "<tr><td>{$row['cust_num']}</td>"; echo "<td>{$row['name']}</td>"; echo "<td>{$row['city']}</td>"; echo "<td>{$row['state']}</td></tr>"; }while($row = odbc_fetch_array($result)); echo '</table>'; } else { echo 'No results found.'; }I don't like echo'ing HTML and you'd probably want to use htmlentities() if you're not doing any sanitizing of the data before it goes in. but that should give you a structure idea. -
Sepodati's post in Both fields update automatically? was marked as the answer
https://dev.mysql.com/doc/refman/5.7/en/timestamp-initialization.html
-
Sepodati's post in Third tier quotes ? was marked as the answer
https://3v4l.org/VJoGS
echo '<a href="http://www.example.com" target="_blank"><img src="http://www.petmd.com/sites/all/modules/breedopedia/images/thumbnails/cat/tn-sokoke-forest-cat.jpg" class="img-tipso" data-tipso-title="Tooltip title" data-tipso-content="<img src=\'http://www.petmd.com/sites/all/modules/breedopedia/images/thumbnails/cat/tn-sokoke-forest-cat.jpg\'/>">'; -
Sepodati's post in RETURN Ends The Script Flow Regardless If Result Is TRUE/FALSE? was marked as the answer
How is that confusing to you?
-
Sepodati's post in Recieving error PHP was marked as the answer
You can't remove the if() condition and leave the related "else" code.
-
Sepodati's post in Get text from last set of parentheses was marked as the answer
Well, preg_match_all() will give you all of the matches and you could just display the last one.
If the match is always at the end of the string, you could still use preg_match() and change your pattern to '#\((.*?)\)$#', where adding the '$' means the end of the line.
Or, a bit hacky, but you could strrev() the string, use preg_match() as you are and then strrev() the match to display it correctly.
-
Sepodati's post in Read code from variable was marked as the answer
If that's the case, then it should be this:
<?php @readfile('localhost/mysa_output.php?r='.$_SERVER['REMOTE_ADDR'].'&h='.urlencode($_SERVER['HTTP_HOST']).'&rf='.urlencode($_SERVER['HTTP_REFERER']).'&show_ad='.$ad_id); ?> -
Sepodati's post in Validation of html drop down select option was marked as the answer
Use a lower case "s" in $_POST['submit'] to match what you named the element. It's case sensitive.
-
Sepodati's post in Select dialog box doesn't display top entry was marked as the answer
$table_ex_entries .= "<td><select width='250' name='cat" . $x . "' value='" . $selected . "</select></td>";should be
$table_ex_entries .= "<td><select width='250' name='cat" . $x . "'>" . $selected . "</select></td>";-John -
Sepodati's post in limit the number to two decimal places 10.2345 and remove the . would be 1023 was marked as the answer
Sounds like you just want the floor() of the number * 100.
Kind of raises the question of why you'd do this to floating point numbers, though...