margaux
-
Posts
453 -
Joined
-
Last visited
-
Days Won
52
Posts posted by margaux
-
-
Sorry, I didn't read your original post properly. You need to check that the radio button is checked.
if (isset($_POST['Agree']) && $_POST['Agree'] == 'checked') ) {
- 1
-
if (isset($_POST['radio_Agree'])) {
should be
if (isset($_POST['Agree'])) {
- 1
-
You could do the division on the image size first and then set the width and height attributes on the img tag
$image_properties = getimagesize("uploads/orders.jpg"); $image_width = $image_properties[0]/2; $image_height = $image_properties[1]/2; echo "<img src=\"uploads/orders.jpg\" width=\"$image_width\" height=\"image_height\">";
- 1
-
As well as creating a site about a topic you're interested in, you could create your own site which would include your portfolio (just make it up initially), a blog which you hand code rather than using something like wordpress or joomla, a contact form, social media links and an xmlfeed. Other ideas are to do some sites for local charities or community projects.
Regards software - I use a basic text editor, TextWrangler. It provides colour coding for different languages which is very useful. I've heard very good things about TextMate and keep meaning to have a look at it.
-
I would just always select the X latest rows and let it be with that. DBMS systems can handle huge sets of data, so I would not worry about that. If it should become a problem, run a clean up function once in a while instead.
That seems like a better approach but how does that cater for items that are no longer on the feed but will still be on the database and returned by search queries?
-
I also agree that its ugly but once I used it for some lengthy php/ html mix and I was converted. Is it bad form or just not pretty?HEREDOC is cool but for me it is a little ugly, may come to use it though.
I do too. For different situations its good to have a couple of options you can fall back on to make things simpler.for simpler stuff like the price, name and description it seems easier to just concatenate.MVC - stands for Model, View, Controller. Its a programming approach to keep your code organised and easier to maintain especially good when working on large sites involving many people. Many frameworks follow this approach. The model is the data, the view is the presentation and the controller is the logic that binds the model and the view. As an analogy think of good website development - you separate the html from the css and the javascript so you are not mixing presentation with styling with behaviours.
- 2
-
There are a number of ways you can code this. Personally, if I'm coding alot of html mixed with php processing and variables I don't use echo. When you need to some php processing, just insert it within <?php and ?> tags. Be sure to not use the shortcode tags as they have been deprecated.
<table class="myclass"><tr><td><input name="display_y" type="radio" value="Yes" checked=" <?php if($snippets_list['display']='y'){echo 'checked';} ?>"/></td></tr></table>
An alternative is to use echo with the heredoc syntax.
- 2
-
I'm working on a site which reads in data from an xml feed and creates a d/b table. The feed is continually being updated so the table also has to be updated frequently. I think the feed will be accessed several times/hour to refresh the database. Is the better approach to
1. Drop the table and recreate from fresh everytime the feed comes in. This ensures that the database doesn't continually grow with items that have already been stored. However how will site visitors be affected if the table is being created while they're viewing?
2. Create the table once and update it subsequently. Check for each item's unique reference - if it exists then overwrite it, that way you pick up any changes to the item. This approach seems less attractive from a speed point of view. Also it means that items that are no longer on the feed will still be on the table and there will have to be some kind of manual reconciliation?
Or is there another option?
Thanks for your thoughts.
-
Check what type $qty is with gettype() or is_float(). You can use settype() or convert it to a float e.g $qty *= 1.0. Also change your filter_var statement to
$qty = (filter_var($qty, FILTER_VALIDATE_FLOAT, array('min_range' => 0))) ? $qty : 1.0;
-
Actually, I'm thinking I was incorrect. I created a blog for someone and originally had a similar query (note my order by is DESC).
$r = mysqli_query($dbc, "SELECT title, excerpt, content, image_file, DATE_FORMAT(date_created,'%D %M %Y') AS pubdate FROM articles ORDER BY pubdate DESC LIMIT 5");
The problem was that the rows were being ordered by day rather than the whole date, which technically makes sense. But I was getting the rows in this order
7th March
7th June
6th May
5th January
3rd April
Then I changed the query to
$r = mysqli_query($dbc, "SELECT title, excerpt, content, image_file, DATE_FORMAT(date_created,'%D %M %Y') AS pubdate FROM articles ORDER BY date_created DESC LIMIT 5");
and the rows returned as follows
7th June
6th May
3rd April
7th March
9th February
This thread is a good illustration of where aliases come into their own. In the above query, without an alias I would have had a cumbersome bit of code to access the date field e.g.
$r = mysqli_query($dbc, "SELECT title, excerpt, content, image_file, DATE_FORMAT(date_created,'%D %M %Y') AS pubdate FROM articles ORDER BY date_created DESC LIMIT 5"); while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { echo "<h2>$row[title]</h2><p> $row[excerpt]</p><p> $row[DATE_FORMAT(date_created, '%D %M %Y')]</p>"; }
Much easier to code
$row[pubdate]
and much less room for error!
Anyway Leo - I hope this helped a little and didn't cause you any confusion.
And thanks Antonio - you are correct that the column must be selected to use it for ordering.
- 1
-
I would have thought the error in the query was due to the ORDER BY clause. In your query you create an alias for the date_registration by do not use it in the ORDER BY clause. It should be
$q = "SELECT last_name, first_name, ➝ DATE_FORMAT(registration_date, '%M ➝ %d, %Y') AS dr, user_id FROM users ➝ ORDER BY dr ASC ➝ LIMIT $start, $display";
Its definitely worth spending time on the debugging chapter - you will save yourself loads of time in the future and learn a few tricks. One quick trick is to insert something like
print_r($r)
in your code which will give you full information about your query in a more readable format.
- 3
-
The error message is telling you that your d/b query that $r references has not been successful. For starters, try running that query directly via phpmyadmin or equivalent and ensure there are no typos, all variables are named as in the table etc.
- 2
-
Thanks Larry for replying. I found the solution on stackflow but your link got me searching on the appropriate terms. Because [link] is being returned as an object, I had to convert it to a string.
$href = (string)$entry->link->attributes()->href;
-
If you are trying to store the zip code as 21-150, the zip field in your table needs to be of a different type, at the moment it is set to mediumint and therefore is expecting all numbers. You will either need to convert $_POST['zip'] to all numerics or change the zip field in your table to varchar(6).
Why do you have auto_increment=4 at the end of the table?
- 1
-
You could echo them into a div with a class
echo '<div class="error">' . $reg_error . '</div>';
and then in your stylesheet set some rules for the error class.
- 1
-
Thanks for the reply. Now I have an array full of objects which I still don't know how to access. I'm sure there is a way to access the objects within the objects just not sure how.
Also is it possible to request just the 3 most recent 'entries' from the rssfeed as opposed to having to download the whole file?
-
I'm trying to display an rss feed on a webpage and could use some help getting the data. The format of the feed is
SimpleXMLElement Object ( [title] => HBR.org [id] => tag:blogs.harvardbusiness.org,2007-03-31:0.global-incremental [link] => SimpleXMLElement Object ( [@attributes] => Array ( [rel] => alternate [type] => text/html [href] => http://blogs.hbr.org/ ) ) [updated] => 2012-10-22T11:10:17Z [subtitle] => Practical insights, tools and resources from leading business thought leaders. [logo] => http://cbimages.ed4.net/hbsp/9380_225659.gif [entry] => Array ( [0] => SimpleXMLElement Object ( [title] => The Sad Truth Behind Growing Clashes at the WTO [id] => tag:blogs.harvardbusiness.org,2007-03-31:126.12422 [link] => SimpleXMLElement Object ( [@attributes] => Array ( [rel] => alternate [type] => text/html [href] => http://feeds.harvardbusiness.org/~r/harvardbusiness/~3/olpM1q4GSdM/the_sad_truth_behind_the_growi.html ) ) [published] => 2012-10-22T11:00:41Z [updated] => 2012-10-21T22:47:25Z [summary] => Don't be fooled by the rhetoric about protectionism.
I want to get the title, href, published and summary data for the 3 most recent [entry]s. Code below is working for the most part but I dont know how to get to the href which is an attribute of link. I've tried a number of different syntaxes and foreach loops but unsuccessfully.
//get the feed and create a variable to enable parsing of the data which is returned in xml format $feed = simplexml_load_file("http://feeds.harvardbusiness.org/harvardbusiness/"); echo '<ul id="rssFeed">'; $i=0; //parse the feed to get the title, link, published date and summary for each entry foreach ($feed->entry as $entry) { $pubdate = date("jS M, Y H:i", strtotime($entry->published)); echo '<li a href="' . $href . '">' . $entry->title . '</a> <p>' . $pubdate . '</p> <p>' . $entry->summary . '</p> </li>'; if ($i++ == 2) break; } //end foreach loop echo '</ul>'// end the ul tag
Please can you suggest how I access the href value?
Also I've used a counter and a break clause to stop the loop after 3 loops but I don't think this is the best practice. How would I get just the first 3 entries from the feed?
-
The error message is telling you what the problem is and how to resolve it. The timezone is probably not set on your server so you need to set it usingAn error occurred in script 'D:\xampp\htdocs\includes\form_functions.inc.php' on line 64:date() [function.date]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'UTC' for '5.5/no DST' instead
date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier.- 1
-
Thanks HartleySan, I'll look into it. Your reply on another thread about the benefits etc of ajax was good.
-
Thanks HartleySan, that does help. I did not realise I could use php within javascript.
Would Ajax be a better option? If so could you suggest some pointers on where to start?
-
I'm not surprised.
The form is validated using js and php. The php script inserts the data to the d/b and sends an email. Only then do I want to display a message on the original page and have that message fade out on the click of a button (used some jquery for this). This message is inform the visitor his form data was sent (validation errors are handled earlier).
My approach has been to code the message in a div with display:none.
<div id="msg" name="msg"> <h2>Message</h2> <p>blah blah blah</p> <p><input type="button" value="close" id="closemsg" class="formbutton"/> </p> </div>
and the css is
#msg { background:#fff; color:#b26fa7; border:2px solid #b26fa7; z-index:1; display:none; position:absolute; width:30%; height:100px; margin:50px auto 0; -webkit-border-radius: 8px; -moz-border-radius: 8px; border-radius: 8px; text-align:center; }
When the php script finishes it redirects to the original home page with a $_GET variable set. The js above checks for this variable and sets msg div's position to block so it can be seen. Surprisingly everything is working except one detail - because I've set msg div's position to block, its slightly throwing out the page layout.
Maybe I could use Ajax instead but I'm not proficient enough to use it. Maybe that's the answer to my original question 1. As for my other question, how would I use something like slice instead of charAt to get the characters after the equals sign from the url. As I'm using $_GET, the url is along the lines of www.example.com?action=display&id=2. I tried
var action = window.location.search.toString().slice('=');
I'll try again tomorrow but I was just happy the page worked.
-
Some more searching and I discovered window.location.search and below is my function which seems to work. I'm going to try to tidy it up with split. Any other improvements do chime in.
window.onload = function showMsg () { 'use strict'; var action = window.location.search.toString().charAt(3); if (action == 'd'){ var div = document.getElementById('msg'); div.style.display = 'block'; } }
-
I'm building a one page website which uses php, mysql and jquery to provide various functionality including form processing. After the form is processed I would like a simple message to be displayed which can then be hidden by clicking a button.
What would be the best way to achieve this. I was thinking of displaying the message in a div which could toggle between display:none and display:block. The php file which processes the form and inserts the data to the d/b could redirect to the same page with a hidden field which could be checked and if set could use javascript to set the message div to display:block.
My questions are:
1. is this a good way to achieve this or would you suggest an alternative approach?
2. if I used the above approach, how do I get the javascript to check if the hidden field is set in the $_GET variable? I did a little seach and saw something about using decodeURIcomponent. Before I start looking into thIs more, is decodeURIcomponent a good method, are there others? and any tips on using decodeURIcomponent?
Thanks for any suggestions.
-
Try something like this
// Display all the Paintings. $result = mysql_query ($query); while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) { // Display each record. echo "<div class=\"prints\"><a href=\"view_print.php?pid={$row['print_id']}\"> <img src=\"Uploads/{$row['image_name']}\"height=\"130\" $image[0] alt=\"{$row['print_name']}\" /></a></div> \n"; } // End of while loop. mysql_close(); // Close the database connection.
The above code outputs your html, then you need to style it to make it look nice. You should avoid mixing html and css in code as you originally did for a number of reasons which you can read about. Presumably you have an external stylesheet? Add the following to that file, though you may need to adjust the margins and padding.
.prints { width:33%; float:left; padding:10px; }
If you dont have an external filesheet, you should. But if this is just practice you can add the styling to the head section of your page - just surround the css code with <style></style> tags.
rob is right - this thread is for php and you're asking questions about basic html and css. Ask away, just do it in the right place.There are loads of resources on and offline that will teach you what you need to know. One book that looks pretty good is HTML5 and CSS3, published by the same publishers that Larry uses. Its good as it will intro you to HTML and CSS and then show you some HTML5 and CSS3 additions. Spend some time learning the basics and you'll save yourself alot of time in the long run. Oh, and NEVER use all caps for your html tags.
Form Validation - Radio Buttons
in PHP for the Web: Visual QuickStart Guide (3rd Edition)
Posted
I think you actually want to use a checkbox for your agree to T&C and I agree with HartleySan so I've removed the empty a element as it isn't doing anything.
Change your form to
and you will need to ensure that your create_form_input function includes some code for input type checkbox. I don't have this book but something like
Your validation will then be
You have some non-standard practices in your code such as including styling within the html, using a capital letter in your your variables e.g. 'Agree' and not using ascii codes for special chars in your html e.g. change '-' to . I hope you don't mind my pointing these out but its good idea to use good practices. On some forums (not this one) people won't help unless you use standard practices.