Jump to content

lxndr

Members
  • Posts

    72
  • Joined

  • Last visited

Everything posted by lxndr

  1. Thanks for the suggestion. When I run this though I get an error as follows: Every derived table must have its own alias
  2. Many thanks for this. I thought perhaps something like this might be needed but my SQL knowledge was too basic to come up with it. Having said that, I've just tried it on my database and it doesn't seem to have picked up the co-authors ... __
  3. I tried that and it doesn't provide what I need. Here's an example which might make it a bit clearer: Rec 1 author: John Smith co-author: Mary Jones Rec 2 author: Mary Jones co-author: rec 3 author: John Smith co-author: Fred Bloggs I'd like the results for the above to output as: Mary Jones 2 John Smith 2 Fred Bloggs 1
  4. I have a table which holds details of various books and currently have a query which is used to provide a dropdown list of authors: SELECT count(*) as total, author as author FROM library WHERE author <> 'Unknown' GROUP BY author ORDER BY author ASC That works fine and is later used to provide a list like: John Smith 34 Mary Jones 28 etc but the table also has a column called 'coauthor' and what I want to be able to do is add in the results for coauthor as well as author to the grouping. Is there a way of doing that in the query, grouping by multiple columns but as if they were one and the same? Thanks in advance for any help. __
  5. Ah, that fixed it. Many thanks for your help, it's much appreciated.
  6. I need to be able to read in some text from a MySQL table and then pre-load it into an input element within a form. I'm having trouble getting it to work if the pre-loaded input has BOTH apostrophes and quotation marks in it and can't seem to find a way round it. For example the html to be output would be something like: <input type="text" name="field" value=" php string variable here "> where the php string variable but is being read in from an SQL row.
  7. Do you know if that will that work cross-browser consistently including Opera and Safari ? __
  8. I'm not sure if this is the best place to ask this question as it all depends on what the answer is. Basically, I need to modify an existing php program with reads in a file of messages and if there's a message for the user who's running the program it generates a javascript alert with the message displayed in it. What I need to be able to do is provide the means of replying to the alert. I could do away with the alert altogether of course but I need something that sits on top of the screen in all browsers that can only be got rid off by clicking OK (or by replying). I'm simply not sure of the best way to go about this and would welcome any positive suggestions or help. TIA..
  9. I can access the script on it's own, that doesn't give a 403, it's when I call it and pass parameters in the URL that the Forbidden message crops up ... Having said that it is likely to be related to Apache rather than php isn't it .. I'll raise a support ticket and ask the host provider ... __
  10. A php script which has been running for some years has suddenly started generating a Forbidden 403 error and this seems to coincide with the host upgrading from php4 to php5. A number of items are passed in the URL including spaces represented as %20 and I think single quotation mark represented as %27 ... I suspect these may be responsible for the error. Can anyone confirm that's likely to be the case and suggest the best way to deal with it? TIA.
  11. That worked just fine, many thanks for your help, I hadn't realised it could be done so simply. Will know better next time. __
  12. I've been using the following function to sort a multi-dimensional array by a numeric key: function sort2d ($array, $index, $order='desc', $natsort=FALSE, $case_sensitive=FALSE) { if(is_array($array) && count($array)>0) { foreach(array_keys($array) as $key) $temp[$key]=$array[$key][$index]; if(!$natsort) ($order=='asc')? asort($temp) : arsort($temp); else { ($case_sensitive)? natsort($temp) : natcasesort($temp); if($order!='asc') $temp=array_reverse($temp,TRUE); } foreach(array_keys($temp) as $key) (is_numeric($key))? $sorted[]=$array[$key] : $sorted[$key]=$array[$key]; return $sorted; } return $array; } I'm using it to sort a league table of football teams and sorting on the number of points they have which is item 7 in the array as follows: $league = sort2d($league, 7); This is where the array elements get assigned within a for loop following various calculations: $league[$j] [0] = $team_name; $league[$j] [1] = $played; // played $league[$j] [2] = $won; // win $league[$j] [3] = $drawn; // drawn $league[$j] [4] = $lost; // lost $league[$j] [5] = $score_for; // for $league[$j] [6] = $score_against; // against $league[$j] [7] = $points; // points $league[$j] [8] = $user; $league[$j] [9] = $score_for - $score_against; // goal difference; What I really need to do though is have a secondary sort based on element 9 which is goal difference. In other words I want to sort by points and then if the points are equal by goal difference. I've tried a few times to update the function to do this but have had no success so far. Can anyone help ? Thanks in advance. __
  13. I have some code which is intended to write text into an existing png image using one of 8 different colours. I noticed that it works as intended about a dozen times and then the text is always black each subsequent time. I wrote some debug to capture what was going on and have to admit to being totally confused. This is the code which assigns the rgb colours and then calls ImageColorAllocate: $red = hexdec( substr( $hexval, 0, 2 ) ); $green = hexdec( substr( $hexval, 2, 2 ) ); $blue = hexdec( substr( $hexval, 4, 2 ) ); $color = ImageColorAllocate( $myimage, $red, $green, $blue ); Then later this is the code that writes the text into the image: imagettftext( $myimage, $fontsize, $textangle, $start_x, $start_y, $color, $fontfile, $string ); What I don't understand are the values being returned from the ImageColorAllocate call on subsequent calls, why is the value for color continuing to rise even though I'm only using 8 actual different colours? I'm also fairly sure it didn't used to behave this way but my server has recently been upgraded from php4 to php5 so wondering if that has anything to do with it. Anyway, if anyone who has a much better understanding of ImageColorAllocate can tell me where I'm going wrong or better still what I need to do to fix the problem I'd be very grateful. Here are the values for hexval and color that are returned by subsequent program executions: 01. hexval: #C0C0C0, $color: 18 02. hexval: #FF0033, $color: 33 03. hexval: #FFFFFF, $color: 71 04. hexval: #FFFF00, $color: 95 05. hexval: #FF0033, $color: 111 06. hexval: #00FF00, $color: 127 07. hexval: #6666FF, $color: 135 08. hexval: #00C0C0, $color: 148 09. hexval: #FF0033, $color: 168 10. hexval: #FFFFFF, $color: 173 11. hexval: #FFC0C0, $color: 176 12. hexval: #00C0C0, $color: 184 13. hexval: #00C0C0, $color: 213 14. hexval: #00FFFF, $color: 216 15. hexval: #00FF00, $color: - TIA for any help. Ian __
  14. I've basically been writing (for free) a series of web pages for a charity organisation and they regularly want their pages updating. Because I'm not always able to do it for them immediately I wrote a series of admin functions for them which allow them to change some of the page content. These functions are behind 2 layers of password protection ... I'm not sure whether that would be considered secure enough ? __
  15. I'm currently displaying a series of web pages based on HTML code and content which is stored in an SQL table. This works fine. Basically, the data is read into a php variable and then displayed using php echo statement. What I'd like to be able to do is incorporate php statements into the code stored in the SQL database but when I do that currently the php code does not get interpreted but merely left as the original code and ignored. Presumably this is because I'm echoing the content .. is there a way round this, i.e. I can read in the php code from the database AND have it interpreted as part of the web page display. Thanks in advance for any help. Ian
  16. detecting "yesterday" isn't as simple as it appears unless I'm missing something ?
  17. Was just wondering if there's an easy way of being able to display a unix timestamp for GMT so that if the date in question is today or yesterday the date gets displayed using those terms while all other dates get shown as actual dates. As an example, that would mean I'd get something like: user joined Person A Today, 02:52 AM Person B Yesterday, 06:59 PM Person C 25 Jan 2008, 04:45 PM Person D 24 Jan 2008, 11:02 AM Person E 24 Jan 2008, 09:34 AM TIA for any help or advice.
  18. Is there a way of determining how many unread messages there in an email inbox using php? ...
  19. I'm trying to write a function that will read in a text document containing various bespoke tags which I then expand into the appropriate HTML. I've done most of them but was wondering if someone could help me with this particular one .. I'm guessing I should be using preg_replace but can't seem to get it to work. I have a variable called $rec_id which is an integer. The following is the conversion I want to perform: in text file: <image 1/jpg> should be converted to : <img src = "story_images/1347-1.jpg" style="float:left;padding:5px;"> where the conversion string is all fixed as above apart from the bit in colour and in the above example $rec_id was 1347. Here are another couple of examples to illustrate the above: $rec_id: 1281 tag in text file: <image 2/gif> tag replaced with: <img src = "story_images/1281-2.gif" style="float:left;padding:5px;"> $rec_id: 763 tag in text file: <image 4/jpg> tag replaced with: <img src = "story_images/763-4.jpg" style="float:left;padding:5px;"> Any help much appreciated. .
  20. I'm sure I must be doing something incredibly dumb here but in certain circumstances when I call this particular php program I have written which is intended to insert a single record I find that instead it inserts the same record twice (there's no index field). I don't know what to make of it, this is the actual code: $today = time(); if (BST()==TRUE) $today = $today + 3600; $sql = "INSERT INTO stories_views VALUES ( '$user_name', $rec_id, $today ) "; $result = mysql_query($sql, $db) or die(" - Failed More Information:<br><pre>$q</pre><br>Error: " . mysql_error()); The field types are as follows: $user_name: varchar $rec_id: int $today: int It's starting to drive me nuts now so if anyone can suggest what the problem might be it'd be much appreciated.
  21. I'm not sure what you mean by sample output and input but maybe if I paint one specific example I can apply the proposed solution as a generality. The database field (called responses) is VARCHAR, length 16 Example data item: 1000000100000000 I then have an HTML form with 16 checkboxes on, i.e. Item 1 Item 2 . . . Item 16 Now I want the above data item (1000000100000000) to be a match if the user selects EITHER item 1 or item 8 and was trying to generate the most elegant SQL solution. Obviously I can generate multiple OR statements .. ie.. SELECT * from table WHERE responses REGEXP '^1...............$' OR responses REGEXP '^.......1........$' what i was hoping is that there's be a neater way of doing it ?
  22. I have a database field that is composed of 16 characters each of which can be set to '0' or '1'. The characters represent data from a form with 16 checkboxes. What I want to able to do now is query this field. I was almost able to do it using REGEXP with the following as an example: SELECT * FROM `library` WHERE responses REGEXP '^1......1........$' This works if searching for items that have both the 1st and 8th elements set to 1 but what I really want is for it to search for rows where this field has EITHER 1st or 8th elements set to 1. e.g. If the user does a search and fills out both 1st and 8th checkboxes I'd like the MYSQL query to return the following as an example 1000000000000000 0000000100000000 1000000100000000 currently it's acting in a logical 'AND' kind of way and only returning: 1000000100000000 Can anyone tell me the best way to do what I want? TIA
  23. If I take the debug statement which is the actual SQL call made by my php program and copy/paste it into the SQL tab of phpmyadmin it works perfectly so I can't see how the code can be at fault ?
  24. There are no constraints on the table and yes the "user" update is redundant ...
  25. game_name: varchar(35) game_id: int(4) date: int(11) user: varchar(45) popup: tinyint(1) You are not supposed to give quotes for integer data type. I've changed that and removed the quotes and the problem is still there. I should also say that this problem only occurs in relation to 2 of the game_ids ... the other 271 don't cause this problem.
×
×
  • 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.