Jump to content

XenoPhage

Members
  • Posts

    99
  • Joined

  • Last visited

    Never

Everything posted by XenoPhage

  1. [!--quoteo(post=357094:date=Mar 21 2006, 04:13 PM:name=brokenhope)--][div class=\'quotetop\']QUOTE(brokenhope @ Mar 21 2006, 04:13 PM) [snapback]357094[/snapback][/div][div class=\'quotemain\'][!--quotec--] Now, the userid is easy, I will set it to int, auto_increment. The thing's that I dont know how I should set is pretty much everything else, usually I would set them all to Text... username will contain the persons username userpass will contain a md5'ed version of the persons password userjoindate will contain a timestamp of the date they joined userpageviews will contain a numerical value of the number of pages they have viewed userlastlogin will contain a timestamp of the date they last logged in userlevel will contain a numberical value to the id of their userlevel (corresponding in the userlevel/ privilages table) useravatar will contain a url, maybe an id to their avatar userfavorites will contain an array, or a string (to be "explode()"'ed into an array) of the users favorite pages on the site [/quote] Well, don't just set then for text unless you have no interest in growth .. :) I'd do the following : [code] CREATE TABLE mytable (id   INTEGER UNSIGNED  AUTO_INCREMENT,                                     username  CHAR(15) NOT NULL,                                     password   CHAR(32) NOT NULL,                                     joindate     DATETIME NOT NULL,                                     pageviews  INTEGER DEFAULT 0,                                     lastlogin     DATETIME NOT NULL,                                     level          TINYINT NOT NULL DEFAULT 0,                                     avatar        INTEGER,                                     PRIMARY KEY (id)); CREATE TABLE avatar (id   INTEGER  UNSIGNED  AUTO_INCREMENT,                                   location  CHAR(255) NOT NULL,                                   PRIMARY KEY (id)); CREATE TABLE favorites (id  INTEGER  UNSIGNED  AUTO_INCREMENT,                                      url  CHAR(255) NOT NULL,                                      userid INTEGER UNSIGNED NOT NULL,                                      PRIMARY KEY (id)); [/code] Now, what I've done above is how I'd structure it based on what you told me.. I definitely wouldn't be placing the favorites into an imploded array.. Let SQL do the work for you.. As for queries, that depends on what you need..
  2. [!--quoteo(post=356963:date=Mar 21 2006, 08:58 AM:name=dalmaca)--][div class=\'quotetop\']QUOTE(dalmaca @ Mar 21 2006, 08:58 AM) [snapback]356963[/snapback][/div][div class=\'quotemain\'][!--quotec--] but now ive moved over to my new webserver im gettin error cron mails.. saying " php: error while loading shared libraries: libmysqlclient.so.12: cannot open shared object file: No such file or directory" is this something ive done or there end ? [/quote] This would be their end. Sounds like they don't have the shared_compat libraries installed.
  3. [code] <html> <head> <title>Homework Administration- Delete Homework</title> <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"> </head> <body> <?php $conn = mysql_connect("localhost","cortez","165745"); //now choose the database to use mysql_select_db("cortez_photoalbums"); $id = $_GET['id']; // retrieve id passed via URL if (isset($id)) {     $query = "DELETE FROM images WHERE id = '$id' ";     $result = mysql_query($query); } $getimages = mysql_query("SELECT * FROM images ORDER BY id DESC"); while($r=mysql_fetch_array($getimages)) { extract($r); //remove the $r so its just $variable     echo("<hr>   Image: <image src='$_POST[imageurl]' height=\"50\" width=\"50\"><br>     Id: $id <br>     Date: $date<br>     <a href='". $_SERVER['PHP_SELF']. "?id=$id'>delete</a>"); } ?> </body> </html> [/code] You missed closing the while() loop.. Above passes a php lint test.
  4. [!--quoteo(post=355482:date=Mar 15 2006, 04:21 PM:name=PGS JoE)--][div class=\'quotetop\']QUOTE(PGS JoE @ Mar 15 2006, 04:21 PM) [snapback]355482[/snapback][/div][div class=\'quotemain\'][!--quotec--] [code]$days = array(   //read database and if there is an event, of which there should be plenty...        day of event=>array('# . $id','linked-day' //I have no clue what this does), );[/code] [/quote] Hrm.. array of arrays.. Good fun! [code] $days = Array(); while ($line = mysql_fetch_array($result)) {    $days[$line[0]) = Array($line[1], $line[2]); } [/code] For my little example, $line[0] is the day of the week, $line[1] is '# . $id' and $line[2] is 'linked-day' .. All of those values are returned from the database.. I think that gives you what you want?
  5. [!--quoteo(post=355481:date=Mar 15 2006, 04:19 PM:name=HoTDaWg)--][div class=\'quotetop\']QUOTE(HoTDaWg @ Mar 15 2006, 04:19 PM) [snapback]355481[/snapback][/div][div class=\'quotemain\'][!--quotec--] [code] <?php $conn = mysql_connect("localhost","cortez","165745"); //now choose the database to use mysql_select_db("cortez_photoalbums"); $id = $_GET['id']; // retrieve id passed via URL if (isset($id)) {     $query = "DELETE FROM images WHERE id = '$id' ";     $result = mysql_query($query); } $getimages = mysql_query("SELECT * FROM images ORDER BY id DESC"); while($r=mysql_fetch_array($getimages)) { extract($r); //remove the $r so its just $variable     echo("<hr>   Image: <image src='$_POST[imageurl]' height=\"50\" width=\"50\"><br>     Id: $id <br>     Date: $date<br>     <a href='". $_SERVER['PHP_SELF']. "?id=$id'>delete</a>"); </body> </html> [/code] [/quote] You didn't close out the php code.. You need to add ?> just before the </body> statement..
  6. [!--quoteo(post=355476:date=Mar 15 2006, 04:10 PM:name=brown2005)--][div class=\'quotetop\']QUOTE(brown2005 @ Mar 15 2006, 04:10 PM) [snapback]355476[/snapback][/div][div class=\'quotemain\'][!--quotec--] can anyone tell me how to get this to work below please:- header('location: '.$config_url.'/files/url.php?id='.$random_array['blocks_id'].''); [/quote] Can you explain what you're tryin to go? Are you sure all those variables are set? What results are you getting currently?
  7. What output are you getting? Are you getting errors? Have you included that page anywhere else in the script?
  8. [!--quoteo(post=355445:date=Mar 15 2006, 02:38 PM:name=Arsenal)--][div class=\'quotetop\']QUOTE(Arsenal @ Mar 15 2006, 02:38 PM) [snapback]355445[/snapback][/div][div class=\'quotemain\'][!--quotec--] Oh yeah....that would help. [/quote] Your query failed, or possibly returned no rows. Try your query directly in mysql and make sure it works. Also, add this : [code] $fac_qry  = mysql_query("SELECT name, email FROM ".$SET['pref']."_stor_facility WHERE abbr = '$locat'") or die ( 'MySQL Error : ' . mysql_error() ); [/code]
  9. Ok, this one's not for the light hearted.. :) This is PHP 4.4.0 (gentoo build) Here's some code to start us out (I've cut a LOT out of this) : [code] class Outage {    var outage_id;    var outage_dirty;    function Outage(&$dbconn, $oid = -1) {       if (($oid != -1) && is_numeric($oid)) {          // Load some data from the database          $this->outage_id = $oid;          $this->outage_dirty = false;       } else {          // New outage          $this->outage_id = -1;          $this->outage_dirty = true;       }       // Register a shutdown function       register_shutdown_function( array(&$this, '_check_dirty_flags') );       // Outage creation successful - return true       return true;    }    // Set and/or return the Outage ID    function outage_id($outage_id = -1) {       if (($outage_id != -1) && is_numeric($outage_id)) {          $this->outage_id = $outage_id;       }       // If the current outage ID is -1, this may be a new outage and we need       // to serialize it.       if ($this->outage_id == -1)          $this->_check_dirty_flags();       return $this->outage_id;    }    // Serializes (saves) any changes to the outage    function _serialize_outage() {       // -1 signifies a new outage       if ($this->outage_id == -1) {          // Save this new outage to the database          $this->outage_id = mysql_insert_id();       } else {          // Update this existing outage in the database       }       $this->outage_dirty = false;    }    // Shutdown function    // Checks the flags to see if any serialization is needed    function _check_dirty_flags() {       if ($this->outage_dirty) {          $this->_serialize_outage();       }    } } [/code] Ok, some explanation. I create an instance of the outage class at the beginning of my program. In the direct instance I'm talking about, this is a new outage. The code has a flow something like this (note, in this example, assume that $_REQUEST['outage_id'] is not set : [code]    // Load the defaults    require_once('outage_glob.php');    // Connect to the MySQL database    $sqlhdlr = mysql_connect($DB_HOST, $DB_LOGIN, $DB_PASS)       or die('Could not connect: ' . mysql_error());    mysql_select_db($DB_NAME) or die('Could not select database');    // Create the outage object (all sanitization is handled by the object)    if (isset($_REQUEST['outage_id'])) {       $outage_obj = new Outage($sqlhdlr, $_REQUEST['outage_id']);    } else {       $outage_obj = new Outage($sqlhdlr);    }    // Set a bunch of stuff up in the outage    $outage_obj->mymethod('stuff');    // Now we display the outage id    print $outage_obj->outage_id();    // and exit    exit; [/code] The behaviour sought here is for the outage to have been serialized when $outage_obj->outage_id() was called, and when the code exits, the shutdown function will see the outage_flag as false, thus not bothering to serialize the outage again. However, for some reason, it sees the flag as dirty when the shutdown function is called, and it serializes again. This wouldn't be so bad, but it also sees the outage_id as -1, so it thinks it's a new outage. Can PHP handle this? Am I doing something wrong here? I can always change my program slightly to call the serialization function just before exiting, but I was hoping to add some additional functionality and check for user aborts as well. I wanted to get this working first, though.. HELP! Thanks!
  10. [!--quoteo(post=354920:date=Mar 14 2006, 10:53 AM:name=cnl83)--][div class=\'quotetop\']QUOTE(cnl83 @ Mar 14 2006, 10:53 AM) [snapback]354920[/snapback][/div][div class=\'quotemain\'][!--quotec--] Anyone jack with scorm? I cannot figure how the LMS pulls the data. Say if my score field is named SCORM, how it tells the LMS the the actual score field is name $SCORE. SCORM is the crappiest system in programming yet! [/quote] Are you referring to the Sharable Courseware Object Reference Model? Is this even PHP related?
  11. [!--quoteo(post=354865:date=Mar 14 2006, 08:03 AM:name=chuddyuk)--][div class=\'quotetop\']QUOTE(chuddyuk @ Mar 14 2006, 08:03 AM) [snapback]354865[/snapback][/div][div class=\'quotemain\'][!--quotec--] im just getting stuck with how to make it add the "1" when the radio button is selected and submited any ideas? [/quote] I'm not 100% sure of what you want.. Post what code you currently have, as well as the database design, and maybe we can help more.. As for how to detect if a radio button is selected, you need to do something like this : [code] <input type='radio' name='newstype' value='1'>Business</input> <input type='radio' name='newstype' value='2'>Student Union</input> <input type='radio' name='newstype' value='3'>Employer News</input> <input type='radio' name='newstype' value='4'>16-19 Years</input> <input type='radio' name='newstype' value='5'>Adult News</input> [/code] And then on the php side : [code] if ($_REQUEST['newstype'] == 1) {    // Handle business news here } else if ($_REQUEST['newstype'] == 2) {    // Handle student union news here } else if ($_REQUEST['newstype'] == 3) {    // Handle employer news here } else if ($_REQUEST['newstype'] == 4) {    // Handle 16-19 years news here } else if ($_REQUEST['newstype'] == 5) {    // Handle adult news here } else {    // Handle exceptions here (nothing was chosen!) } [/code]
  12. [!--quoteo(post=354476:date=Mar 13 2006, 07:38 AM:name=Essjay_d12)--][div class=\'quotetop\']QUOTE(Essjay_d12 @ Mar 13 2006, 07:38 AM) [snapback]354476[/snapback][/div][div class=\'quotemain\'][!--quotec--] The data was inserted using an insert form through php using a <textarea name="F_Review"></textarea> tag. How can I get php to recognise or produce it in two paragraphs? [/quote] HTML will ignore \n (linefeed) ... So you need to convert those to <br /> .. Try using nl2br() before displaying the info from the database. Or, it may be possible that when you stored the data that was submitted, something you did stripped the line feeds.. Can't tell that unless you post that part of the code.
  13. [!--quoteo(post=353605:date=Mar 10 2006, 08:11 AM:name=Cell0518)--][div class=\'quotetop\']QUOTE(Cell0518 @ Mar 10 2006, 08:11 AM) [snapback]353605[/snapback][/div][div class=\'quotemain\'][!--quotec--] Example (from Gallery 2) $urlGenerator->makeUrl($path)); for this "->", does it mean something like this? $variable "execute and set return value = to $variable" makeURL(to "$path variable" in this case)? Just trying to understand some of the more complicated code in Gallery. Thanks, Chris [/quote] $urlGenerator is an object, makeUrl is a method for that object. It's basically calling the makeUrl method with an argument of $path. It doesn't appear that this is returning anything as there's no additional variable. It may be that the method creates the URL and stores it in an internal member variable.
  14. [!--quoteo(post=353306:date=Mar 9 2006, 12:01 PM:name=Jerry1)--][div class=\'quotetop\']QUOTE(Jerry1 @ Mar 9 2006, 12:01 PM) [snapback]353306[/snapback][/div][div class=\'quotemain\'][!--quotec--] That seems to have worked. What else can I do to make sure my employer can not back track anything to find what web-sites i have been on? [/quote] Umm.. what exactly does this have to do with PHP and/or MySQL?
  15. Hey all, I have a select multiple box. In that box are a number of options. The user chooses options and then the back end saves them to a database. This all works fine. Now, the user needs to edit those choices. I pull the data from the database, and display the relevant selections to the customer. Again, that same select multiple box, but this time with the previous selections highlighted. The customer changes the selection and submits it again. This is the part I'm curious about. Right now, I take that input, plus the values from the database, and I build a hash. If the value is in the database *and* was submitted, I do nothing. If the value is in the database and not submitted, I delete it from the database. And lastly, if it was submitted but not in the database, I add it to the database. My question is, is there a more efficient way to do this? Are there any tricks or php functions that can do this work easily? The code is fairly simple to do this, but I think I'm wasting a ton of memory because, in the end, I wind up with 3 lists that have roughly the same data depending on how many changes there were.. Any thoughts?
  16. [!--quoteo(post=353260:date=Mar 9 2006, 09:57 AM:name=zeroth404)--][div class=\'quotetop\']QUOTE(zeroth404 @ Mar 9 2006, 09:57 AM) [snapback]353260[/snapback][/div][div class=\'quotemain\'][!--quotec--] I think that solves the issue of speed, however it still refuses to insert the data. [/quote] Umm... I must have missed that bit.. I wasn't aware that it wasn't adding the data.. Are you getting an error? Try changing the mysql_query line to this : [code] mysql_query($query) or die(mysql_error()); [/code]
  17. [!--quoteo(post=353251:date=Mar 9 2006, 09:22 AM:name=Gaia)--][div class=\'quotetop\']QUOTE(Gaia @ Mar 9 2006, 09:22 AM) [snapback]353251[/snapback][/div][div class=\'quotemain\'][!--quotec--] Thanks, but i'd rather learn how to do it myself and create my own function/class. Do you remember any of the resources/tutorials you used that helped you create your object? Thanks ^_^ [/quote] Sure.. I looked up the specs for RSS 0.90, 1.0, and 2.0. I used those to figure out what the structure looked like, and then built a class to output that data. Here are some links for RSS : [a href=\"http://backend.userland.com/rss092\" target=\"_blank\"]RSS 0.92 Spec[/a] [a href=\"http://blogs.law.harvard.edu/tech/rss\" target=\"_blank\"]RSS 2.0 Spec[/a] [a href=\"http://web.resource.org/rss/1.0/\" target=\"_blank\"]RSS 1.0 Spec[/a] [a href=\"http://atompub.org/2005/07/11/draft-ietf-atompub-format-10.html\" target=\"_blank\"]Atom 1.0 Spec[/a] NOTE : RSS 1.0 is *NOT* compatible with 2.0 ... Read the history. 1.0 is basically an off-shoot from 0.90 and developed independently from 2.0. 2.0 was named such so as to not confuse people..
  18. [!--quoteo(post=353244:date=Mar 9 2006, 09:05 AM:name=wickning1)--][div class=\'quotetop\']QUOTE(wickning1 @ Mar 9 2006, 09:05 AM) [snapback]353244[/snapback][/div][div class=\'quotemain\'][!--quotec--] Look, when you use COUNT(*), MySQL sends one little integer back to you over the internet. It doesn't even have to do a disk read to get that number because all the information it needs is sitting in memory in an index. When you select all the rows, MySQL has to retrieve all the thousands of rows of data from the hard disk, send you that data over the internet, and when they all finally arrive, you use PHP to count how many. [/quote] Agreed.. Although, I'm not 100% sure that the index is always memory resident.. It might have to do a little work, but it's still a LOT less than returning all the rows. If you weren't seeing a significant speed increase (assuming you were asking for hundreds of rows and not just one or 2), then you might need to look a little closer at the code and determine where the bottleneck is. Try adding some timing functions to the code and display the output. That can help indicate where the issues are. [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--] By all that is holy, there is no way in hell that selecting all the rows is faster. In any universe, even the evil one where Spock has a beard. The only time you should EVER use mysql_num_rows is if you need all the data AND a count. You just need a count, so don't use it. [/quote] Hrm.. I liked spock better with the beard.. :)
  19. [!--quoteo(post=353029:date=Mar 8 2006, 04:55 PM:name=zeroth404)--][div class=\'quotetop\']QUOTE(zeroth404 @ Mar 8 2006, 04:55 PM) [snapback]353029[/snapback][/div][div class=\'quotemain\'][!--quotec--] thanks, that works. but its much slower than the other method of copying the contents into other variables. with your method I get about 100 lines copied in 30 seconds, while I get 700 lines with the former. I may just have to request to my webhost that the 30 second execution limit be raised. I'm still open for suggestions. [/quote] Change the script to do one large insert instead of multiples.. something like this : [code] $query = 'INSERT INTO partsdb (p_num, p_name, p_price) VALUES '; $first = true; for ($db_index=0; $db_index < $db_entries; $db_index+=3)  //a part number is every 3 lines,    {       if ($first) {          $query .= sprintf('%d, "%s", %f)', $db_data[$db_index], $db_data[$db_index+1], $db_data[$db_index+2]);          $first = false;       } else {          $query .= sprintf(',(%d, "%s", %f)', $db_data[$db_index], $db_data[$db_index+1], $db_data[$db_index+2]);       }    } mysql_query($query); [/code]
  20. [!--quoteo(post=353017:date=Mar 8 2006, 04:41 PM:name=zeroth404)--][div class=\'quotetop\']QUOTE(zeroth404 @ Mar 8 2006, 04:41 PM) [snapback]353017[/snapback][/div][div class=\'quotemain\'][!--quotec--] ok, tried that. I get "Undefined index: $db_index" a bunch of times. strange. [/quote] Here, this should help. (I'm assuming here that price is a float value) [code] $query = sprintf('INSERT INTO partsdb (p_num, p_name, p_price) VALUES (%d, "%s", %f)', $db_data[$db_index], $db_data[$db_index+1], $db_data[$db_index+2]); [/code]
  21. [!--quoteo(post=353016:date=Mar 8 2006, 04:40 PM:name=jesirose)--][div class=\'quotetop\']QUOTE(jesirose @ Mar 8 2006, 04:40 PM) [snapback]353016[/snapback][/div][div class=\'quotemain\'][!--quotec--] Why would I do that? Doesn't that just find out if it is a number, wheras intval returns the numeric value? Can you explain the value of checking if it's a number? Thanks :) [/quote] Well, if you're expecting a number, and someone submits a character, is_numeric will make that apparent... I generally do checks like this : [code] if (preg_match('/^\w+$/', $_REQUEST['variable'])) {    $myvar = $_REQUEST['variable']; } else {    // Either warn the user or fall back to a "default" } [/code] That would be for a text value containing any alphanumeric character including _ ... You can obviously change the regex to something else as needed.
  22. [!--quoteo(post=352976:date=Mar 8 2006, 03:49 PM:name=tinuviel)--][div class=\'quotetop\']QUOTE(tinuviel @ Mar 8 2006, 03:49 PM) [snapback]352976[/snapback][/div][div class=\'quotemain\'][!--quotec--] So it has been determined that this code SHOULD work, it just doesn't. Anyone else want to take a stab at why this is being quirky? [/quote] I honestly think there's something environmental going on here. As I mentioned to you in email, I don't have access to the database, but if I comment out the database calls and hard code "pretend" values in there as returns, the code works flawlessly. Can you elaborate on the environment? Linux? Windows? Apache? PHP Version?
  23. [!--quoteo(post=352961:date=Mar 8 2006, 03:17 PM:name=Gaia)--][div class=\'quotetop\']QUOTE(Gaia @ Mar 8 2006, 03:17 PM) [snapback]352961[/snapback][/div][div class=\'quotemain\'][!--quotec--] hi, I want to be able to export some data from a mySQL table to a rss file ( .rss ). So basically i want to create a .rss file for syndication on other websites. How can you do that via PHP? If anyone can get me started or point me to a resource/tutorial or a section in the PHP Manual that discusses this? Thanks. [/quote] I created my own object to do this. You can use the code if you like, it's part of my [a href=\"http://www.sourceforge.net/projects/phptodo\" target=\"_blank\"]phpTodo[/a] project.
  24. [!--quoteo(post=352954:date=Mar 8 2006, 03:01 PM:name=johnl1479)--][div class=\'quotetop\']QUOTE(johnl1479 @ Mar 8 2006, 03:01 PM) [snapback]352954[/snapback][/div][div class=\'quotemain\'][!--quotec--] Yes, I know this. An empty resultset is empty. (0 rows, I performed check with mysql_num_rows()) As you can see what from i said, the data does exist in the database. The exact same query in phpMyAdmin returned the desired result. --EDIT-- What do you mean by wierd characters? i have checked the page from multiple computers running different O/S's and different browsers, nothing shows wierd characters [/quote] It looks like this (Firefox 1.5) : [img src=\"http://www.godshell.com/oss/broke.jpg\" border=\"0\" alt=\"IPB Image\" /]
  25. [!--quoteo(post=352953:date=Mar 8 2006, 03:00 PM:name=jesirose)--][div class=\'quotetop\']QUOTE(jesirose @ Mar 8 2006, 03:00 PM) [snapback]352953[/snapback][/div][div class=\'quotemain\'][!--quotec--] Hi :) Right now I have a few functions I am using for when a user submits info, which strip out anything that could be dangerous. Is there anything else I need to add, or do they look okay as is? Here are two of them: [code]function safe_POST($item){     $item = mysql_real_escape_string(strip_tags($_POST[$item]));     return $item; } function safe_int_GET($item){     $item = intval($_GET[$item]);     return $item; }[/code] [/quote] Well, that's one way to do it.. You can also use preg_match() to ensure that the data is exactly what you're looking for. Then wrap it from there if you need to insert it into a database.
×
×
  • 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.