-
Posts
234 -
Joined
-
Last visited
-
Days Won
10
Everything posted by Sepodati
-
Why would I want the browser clicking something on my behalf? Sounds sketchy.
-
if ($row = mysqli_fetch_assoc($result) > 0) Take off the > 0 part. Stop storing plain text passwords and use prepared statements. This is very unsecure the way you have it.
-
You have the "id" of the product you're editing and each row has an "id". When they are the same, add the "selected" tag to the <option>.
-
The part you're worried about looks like it is. Make an array and then encode it.
-
Instead of building a string, build an array and then implode() it with commas. Or use substr() to get rid of the last character.
-
use keys from associative array in and update statement.
Sepodati replied to kk4iku's topic in Microsoft SQL - MSSQL
Sometimes the guess is right. -
If the file field is blank, as you're checking, then don't include that field in your update query. The field will retain it's current value. How are you naming the file fields?
-
use keys from associative array in and update statement.
Sepodati replied to kk4iku's topic in Microsoft SQL - MSSQL
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})"; -
Prevent pre-defined form fields from being empty
Sepodati replied to robkar32's topic in PHP Coding Help
if(empty($uid[$name]) && is_allowed_field($name)) { This comes out to false when you're dealing with $_POST['blabla']. empty() will return true, but is_allowed_field() will return false. Just like it did in the previous if() condition. You're better off using filter_input() (http://php.net/manual/en/function.filter-input.php) and checking each value independently. You lose the context of what you're checking when you attempt to automate the checks like this. -
How about showing the code you ran that didn't work (how did you interact with this class) and the exact error that came up?
-
That has nothing to do with building the array in the fetch loop.
-
regex question find pattern and replace part of pattern
Sepodati replied to Semnomic's topic in Regex Help
It's just a detailed print. More useful for arrays, but I used it out of habit. -
regex question find pattern and replace part of pattern
Sepodati replied to Semnomic's topic in Regex Help
Like this? <?php $mystring = 'cat-345-4345645678abcd-12abc'; $newstring = preg_replace('/-([0-9]{10})/', 'xx$1', $mystring); var_dump($newstring); ?> Output: string(29) "cat-345xx4345645678abcd-12abc" -
If you're asking whether you can insert 3 times for someone that has 3 ballots, that sounds like a bad idea. If it's not, then I don't understand the question.
-
That encode/decode in the middle there seems wasteful. Wouldn't this do the same thing? <?php $search_value=$_POST["search"]; $mysqli = new mysqli('localhost','root','usbw','mydb'); $myArray = array(); if ($result = $mysqli->query("SELECT * FROM transcriptome WHERE genename LIKE '%$search_value%'")) { while($row = $result->fetch_array(MYSQL_ASSOC)) { foreach($row as $key=>$value) { $myArray[] = array($key=>$value); } } //file_put_contents('jsonoutput.json', json_encode($myArray)); echo json_encode($myArray); } $result->close(); $mysqli->close(); ?>
-
How to auto create a new page based on inputs
Sepodati replied to martijnschuman's topic in PHP Coding Help
<input type="activiteit" placeholder="Activiteit"> This needs a name and needs to actually be inside the <form> tags. Then read here for how to handle file uploads: http://php.net/manual/en/features.file-upload.php -
Maybe answer the "why" you think you need to do this, then?
-
Is that one row of the results from the query? And you want each column to be an object? Is that how I'm reading this? Any reason why? Oh, nevermind... as Req said. <?php $myarray = array('one'=>1,'two'=>2,'three'=>3,'four'=>4); $newarray = array(); foreach($myarray as $key=>$value) { $newarray[] = array($key=>$value); } echo json_encode($newarray); ?> Output: [{"one":1},{"two":2},{"three":3},{"four":4}]
-
Sounds like I gave too many details, then!
-
PHP script, selecting and inserting into mysql without duplicates
Sepodati replied to thenorman138's topic in PHP Coding Help
Depends on exactly how you retrieve them in the query, but you'd likely build it something like $insert[] = "({$row['sessionid']}, {$row['name']}, {$row['number']})"; within the loop, for each row, then implode() that $insert array with a comma value when you're ready to tack it on to the end of the actual query. $query = "INSERT INTO proddb.tablename (sessionid, name, phone, ...) VALUES " . implode(',', $insert); Include your actual column names and make sure the number of columns listed matches the number of values in each VALUE () element and all that jazz. This is just an example. -John -
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
-
PHP script, selecting and inserting into mysql without duplicates
Sepodati replied to thenorman138's topic in PHP Coding Help
To borrow from ginerjm's syntax, the first query is going to be Query 1: SELECT MAX(sessionid) FROM proddb.tablename Retrieve that value into say $max. Then the second query would be Query 2: SELECT * FROM phonedb.tablename WHERE sessionid > $max Now, you'll check if there are any returned rows and if there are, start looping through them. Your goal would be to create a query in this syntax: Query 3: INSERT INTO proddb.tablename (sessionid, name, phone, ...) VALUES (1234, 'John', '555-555-5555'), (1235, 'Bob', '666-666-6666'), (1236, 'Roger', '777-777-7777') where you build each "value" set as you loop through the results of query 2 and execute a single query when you're all done. This is basically the same as what ginerjm is saying, but I don't think you can select from two different servers in the same query, as his example does. Two databases on the same server, yes, but not two servers. -John -
PHP script, selecting and inserting into mysql without duplicates
Sepodati replied to thenorman138's topic in PHP Coding Help
Sounds like you first want to get the max SESSIONID from your local table, then select all the rows from the remote table with a SESSIONID greater than than that value. Then loop through and create an INSERT to put them into the local table. EDIT: Or, I remember being able to select into a file, at which point you could then import that file into the local database. Still all within PHP, but rather an looping and creating inserts, you're just dumping & importing. -
PHP script, selecting and inserting into mysql without duplicates
Sepodati replied to thenorman138's topic in PHP Coding Help
Now that that's established, how do you determine what is new in the phone database? Is there any date information or is it only because it's not in your local copy? -
For the data group you listed, what exactly are you expecting to see? Age group 20 has three values... what do you want the result of your query to be based on this data? My Database: AGE Consumer Spending Discount ------ ---------------------------------------- 13 10% 20 30% 60 90% 20 10% 13 10% 20 40%