cpd
-
Posts
883 -
Joined
-
Last visited
-
Days Won
5
Posts posted by cpd
-
-
I need it to where I don't always have to have a entry in there like this.
Sorry... what?
Yes
Great answer, care to share why?
If you NEED to use an XML file I suggest you do the following:
- Break your problem down into small problems, i.e. I need to create a file if it doesn't exist and append to one if it does.
- Tackle each problem individually, one-at-a-time.
- Comment your code so you, and others, know whats going on.
- Change "reports" to "report" as it contains report information not many reports.
- Define a Document Type Definition (DTD) to create a fully qualified XML document.
Once you've broken the larger problem down into smaller ones you will, hopefully, find its actually a really easy task.
Let me get you started
// Does the file exist? if(file_exists($file)) { // Yes, lets get its contents $xml = file_get_contents($file); } else { // No, lets set up a default $xml = "<entries></entries>"; //Should also contain the DTD and the XML definition. Perhaps have a default XML file. } // Lets load the XML into a DOMDocument object... $dom = DOMDocument::loadXML($xml); // Now lets append entries. This will be the same regardless of whether or not the file already exists.
-
One can only assume your system forces unique usernames, apply the same technique to your phone number field.
Otherwise, post only the relevant code.
Bambinou, do you understand what Jessica is saying here? By enforcing a UNIQUE constraint on the phone field within your table you'll achieve the basis of what you want. You can then implement php code to check for the phone number and display an error if it exists.
Moreover, why on earth were you attempting to create the table every time the script loaded? Think logically about what you're doing.
-
I'd start by restructuring your DOM; at the moment you have no encapsulation for each expandable section. Consider wrapping each section in a div and then using a single span to wrap the titles with an additional span tag around the [-/+] parts.
You can then write your JavaScript using the top node in each section, i.e. using the div that encapsulates each section, to manipulate the content within. I'd also suggest registering your event listeners in your JavaScript as opposed to inline although its not a big issue either way.
-
Something you should note: the cronjob runs the script, the script doesn't run the cronjob as your question implies.
-
This is simple file/directory testing stuff, i.e. you can use
file_exists($file)
and if it does, overwrite the .ini setting; be it temporarily or permanently. -
Take some time to learn PHPass; not much time need to be totally honest. It'll encrypt your passwords using a collection of techniques fundamental to good security.
-
I would consider using recursion to simplify your problem here as you have a 3 dimensional array. You need to consider how you want to display your data as well as this will affect the algorithm.
Example
function display(array $array) { $output = ""; foreach($array as $v) { $output.= (is_array($v) ? display($v) : $v); $output.= "<br />"; } return $output; }
You can then use this function by doing
$array = array(...); foreach($array as $v) { foreach($array as $v) { echo (is_array($v) ? display($v) : $v); echo "<br />"; } }
That said, if you're unsure of the depth of your array you should consider a different data structure and definitely not use this method as it could cause overflow issues.
-
Could you give us an idea of the bigger picture as this may not be the best way to handle your URL Rewriting if you need to rewrite multiple URLs.
-
Remove the "<select..." parts and in the while loop alter the "<option..." to be an input of type checkbox - really isn't that hard.
-
Print the SQL statement out and evaluate it. Its usually right before the first character in the error - i.e. its likely right before "Magnum".
-
You've got poorly chosen tag and attribute names there. Rethink the mark-up.
If you want to save the document I suggest you use the SimpleXML object as it contains a save method.
-
If you send POST data to the server, use
$_POST
- similarly if you send GET data use$_GET
.Currently you're posting and using
$_GET
within your script which will just fail. -
You've used
$row['number'];
so assuming that's what you meant and this is a uniquely identifying integer for the record then yes. -
All that's happening is you're setting a variable?
<script type="text/javascript"> img = (data['img'] == "" ? "IMAGE 1" : "IMAGE 2"); </script>
Is that what you meant?
-
if(($id % 2) == 0) echo '<td class="red">'; else echo '<td class="blue">';
-
From what you've said it sounds as though you'd merely return an array of data detailing the user information. A good object oriented design involves encapsulating data in the correct data structures with the correct visibility. For example the ID field of a user could be considered a property that shouldn't be overwritten and therefore you only provide a getter for that attribute. In contrast you could have the first and last name of a user that you want to be able to overwrite so you can write a getter and setter.
You can then appropriately manipulate the state of the object and commit it to the database via the ORM.
-
You're getting confused between your data model layer and your database layer; arguably one-in-the-same.
The logic for interacting with the database, i.e. the logic to actually run a query, should ideally be in a class of its own; this acts as a portal for all queries. A data model class wraps, normally, a single row from your query into an object. You can then pass this object between other objects to keep the information contained. If you want to pass multiple rows you can create an iterator and pass the iterator around.
Or perhaps have an iterator contained within the data model that, when iterated through, sets the fields to their appropriate values within the data model.
-
I'd recommend making use of the magic methods, particularly "__get()" and "__set()" as they're extremely useful for managing your variables when it comes to modeling your database; this essentially builds upon what trq said.
-
Adding to Jessica's comments; you'll probably use a lightweight method like Agile, RAD or something else for web development. That said if you're planning to create an entire system from scratch (effectively a framework) you'll be better off with a heavyweight method such as waterfall ensuring all development stages are traceable.
-
soo u r telling me that i have to program the core of php (classes and functions) and the database , and then design the website and create the interface between the users and the system (forms and buttons and all ) ?
Of course not...
If you rub this lamp it'll provide a genie that'll magic up all the code for you.
-
And you really need to work on your terminology.
...
Let's say I have a table, in MySQL, and it has one array.
...
A MySQL database does not contain arrays. PHP generates arrays based on the result set provided by MySQL.
-
Whilst I love MVC and its approach so solving many programming problems I don't think its the answer you're looking for. MVC is a way of structuring you're code, not a design process.
You need to look at your requirements and see what's already available. If something is available, how can you implement it? There are many frameworks, good and bad, available so look into them as they'll provide a rigid foundation for you to build your app on top of.
Its hard to give any further comments because everything starts at what your requirements are i.e. what you want to achieve.
-
An array holds many values not 1. Manipulating an array usually means altering its structure not merely taking its values and processing them. So again I ask, what do you want to actually do?
MySQLi is usually downloaded with PHP as one of its extensions but if not you can probably download it from PECL.
-
Needle in a haystack so post the error in future as well. In your function the "First name" and "Last name" lines don't end with a semicolon and moreover, you've not closed the input tag or string on either. Furthermore, using
$_SERVER['PHP_SELF']
can come with some nasty consequences so don't use it like you have.
PHP Search Result Help
in PHP Coding Help
Posted
Have you printed your query out? Its quite possible that because you're using LIKE with wild cards on both sides of the value and OR for everything there is a match for every row.
Print the query and show it to us along with some of your database data.
Posting a page of code isn't going to help, especially when its confusing as hell.