Jump to content

gizmola

Administrators
  • Posts

    5,945
  • Joined

  • Last visited

  • Days Won

    145

Everything posted by gizmola

  1. He's referring to the mysql data type. It needs to match the type of data you are saving in that column. His suggestion which seems good for handling currency is to use a decimal() type. His example of DECIMAL(11,2) would allow you to store numbers as large as 999,999,999.99 in a column.
  2. The code you posted doesn't even work. You have the end of a loop that you didn't provide the start of the loop for. You do a query, and then query again. I can't account for the output you get, because we don't have the actual code you're using that is relevant to the problem.
  3. This is what I'd typically do given your outline. Obviously you'd have to fill out the tables, but the barebones of it I would do like this. This does not utilize "defining" relationships between the tables that join to events, which simplifies adding events to the events table, and also leaves duplicate checking to you, but as this needs to deal with start/end times at a venue anyway, it handles it from the database standpoint efficiently. I also included the constraints but unless you use the innodb engine with mysql (the default is myisam) constraints are dropped so they won't have any effect on the structure or functionality. # ---------------------------------------------------------------------- # # Tables # # ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- # # Add table "`show`" # # ---------------------------------------------------------------------- # CREATE TABLE `show` ( show_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, name VARCHAR(40), CONSTRAINT PK_show PRIMARY KEY (show_id) ); # ---------------------------------------------------------------------- # # Add table "venue" # # ---------------------------------------------------------------------- # CREATE TABLE venue ( venue_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, name VARCHAR(40), address VARCHAR(40), CONSTRAINT PK_venue PRIMARY KEY (venue_id) ); # ---------------------------------------------------------------------- # # Add table "event" # # ---------------------------------------------------------------------- # CREATE TABLE event ( event_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, show_id INTEGER UNSIGNED, venue_id INTEGER UNSIGNED, startDate DATETIME, endDate DATETIME, CONSTRAINT PK_event PRIMARY KEY (event_id) ); # ---------------------------------------------------------------------- # # Foreign key constraints # # ---------------------------------------------------------------------- # ALTER TABLE event ADD CONSTRAINT `show`_event FOREIGN KEY (show_id) REFERENCES `show` (show_id); ALTER TABLE event ADD CONSTRAINT venue_event FOREIGN KEY (venue_id) REFERENCES venue (venue_id);
  4. Morris, You just need to tweak your output where you are already echoing out the values from the row. I also am using a technique called "interpolation" that lets you embed your variables in one string instead of having to concatenate them all using the '.' operator. Hopefully it will make it simpler to see what you're doing in the future and is a great technique to know. The secret is that you need to wrap arrays inside the {} to get it to work. chart = mysql_query("SELECT * FROM Hitlist ORDER BY total DESC limit 5"); $num_rows = mysql_num_rows($chart); while($row = mysql_fetch_assoc($chart)) { echo "{$row['artist']} ... {$row['city']} ({$row['country']}) " . '' . "{$row['total']} USD "; } The important thing in php is to learn the difference between using single quotes and double quotes and how they work. Single quotes make a string literal/constant. It is exactly what it is. Double quotes makes an "interpolated" string, where the php parser will go through it at runtime looking for variables to replace, and inserting their values. $name = 'George'; $fruit = array(); $fruit['name'] = 'orange'; $literal = 'The value of the $name variable will not be interpolated here'; $interp = "The value of the name variable is $name"; $interparray = "I have an {$fruit['name']} in my lunch today";
  5. Yes, but since it's static, the easiest thing would be to turn it into a javascript array that you emit at the top of the page in a javascript script block. I also would use a different format of array. If the array has no value being in php you might want to just code it up in javascript. I would also suggest a different structure for your array. Since it seems that what you have is "username" => "email", i'd structure your php array that way. Here's what I'd suggest: $users = array('destramic' => 'destramic@hotmail.co.uk', 'Process' => 'pro@whatever.com'); ?> <br /> var users = <?php echo json_encode($users); ?>;<br /> </pre> <form> < FYI, one of the issues with using json_encode is that you need a recent version of php ( > 5.2) and you have to install a pecl addon. You could just output the javascript array ready to use: var users = { 'destramic' : 'destramic@hotmail.co.uk', 'Process': 'pro@whatever.com' }; The main value of having a php array first is if you will also use those values in the serverside portion of the script. Hopefully it is apparent that you could use the php script to output it in javascript array format using a foreach() loop if that was the case. Json is wonderful for many things but it is not essential here, so I just wanted to clarify that.
  6. No, it's a function that takes a parameter. But the entire condition needs to be put inside parens: if (!empty($UserId)) { // do whatever }
  7. I'm responding to your code. json_encode($array) does nothing if you don't get the return value. PHP scripts run serverside -- they can't "run on value change". If you want to react to clientside events you 'll need javascript. Otherwise, you'll need to provide more code.
  8. You can't send output (your form) then send output again. Not a php thing.... that is an html thing. Besides that fact, json_encode takes the parameter and returns the json encoded version. At very least you need to $str = json_encode($array); echo $str;
  9. Just give your style a different name. Do you understand css? You simply need to create a class in one of your style sheets... could be the global joomla style sheet. Adding a style that joomla doesn't use willl not effect any existing styles because you are going to reference this style by its name. .bigHitList { font-size: 18px; color: yellow; } echo '' . $row['total'] . ' USD '; Doing it this way, you can change the appearance of the span by changing the style sheet, rather than having to update the php code. This might help you: http://www.csstutorial.net/css-intro/introductioncss-part1.php
  10. This isn't really a php question -- you just need to echo out the html markup: echo '' . $row['total'] . ' USD '; You can echo out the actual inline style but I would highly recommend that you don't do that and instead refer to a style you set in your style sheet. Actually using an inline style defeats the purpose of style sheets.
  11. Regex's are difficult. I highly recommend getting your hands on an interactive testing tool. I use http://weitz.de/regex-coach/ but there are many others you will find if you do a google for "mac interactive regex tool" as an example.
  12. PHP sessions can and do facilitate this. Sessions by default are actually small files that are stored on the server. An associated cookie for the session id is sent to the client and that is how the server knows on subsequent requests that the same browser is making a new request. Unlike cookies, the good thing about this is that the data in the session stays on the server. You could put the cart data into a database but practically speaking it is not necessary until the point you actually have an order. The choice is really yours. The basics of sessions are very simple. On every page that uses sessions you must start the session first. Most people have an initialization/include of this function: session_start(); Now you can read session variables that have been set, change them or add new ones, using the $_SESSION superglobal. $_SESSION['items']++; echo "You have {$_SESSION['items']} in your cart now."; Try this on a page and as you refresh it you will see the count increase if you've done everything normally. That should be enough to get you started, but I'd recommend reading the http://us3.php.net/manual/en/book.session.php even if you don't completely understand everything in it.
  13. Left Middle Right Dick Tom Harry Welcome to phpf.
  14. gizmola

    Anuvver kev

    Please... that book is horrible. Do yourself a favor and look for something better. The php manual itself is free and quite serviceable, and there are literally scores of tutorials not to mention many screencasts that will probably do a much better job teaching you what you need to know.
  15. The script that is the target of the post will have any posted values in the $_POST superglobal array. All you need do is go through those values using a foreach() loop: foreach($_POST as $key => $value) { echo "$key: $value "; } You didn't specify which database you are using, but you will at very least need to do some input validation. At minimum you need to escape characters relevant to any strings you are inserting into char types, and you might also want to run htmlentities or strip_tags on it, so that malicious html/javascript that could cause xss problems is handled. From there it's simply a matter of getting the input you require and creating an insert statement for the database you're using. Without more details all we can offer is generalized help like this.
  16. header("Location: url_to_goto"); exit(); However, you can't redirect once you've sent output, because at that point the page is complete. You can either have a link or use some javascript to redirect, but you might want to think through your design better.
  17. I'm not sure what you're asking here. The script is a mess. I stripped out the complete nonsense and am left with this. Give it a try. // Subject of email sent to you. $subject = 'PCI Tour/Excursion Request'; // Your email address. This is where the form information will be sent. $emailadd = 'MY EMAIL HERE'; // Where to redirect after form is processed. $url = 'FORWARDING URL'; $text = "Results from form:\n\n"; foreach ($_POST as $key => $value) { $value = trim(strip_tags($value)); if (!empty($value)) { $text .= "$key: $value\n"; } } mail($emailadd, $subject, $text, 'From: '.$emailadd.''); echo '';
  18. First off, why are you making your own id value? Does this table not have an auto_increment key? Second, it is more efficient to do multiple inserts in one transaction: INSERT into Subjects (Subjects, User, Classs) VALUES ('$subject1', '$username', '...'), ('$subject2', '$username', '...'), etc... So it would be better if your loop added a set of VALUES to the $query string each time through the loop, and when finished, you need only do one mysql_query().
  19. That is an older version. Try the one in this archive: http://museum.php.net/php5/pecl-5.2.6-Win32.zip
  20. It looks like you've met the requirements. What does phpinfo() show you for php-dio? Since the functions actually work, it looks like you have what you need.
  21. This is a pretty complete answer to the problem: http://stackoverflow.com/questions/1952570/php-how-to-capture-browser-window-screen-with-php
  22. Try redirecting output to a file so you can see what the operating system is reporting. If your server is configured with selinux enabled, sudo will most probably not ever work.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.