-
Posts
3,404 -
Joined
-
Last visited
-
Days Won
55
Everything posted by Ch0cu3r
-
That is what you need. Just make sure $count = 1; is outside of the loop! Otherwise it will reset the counter on each iteration
-
The error is self explanatory. For the ON clause you are referring to a column called user_id from a table called Post in your database. MySQL cannot find that column in that table and this is why you are getting that error. Make sure you have supplied the correct table/column names. You cannot delete topics/posts. Only admins/mods can delete topics/posts. We do not reponds to requests for topics/posts to be deleted unless they are against the forums Rules and ToS
-
No idea why, but variables in a double quoted string can be wrapped in curly braces, usually they are only required for more complex variables names such as arrays/objects, example echo "Welcome, {$_SESSION['username']}"; It just explicitly points out to PHP the start/end of a variable name. You've just contradicted yourself If you knew what it does then you wouldn't need to ask that question.
-
Well you need to alter the example queries I provided so the table/column names match the ones you're using in your actual database! Also why are you using globals in a class? If your class requires the $pdo object you should pass it to the Article object on initiation and define it as a class property, this is refereed to as Dependency Injection, Example class Article private $db; public function __construct(PDO $db) { $this->db = $db; } public function fetch_all() { $this->db->prepare(... ); // ...etc } } $pdo = new PDO(... ); $article = new Article($pdo); // pass the pdo instance on object initialisation $articles = $article->fetc_all();
-
Apply a LIMIT to your SQL query, eg SELECT * FROM articles LIMIT 4 Again modify you SQL query which orders the results by the article id or publishing date in descending order, example SELECT * FROM articles ORDER BY article_id LIMIT 4
-
Brain fart moment . It should be like $endtime = date('Y-m-d H:i:s', strtotime("+$type minutes", strtotime($start)));
-
The third line needs to be $endtime = date('Y-m-d H:i:s',strtotime($start, "+$type minutes")); No need for the quotes
-
You need to call the SelectTea method first, which then calls the AssignTea method, which then sets the value for the current_tea property $tea = new Tea(); $tea->SelectTea(); var_dump($tea->current_tea);
-
So you want to ignore rows where the 4th column has value less than 10? In that case you'd do something like this $data = array(); if (($handle = fopen("data.csv", "r")) !== FALSE) { while (($row = fgetcsv($handle, 1000, ",")) !== FALSE) { // only add rows to the array where the 4th column value is greater than or equal to 10 if($row[3] >= 10) $data[] = $row; } } }
-
Because you're using array_key_exists wrong, In fact you dont even need to use that function. All you need to do is check the value of $key is less than 5 foreach($data as $key => $val) { if($key < 5) unset($data[$key]); }
-
easy problem, i think ;/ selection menu not showing rows
Ch0cu3r replied to loxfear's topic in PHP Coding Help
PHP code does work in .html files (unless the server is confgured to do so). I suggest to rename your file so it ends in .php If you are new to PHP I highly recommend you to learn PDO or MySQLi. -
easy problem, i think ;/ selection menu not showing rows
Ch0cu3r replied to loxfear's topic in PHP Coding Help
Looking at the code it should be populating the menu with the results of the query. For why it is not working there could be an error with your query, which you have not checked for. $sql = mysql_query("SELECT title FROM aktiviteter"); // check query did not return an error if(!$sql) trigger_error('DB Error: ' . mysql_error(), E_USER_ERROR); Also you only need to include sqlconnect.php once, there is no need to include it each time you perform a query. Having said that though you should really change your code over to PDO or MySQLi. The mysql_* functions are deprecated and no longer supported, which means they could be removed from future versions of PHP. So this would be good time change. -
So you're reading an XML file and wanting to add the values to a db? If so You're barking the wrong tree there. You need to use the DOM Object
-
You'd perform a SELECT query returning the record where the EmpID matches the name dropdown menu value submitted by your form. Example if(isset($_POST['EmpID')) { $EmpID = intval($_POST['EmpID']); $result = mysql_query('SELECT EmpID, FirstName, LastName, Pay FROM Employees WHERE EmpID = ' . $EmpID; list($FirstName, $LastName, $Pay) = mysql_fetch_row($result); // output form echo '<form method="post"> Firstname: <input type="text" name="FirstName" value="'.$FirstName.'" /><br /> Lastname: <input type="text" name="LastName" value="'.$LastName.'" /><br /> Pay: <input type="text" name="Pay" value="'.$Pay.'" /><br /> <input type="hidden" value="'.$EmpID.'" name="EmpID" /> <input type="submit" name="submit" value="Update" /> </form>'; }
-
Not very clear from where I'm sitting. Can you post a better example
-
undefined Variable Issue due to moving servers
Ch0cu3r replied to rachae1's topic in PHP Coding Help
That is what it should of been in the first place (and should of never existed). It has been disabled by default since 4.2.0 which was release over 14 years ago! Instead you need to get the input from the corresponding superglobal variable -
You could apply an onSubmit event to the form which will selects all the items in the second menu. Why not have a go and see if you can implement that with the for loop code I provided earlier.
-
You will need to loop through all the items in the second list and apply the selected attribute to true for each option. To do so add the following code before return false; in the AddItemInList function for(i = 0; i < list2.length; i++) { list2[i].selected = true; }
-
Code works fine, the problem is the items in the second menu needs to be selected before the form is submitted in order for the chosen options to be submitted.
-
What do you mean that?
-
Id advise not to use addslashes for escaping user input. Instead use mysql_real_escape_string Or preferably change your code over to PDO or MySQLi and use prepared statements. Please note that the mysql_* functions are deprecated which means they are no longer supported and could removed from future versions of PHP.
-
forget to attach image? But yes that HTML is invalid, there is no need for for the anchor tag at all. Just apply the large-button class to the input instead and you'll get the same result. Also what should the button-glare class be doing? Currently it not doing anything other than position and resize an empty div other the top of the container div.
-
It is describing the data type of the bound value.
- 3 replies
-
- pdo::param_int
- pdo
-
(and 1 more)
Tagged with:
-
This is where you'll now need to apply Jacques1 advice and produce the graphs using AJAX. So you'd apply an onchange event for your dropdown, when the user makes a selection you'll then run an AJAX request which will pass the department id to your php code, which will then get graph results for that department from your database and return the results in JSON format. You'd then retrieve the response of the ajax request and pass that to amchart for plotting the graph.