Jump to content

gizmola

Administrators
  • Posts

    5,945
  • Joined

  • Last visited

  • Days Won

    145

Everything posted by gizmola

  1. I have no idea what you're trying to do with php -q. php -f scriptname.php is what you use to run a php command line script. php -f server.php The code works, for what little it does:
  2. Yes. $arr = array(); while ($row[] = mysql_fetch_assoc($data)) { $arr[$row['id']] = $row; } var_dump($arr);
  3. The syntax you want is INSERT INTO table1 (columnlist....) SELECT columnname, 'constants', ... You need to intermix the columns you need from the SELECT with constants you pass as the $var's you will be passing. This example should illustrate the idea. mysql> select * from teams; +--------+-------------+ | member | hockey | +--------+-------------+ | bob | Black Hawks | | bob | Flyers | | bob | Kings | | joe | Caps | | joe | Penguins | | bob | Flyers | +--------+-------------+ 6 rows in set (0.00 sec) mysql> select member, hockey, 'ConstantValue' from teams; +--------+-------------+---------------+ | member | hockey | ConstantValue | +--------+-------------+---------------+ | bob | Black Hawks | ConstantValue | | bob | Flyers | ConstantValue | | bob | Kings | ConstantValue | | joe | Caps | ConstantValue | | joe | Penguins | ConstantValue | | bob | Flyers | ConstantValue | +--------+-------------+---------------+ 6 rows in set (0.00 sec)
  4. When you call mysql_fetch_assoc() you already get an associative array for that one row. For example: $arr = array(); while ($arr[] = mysql_fetch_assoc($data)) { // not sure what you need here } var_dump($arr); If you only want certain columns, you can specify them in your SELECT statement using SELECT column1, column2, column3... etc rather than SELECT *. At this point I'm not really clear on what you are trying to do or why, but $arr will be a numerically indexed array (0 based) where each element is an array that is equivalent to a row in the result set.
  5. This seems to indicate that your query is valid, but that the result set is empty. echo out your $sql and use a tool like phpMyAdmin to double check it. One other thing.. using the technique you're using, you will only ever see the last row, because you fetch all the rows in a loop, then only seem to go to display logic on the last row fetched. Just for quick testing, inside the fetch loop you could put in: var_dump($row);
  6. Well the first thing you should do is add the index. It's a simple syntax CREATE INDEX ... http://dev.mysql.com/doc/refman/5.0/en/create-index.html You can also use phpMyAdmin to add an index. PFMaBiSmAd gave you the syntax to show the create table syntax which will show what engine type you have. To add the LIMIT, just tack it on at the end of the DELETE query... LIMIT 500. You can check mysql_affected_rows and keep issuing the query until that returns 0.
  7. FWIW, if you only have 2 types (cake vs coffee) you will only have 2 groups. You'll get a group per DISTINCT value in the column you're grouping on.
  8. To get counts per group you need to do a GROUP BY on the column that has the type ID's. I have no idea what your table structure looks like, but something like this: SELECT COUNT(*) as countof, rowtype FROM cake GROUP BY rowtype ORDER BY countof DESC LIMIT 5
  9. Good catch by Pikachu2k. I have a link to this in my signature as well for similar reasons: http://www.flingbits.com/article/view/my-script-with-mysql-calls-doesn-t-work-why-1
  10. If you're running 50 sites, and these are generating any substantial revenue, you'd be better off on a dedicated server, I would think. Yes you need an index on the 'date' column whatever it's named that you're using in the where clause as described. Yes you also should lose the order by. You can (in mysql) specify a limit to the query. This might be a good idea as well, to lessen the impact of a giant delete. Are these tables myisam or innodb? With innodb tablespaces in particular space freed by deletions will not be reclaimed so your tablespaces may be getting larger and larger over time, despite this housekeeping.
  11. You're not reading the reply. A result set resource is not a variable you can do anything with. It is only used to support other functions that actually retrieve data from the result set (which is stored on the server). The variable in your script that actually has data is $row.
  12. This article should help you understand your options. http://www.gizmola.com/blog/archives/93-Too-much-information-about-the-MySQL-TIMESTAMP.html If you alter your definition from datetime to timestamp you will save space (4 bytes per row) as well as unlocking automatic timestamping of the row. The only issue is that if you will later update these rows, by default an update will also change the timestamp column which may not be what you want. If you leave it as a datetime, then yes you can simply specify the constant 'NOW()' in the VALUES section.
  13. I really like what you have done with the site. We were talking about it recently, and I wish we had a version of your original site just for comparative purposes, because it makes for a great example of how much someone can learn and develope their skills in a short period. The main thing about the site I'd like to see modified is to have you add some type of background for your main content area. One idea would be to add a background to the wrapper style. Because you have a nice background image, I added a little opacity to it using the webdeveloper plugin, and a style based on support for the rgba() style. This is not supported by all browsers, and for IE you would need to conditionally serve up something extra, but this should give you an idea. #wrapper { margin-top: 30px; overflow: hidden; background: rgb(0, 0, 128); background: rgb(0, 0, 128, 0.7); } More about fully implementing this idea here: http://robertnyman.com/2010/01/11/css-background-transparency-without-affecting-child-elements-through-rgba-and-filters/ The problem is that once you do that, the header image would need to be reworked a bit, so that it fits entirely inside the block with no border or padding -- otherwise it looks odd. Here's a screenshot of what you could expect: The other thing that bothers me is the footer background color which seems to have no relationship to any other part of the site. I would suggest making it the same as the header color. I realize you are still working on things here and there, but you've really done an incredible job. I think I can speak for a lot of the other vets here who contributed to your thread, when I say that your progression and results is what makes the effort we put into answering questions and trying to help people worthwhile and keeps us coming back.
  14. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=330109.0
  15. Is this for MySQL? You can GRANT SELECT ON database.view TO user@... Should work fine.
  16. In your showAddresses function document.getElementById(element).focus(); document.getElementById(element).blur(); The data is then loaded via ajax, but since the element does not have focus, the keypress does not go to it. I don't know why you focus() and then immediately blur(). My suggestion would be to either not do that, or try another focus() call after the ajax load occurs, so that it has focus.
  17. Read this article first. http://www.gizmola.com/blog/archives/93-Too-much-information-about-the-MySQL-TIMESTAMP.html We really need more information to best answer this question. In particular, what is the range of these date/time values. What will you be doing with them? Are they arbitrary date/time's that the user enters in some fashion through the UI, or automatically set (timestamped) by the system.
  18. No, you are right about use only cookies. That is suppossed to constrain it so that the session id is only sent in a cookie, which is what you want. Otherwise, it will allow for the phpsessid parameter to be sent as a url parameter. This is to fight session fixation, where someone "fixates" a session id, they know to a user who is logged in, by getting that user to pass the phpsessid url parameter via some xss, or just having them click on a link. If i can get you to do that and the server accepts it, I can now hijack your session. The reason we have been talking about cookies, is because I thought you wanted to verify that this feature was working by trying to force your browser not to accept cookies, and insure that your site would not login the person via a phpsessid url parameter. So you definately want to have: session.use_only_cookies = 1 Set in the php.ini. I'm not confident however that you can modify this setting at runtime.
  19. This is what I would recommend: http://jquery.com/ http://api.jquery.com/category/ajax/ You write a script that does session_start(), checks that there's a valid user and if so, calls an update function you write that will update the status of the user -- usually via a datetime column in the database named something like lastseen. In your jquery you make calls to this script based on the setInterval() javascript function. One reason not to use the onbeforeunload() event as suggested by russelreal, is that this would be problematic in certain circumstances where for example, someone opens up multiple tabs to your site for the same session, which is easy to do with current browsers. If you assume that because someone closed a tab they were logging out, you could get in a situation where you logged someone out who still had an open window on your site. yes but they would be inactive until they visit another page anyway when they visit the next page their session will be touched and they'll be "active" again. Doubtful. Usually a logout destroys the session data. Otherwise, it's not really a logout.
  20. Yeah... if it's truly only going to be 10-20 searches, or the equivalent of 10-20 page views a day, they probably won't notice, or care.
  21. $pdo = new PDO ("connection_settings", "user", "pass", array (PDO::MYSQL_ATTR_MAX_BUFFER_SIZE=>1024*1024*10)); Would up the limit to 5 megabyte. In the future, please make a new thread, and just add a link to the old one.
  22. Nobody can answer your questions. It entirely depends on the type of information you're pulling and what this means to the company that is providing the information, and what type of copyright they are asserting, or business model they have. Maybe I don't get it, but I can't see how you could have any business based on the premise of 10 visits a day. I'm guessing you mean 10 visits per day, per ID, and there may be hundreds or thousands of these ID's. If you don't think you will get noticed by them (assuming they care) you're probably going to be wrong. If your entire business is going to depend on their data, you should look into making a deal to license it from them at some point.
  23. Firebug is a plugin for firefox. If you're going to be working with ajax and complex javascript it's just about indespensible as a testing/debugging tool.
  24. No problem. In html there's a concept of 'block' vs. 'inline" elements. Typically people apply the one that makes sense, although in css you can set the property to be what you want it to be when you apply a style. So in general, you should try and use the html element that makes sense for your content. If it's a block of content, then use one of the block elements like a p or div. If you need to style something inline, like one word in a sentence then you can use one of the built-ins like strong or b, or use span. This might help you understand the concept better: http://webdesign.about.com/od/htmltags/qt/block_vs_inline_elements.htm
  25. On other thing... if this is a real server, you're going to need an actual url to the script. This won't work: xmlhttp.open("GET","gethint.php?q="+str,true);
×
×
  • 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.