Jump to content

pault

Members
  • Posts

    17
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Male
  • Location
    Devon, England

pault's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I couldn't just use the whole returned row because there are other columns as well as the numbered ones (forgot to mention that) so I would have to filter them out. But your answers have given me enough to sort the problem out and I've learnt a few things today. Thanks to you both.
  2. You mean extract the data from the database using numerical keys instead of associative? Eg. $var[$j] = $row[$j+x]; sort of thing (where x is the number in the offset in the mysqli_fetch_row.
  3. They are actually columns in a MySQl database. It is a 'globals' table and originally there were only two so I called them code1 and code2. Now they have grown in number and it would be better to separate them into a different table but I can't face all the re-writing at the moment.
  4. That didn't quite work but for ($j = 1; $j <= 4; ++$j) { $fieldname = 'field' . $j; $arrayvar[$j] = $$fieldname; } did. Thanks for putting me on the right track.
  5. This is difficult to explain but here goes. Imagine I have several variables called $field1, $field2, $field3 (not the best way to store things I know but that's the way it is - it's actually to do with columns in a MySQL database) and I want to loop through them and put them into an array. Ideally I'd want something like this: for ($j = 1; $j < 4; ++$j) { $arrayvar[$j] = eval('$field' . $j); } so that the loop counter was added to the word $field to create $field1, $field2 and each line became the equivalent of $arrayvar[1]=$field1, thus automating the procedure. Eval works but you have to do it on the whole line: eval('$arrayvar'.[$j]. '=$field'.[$j].';'); So is there any way of using a sort of eval for just part of a line? Hope you understand and thanks for any advice.
  6. I hope someone can help me with this or point towards a published code. I have a PHP page which displays a list summarising database records. When users click on an icon, another window pops up with further information from the record. They can keep clicking through the list, showing each new record in the SAME popup window. Obviously when the popup first appears, the window must be sized to fit within the user's screen and also to one side so that people can still see the main list. But if they resize the window (maybe because they have a very large screen), I want each new display of the window to retain the user's new size. To summarise, the first time the window opens, its dimensions are set to a default size (based on screen size), but from then on it retains the user-defined size. Thanks in advance.
  7. I am using a multiple array with the layout: userarray['score'][00] userarray['id][00] userarray['name'][00] etc where the first column contains properties and the second column is the number for each user (shown as 00). After putting the data into the array, I want to sort the array by the score with the highest at the top. I have used the code: array_multisort($userarray['score'], SORT_NUMERIC, SORT_DESC); but it seems to sort the 'score' column while leaving the other columns in the original order. Obviously I want all the rows to remain related to each other. Can anyone help?
  8. (PHP version 5.2.14) My situation is that I have table of Users and a table of Adverts which are created by those Users. I want to search the Adverts, selecting for for dates, price, etc, which is all very straightforward. The difficulty comes in that the Users are sometimes enabled and sometimes disabled, and when they are disabled, none of their adverts should appear. What I need then is something like "select * from Adverts where (adverts.dates=etc, etc) AND where User.enabled=true" I've been looking at joins and subqueries but the examples don't seem to match what I am looking for. Grateful for any help.
  9. Just tried your code, BlueSkyIS, and it works perfectly. Saved me hours of searching and brain-wracking. Great forum. Thanks everyone for such quick advice.
  10. A problem has arisen which puzzles me. I have forms which save data to MySql and retrieve it, showing it as the default data in the form. Naturally I escape any quotes before sending it to the database and remove the slashes when I retrieve it. But the form HTML code shows the data like this value="$variable" which is fine when only single quotes are used in the data but causes a problem when the user uses double quotes. So data of John \"Jack\" Smith would be output as value="John "Jack" Smith" with obvious problems. If I use value='...' then that would cause problems with single quotes. I haven't seen the answer in any of my books. The only things I can think of is changing all double quotes to single before saving to DB or converting them with htmlspecialcharacters so they are no longer actual quotes.
  11. Oh? They don't then? Isn't your solution what I said two days ago? I thought they did but with experimentation found that addslashes leaves newlines alone and mysql_real_escape_string converts them. Your comments got me on the right track: it was the combination of addslashes AND mysql_real_escape_string which confused matters.
  12. Thanks all for the advice. One combination I've finally found that seems to work is not to use mysqli_real_escape_string at all. I use addslashes taking the data to the database and stripslashes on extraction. That changes quotes but ignores line breaks. I also use prepared statements to write to the database. Would this combination be secure?
  13. Surely addslashes and mysql_real_escape_string do the same thing? If I use stripslashes on the data from MySQL, I just end up with "Foo"rnBar. It doesn't seem to turn the \r\n into a newline.
  14. This is driving me mad. I've looked in my books and on the Internet but I cannot find the answer. I have a form with a textarea and I need to retain the linebreaks. Obviously, before I send the data to MySQL, I run it through mysqli_real_escape_string and the result is: (In form) "Foo" Bar (In phpMyAdmin) \"Foo\"\r\nBar When I extract the data from MySQL, I use stripslashes($var) to get the quote back and end up with: "Foo"rnBar The problem I am having is changing the \r\n or rn to newlines so that it looks correct in the form. I have tried using nl2br before stripslashes. Even tried using str_replace to change the /r/n to <br /> but I just end up with "Foo"<br />Bar in the textarea box. There must be some simple thing that's causing the problem or people wouldn't be using textareas. Help!
×
×
  • 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.