Jump to content

SammyP

Members
  • Posts

    58
  • Joined

  • Last visited

    Never

About SammyP

  • Birthday 06/23/1971

Profile Information

  • Gender
    Male
  • Location
    London

SammyP's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. And I'd also not put quotes around the numbers in your SQL statements, unless the field is stored as text for some reason. It might work, but it shouldn't really.
  2. What is happening is that you query your database to find out if the page exists, and if it doesn't you add it. All well and good. However then you go on to use the results of the initial query, which returned no records. It doesn't matter that you have subsequently added a record, as the initial result set is unaffected. You could requery the database, but you already know what it will say. So, inside your loop where you add the record, just set $count to equal 1. Then, only run the second query if the insert part did not run, so use an else clause on your initial if statement. Inside the else clause, get your $count value, increment it, and run your update statement. You can skip the while loop altogether I think, as you're only expecting one row to be returned, and at that stage you will already know that there is at least one row. In pseudo code: if (count of rows = 0) { insert a row set $count = 1 } else { get $count $count++ update database with new count value } use $count I'm not sure why the vpage thing is erroring. I don't understand exactly what you're saying there.
  3. So from here I had to implement my own php.ini files. It was an annoying bug, but it has been found now. Hopefully this will be of some use to anyone who has a similar problem.
  4. This won't give you an id. $previd = mysql_query('SELECT MAX(id) FROM yearbook'); That gives you a result object and you have to use that to fetch a row, which will be an array. As you did above. There is no great shortcut for this, though I've written my own and have it in a globals page which I always call, so I can always use it. function getsqlval($sql, $default = null) { $res = mysql_query($sql); if ($row = mysql_fetch_row($res)) return $row[0]; return $default; } So whenever I need to run a query just to get one number I can use this: $previd = getsqlval('SELECT MAX(id) FROM yearbook'); Use that if you like.
  5. I have found some information on this if anyone is interested. I ran phpinfo() and searched for 400. It came up as a variable called suhosin.post.max_vars in some security module (Suhosin) my host company has installed. Set to 400 obviously. So I've asked how to circumvent it and will do so if I can, and in case it helps I'll post out how I did it here. If it is possible at all. Sam.
  6. Well, one suggestion I'd make would be to add an extra optional parameter to the page URL structure. So if you ask for yearbook.php?id=6&cmd=prev then you do this, in pseudo, before you show anything: $id = ID parameter if cmd exists { if cmd=prev { $newid = SELECT Max(ID) WHERE ID < $id and whatever else you need for this set of images if $newid $id = $newid else $id = MAX(ID) } else do similarly for cmd=next } Do this before showing anything, so you can show the correct ID which is now in $id, and then you can simply use the following URLs: yearbook.php?id=$id&cmd=prev yearbook.php?id=$id&cmd=next This method will at least not mean any extra processing if the user never clicks Next or Prev. Hope that helps.
  7. Thanks to you guys for the comments, but I've checked and I really seem to have this limitation. I've added different numbers of input elements to the start of the form and everything happens in a way that suggests there is a 400 element limit to my post array. Firstly, in my created HTML, there is no problem, the form looks as I'd expect. All of the elements are there. In my processing, I now echo out the count of the Post array and it is always 400. If I add two dummy elements near the start, when I loop through the Post array the final two from the time before are not there. Does anyone have any idea what might cause this? I don't want to go to the trouble of limiting the number of elements on the screen. (These are personal admin screens and I am not worried about how it looks.) Sam. (Like the quote flyhoney!)
  8. I have a form which has a variable size, depending on the number of rows in a table. For each row there are about ten fields, and I simply show them all for each row. I've recently started having a trouble in that if I create a form with more than 400 elements, then the $_POST variable is truncated at 400. Is this normal? Do I have to limit the size of the $_POST array? Not by MB, which must be trivial for me, but for the number of array elements?
  9. Anyway, this is what I can help you to do, which is get a table for each type of clothing. It will be quite hard to put them all into one big table, but we can look at that later. 1.Your outer query should be this: $query = "SELECT type FROM dc GROUP BY type"; The grouping will ensure we create one table for each type of clothing. 2.Now inside your loop set $type = $row_query['type'] as you do already, and output some table tag stuff and a heading. 3. Run the inner loop, using this query: "SELECT * FROM dc WHERE type= '$type'"; Ideally in this loop don't call anything shorts, as they won't always be shorts. 4. As you go through the inner loop, output something like this <tr><td>$row['colour']</td><td>$row['number']</td></tr> 5. Outside that loop, close the table. 6. Outside the main loop, you're finished. This will get us started, I numbered things in case it isn't clear. If there is a chance that your table could hold two rows like this: Shorts, Red, 4 Shorts, Red, 5 meaning you want to display Red 9 in the Shorts table, you will need to change the inner query to this: "SELECT Colour, Sum(Number) As Total FROM dc WHERE type= '$type' GROUP BY Colour"; Also, remove the 'u's from Colour everywhere. Silly Americans. And if you use this query here, the field name will be 'Total; now. Let me know how we're doing.
  10. Am I right in assuming there can be shorts of different colours in your table, and you want to list them separately, and then probably do the same for other items of clothing? Answer that and I can talk you through it fairly easily. How do you want your output to look, is what I guess I'm asking.
  11. Seeing as we are going to be relying on the session_id, we can approach this from the other way. We can have the Session remember which pages it has been to. In your referral code you would do this: Start the session, which I assume you do already. Check to see if a variable $_SESSION['pages_visited'] is set, otherwise create it: $_SESSION['pages_visited'] = Array(); Check to see if x is in the array. If ($_SESSION['pages_visited'][x]) If it is, then do not run the query which increments viewings. If not, then run the query, and add x to the array: $_SESSION['pages_visited'][x] = True; I think this should work.
  12. OK then, you are almost where you want to be, but you will need a table to contain the SessionIDs. I can see no way around that. Oddly I am working on this part of my site today as well. Here is some code I use. $sql = "INSERT INTO log (page, params, userkey, session, ip, date) VALUES('$_SERVER[sCRIPT_NAME]', '$pageparams', ".nz($_SESSION['userkey'], 0).", '".session_id()."', '$_SERVER[REMOTE_ADDR]', CURRENT_TIMESTAMP())"; mysql_query($sql); This simply adds a row every time a user comes to a page. You would modify this just to hold x and the session_id() value I guess. Maybe the date too. And obviously create the log table. I've just had another idea though... hang on...
  13. Obviously you will have to set up a log table to do the counting. With each count you can store the IP address and SessionID values, and discard duplicates or just have your query which eventually analyses the results ignore them. (If you keep them you can still check to see who tried to cheat.) If you use the SessionID though, it is too easy to get around, as closing the browser window will allow people to get a new value. So that does not help a lot. If you don't though, then you might get different people using the same server, or some other method which means they have the same IP address, who are only counted once, which is also no good. Which I think brings you to cookies as the next best idea, but these can be deleted as well. I don't think there is an absolute way of resolving this. Depends on how prudent you want to be.
  14. You have a sql error. If you check mysql_error after your sql calls it will tell you. I suspect you don't want $type to be in single-quotes in the inner query. I am not sure what output you want, but I think you can probably get to it more easily than the way you are doing it.
×
×
  • 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.