Jump to content

mikesta707

Staff Alumni
  • Posts

    2,965
  • Joined

  • Last visited

Everything posted by mikesta707

  1. Ha that explains everything. But how should I go about fixing that? I read through the MYSQL page on timestamp, and Im thinking that I should set the default value to null for my date column, and take off the auto update attributes (which i didnt even know it had until i read your post. Thanks! EDIT: Ah excellent yeah I got it. Thanks again!
  2. Ok, so I have run into a weird problem. I have a login system where everytime a user logs in, they have their lastlogin column on my user table updated to now. I recently converted my date columns to type Timestamp. There are a total of two data columns, one is date registered, and one is lastlogin. The problem I am having is when I update the lastlogin column, the other date column gets overwritten also. Here is the code I got $dateis = mysql_query("SELECT Now()"); $date = mysql_fetch_assoc($dateis); $new->query_update('lastlogin', $date['Now()'], 'user', 'User', $User); the query_update function of my class looks like this function query_update($columns, $values, $table, $where, $whereEqual){//preforms an update query. if columns is an array, value doesnt have to be, but if it is not, all the columns will be updated to that value //make sure the required values are set $array = array($columns, $values, $table, $where, $whereEqual); $this->isempty($array);//function to make sure the values are set //verify the arrays, if they are arrays if (is_array($columns) && is_array($values)){ $this->array_verify($columns, $values);//verifies the arrays are the same length } $sql = "UPDATE ". $table ." SET "; if (is_array($columns)){ $count = count($columns); $i = 0; foreach($columns as $key => $column){ if (is_array($values)){ $set = $values[$key]; } else { $set = $values; } $sql .= $column ."=".$set.""; $i++; if ($i < $count){ $sql .= ","; } } } else { $sql = "UPDATE ". $table . " SET ". $columns ."='".$values."'"; } $sql .= " WHERE " . $where ."='".$whereEqual."'"; $query = mysql_query($sql); if (!$query){ $this->error($this->errors['sql'].' '.mysql_error()); } } if I were to echo the $sql variable it would read what it should, IE "Update tablename SET lastlogin='Valid Timestamp format date' WHERE User='username'" for my specific date update call. Before, when I had my date columns as varchar (yeah I know, don't yell at me) And called this function, everything worked fine. php version is 5.2.8 mysql version is 5.0.67 Anyone have any ideas?
  3. that is more CSS than PHP. I dont think you could make words have a gradient with PHP, but I'm sure there is a way to gradient text with CSS. try googling css gradient text tutorial. there are tons hope that helps!
  4. This could be completely wrong, but maybe this would work $query = "SELECT * FROM USERS WHERE COUNTRY=US AND ZIP=12345 AND (Age=20 OR Age=25 OR Age=30 that might work... but then again my SQL syntax could be way off. But at least this is something to the effect of what you want Hope that helps
  5. you seem to be missing a semi colon a couple of lines up.
  6. alright well on the page that displays the user's information, and instead of just echoing the information, make aform, and set the values of the forms as the information from the table. FOr example, to make the password changeable, do something like echo "<input type=\"password\" value=\"$password\" /> that would make a password input field with the value of the users password. when they submit that form, it would go to a page that updates their specific entry for the user
  7. if (your condition){ echo "<table>"; //other table stuff } ?
  8. yeah that would work, but you need to wrap array values with { }. Dont ask me why. so something like mysql_query("INSERT INTO example (question) VALUES('{$_POST['question']}' ) ") or die(mysql_error()); [/php[ should work for you. hope that helps!
  9. next time you post code wrap them in code tags... And you need to explain what the problem is.. As far as I can tell that code looks ok.. Whats happening when you run the code. What does the page say when you submit the form? What does the notice say?
  10. the select max mysql command should help you. just do a query, something like $query = mysql_query("SELECT MAX(position) AS position FROM projectData"); $row = mysql_fetch_assoc($query); $pos = $row['position'] + 1; than use that pos variable as the value to input into your position column. You may want to check my syntax first tho
  11. Ok, so here is the deal. I am currently building a class that will do queries for me. So far, it is going ok, But i ran into a problem. I built a function to do simple SELECT queries, that dont have any conditions, IE $query = "SELECT * FROM tablename ORDER BY columnname DESC"; The function builds the query perfectly, and then stores the result in a class variable. The class is pretty long, but here are the relevant parts of the class the variables of the class class superQuery{ //define the variables in class var $debugmode;//sets whether or not to output error messages. Defaults to false var $resource;//the mysql resource of the class var $num_rows;//Number of rows returned from a query. var $info;//array with info from query //error messages var $errors = array( 'required_unset' => 'ERROR: Attempt to access function without passing required parameters', 'sql' => 'ERROR: Invalid MYSQL query. Error Message Below', 'array_verify' => 'ERROR: Attempt to pass arrays of unequal or invalid length to query. Script Terminated', 'sqland' => 'ERROR: Attempt to pass non And Or value into And Or parameter. Script Terminated', 'non_array' => 'ERROR: Attempt to pass non-array value into array parameter. Script Terminated' ); the function itself function query_whereAll($table, $orderBy=null, $select = "*"){//Selects everything from a table. $array = array($table); $this->isempty($array);//just makes sure that the table var is not empty. dont ask why i put it into an array and passed it //set the beginning of the sql $sql = "SELECT ".$select." FROM ".$table." "; if ($orderBy != null){ if (is_array($orderBy)){ $keyArray = array_keys($orderBy); $order = $keyArray[0]; $by = $orderBy[$order]; $sql .= " ORDER BY ".$order." ".$by; } else { $this->error($this->errors['non_array']); } } $this->resource = mysql_query($sql); if (!$this->resource){ $this->error($this->errors['sql'].' '.mysql_error()); } $this->num_rows = mysql_num_rows($this->resource); $this->info = mysql_fetch_assoc($this->resource); } Now this function builds the query correctly, and my server doesn't return any mysql error. However, the problem is when I use the class, IE in the following $topic = new superQuery(true); $topic->query_whereAll('topics', array('lastreply' => 'DESC')); $i = 0; while ($i < $topic->num_rows) { $id = mysql_result($topic->resource, $i, 'id'); $topic = mysql_result($topic->resource, $i, 'topic'); $date = mysql_result($topic->resource, $i, 'date'); $user = mysql_result($topic->resource, $i, 'user'); $text = mysql_result($topic->resource, $i, 'text'); //other stuff } What happens is that the variables id and topic get the right data, but I get the error "Invalid Mysql resource" for the date variable, user variable and text variable. What gets me is that it actually works perfectly fine for the first two variables, but doesn't work any more for the last three. The column names are all perfectly fine, and the query that happens goes without error, so I am at a loss at this point to what could be going on. my server php version is 5.2.8 my mysql version is 5.0.67 And yes, I understand that I can just do the query and it would work fine (actually this is what i did before) but i am trying to update my site using a lot more objects and classes. Can anyone see what is going wrong?
  12. I'm assuming you know how to send those values to an edit page. Just populate a form with those values, and people can edit the forms as they see. once they submit the form you can go to a page the updates the table with the new information. Obviously you will have to pass an Id or some other variable that is unique for every row to figure out which row you need to update. Hope that helps!
  13. well since & is the character entity for the & character, all you would really need to do is a string replace. just replace the & with &
  14. Well I believe that the character entity for the TM symbol is ™ but I can't really help to much beyond that without seeing some code, to tell how your data is parsed.
  15. have you tried the htmlentities() function?
  16. have you tried just using a regular e?
  17. a good tutorial on it. It is actually quite easy http://www.kirupa.com/developer/actionscript/flash_php_mysql.htm hope that helps!
  18. well you could take the file name of the image, and then explode the string using the delimiter '.' and that would give you two arrays with the file name as the first value, and the extension of the second. You could then append the file name with '_t' and then implode the array using '.' as the glue. Then you take your "fixed" image source, and when you output the image, echo that variable as the source
  19. Really? Your not supposed to do that? That's really interesting, and I never knew that. Is there a reason why, or is it just a bad practice? What could happen to the date if it was stored in a varchar?
  20. well if it is already saved in the correct format, then you wouldn't need to format it again would you. This is what I did when I wanted to make a dynamic RSS feed. I just formatted the data, had php write the xml, and then stored the formatted data in MySQL. though, in my case, the RSS feed and the mysql didnt really interact at all. Sorry if this doesn't help, but try posting the code that actually makes the RSS feed.
  21. does your column type HAVE to be a date type? can you just set it to varchar?
  22. try changing php_self to $_SERVER['PHP_SELF']
  23. instead of making a user thumbs table, why not just add a users_id column to the thumbs table. Everytime someone votes on something, you make an entry on that table. If they try to vote again, you check to see that there isnt an entry with the specific item id and their user_id and if there is you don't let them vote. honestly you could just put the item_id and item_name as columns in the thumbs table also.
  24. well what you would have to do is do a foreach to output it, as you cant simply echo an array (unless you wanted to use the print_r function, but that would echo the structure of the array, and not simply the values that are in it. some something like $string = ""; foreach($day as $day){ $string .= $day; } echo "<h4>Schedule:$string @ $time"; that would put all the entries in the array into a the variable string. so if the day array had the values M, W, and Th, the string variable would become "MWTh". Hope that helps!
  25. so something like $query = mysql_query("SELECT ip FROM table WHERE username='$username'"); $row = mysql_fetch_assoc($query); $query2 = mysql_query("SELECT * FROM table WHERE IP='".$row['IP']."' ORDER BY id DESC"); while ($row2 = mysql_fetch_assoc($query2)){ //do stuff here } That would get the IP for someones username, and then do another query which got every row with the same IP as the user. Hope that helps!
×
×
  • 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.