Jump to content
Larry Ullman's Book Forums

Antonio Conte

Members
  • Posts

    1084
  • Joined

  • Last visited

  • Days Won

    126

Everything posted by Antonio Conte

  1. Another solution, I think, is $mysqli->multi_query() $query = 'SELECT * FROM table1'; $query .= 'SELECT * FROM another_table'; $mysqli->multi_query($query); I concatenate a lot of strings to make up a large query in a statistics script. I did this procedural, bot It seems like the function works exactly the same way in OOP. It took me awhile to figure out the errors. If this is what you need, remember to use mysqli::use_result() for the first query and mysqli::next_result for the others. From the manual on multi_query: Looks like you solved id, but might be worth mentioning anyway. I guess it works because you tell the DBS to don't give a f*** about the problem. Maybe I'm wrong.
  2. Stilig! Visste ikke at du var litt norsk av deg. Stavanger er en fin by. Bodde der i et år når jeg var rundt 3 år gammel. Isset does pretty much the same as array_key_exists(). It just check wheter the variable are set or not. Isset() is great to use when you don't care about what the variable contains, but just that it exists. A great use for isset() would be to check wheter $_POST is set or not. But Matt: I really just recommend you to check these function on php.net. You'll learn alot about functions you didn't know you needed to know. A good example are integers and forms. All form input sent with $_POST are sent as Strings(!). This mean you cannot use functions like is_int() without typecasting, but the function ctype_digit() works the same way with strings. A good test is therefor to use something like this: if ( is_int($var) || ctype_digit($var) ) { // we are sure this is an integer or a string representation of an integer. Bulletproof } Things like these are not obvious, but that's why the php manual is indespensable. Be sure to check "related functions" and their description beneth functions. That's how you stumple upon things like these. .) But really. I don't mind explaining, but I guess it's faster for you.
  3. How about something simple like strlen()? No need to over-complicate things. Match the total so it does not bleed.
  4. Hello, everybody It would be nice to know see what you've been able to create over the years. Show us your projects, and tell us a little bit about what you've done. Hope somebody else want to share. It's time to brag a little bit among friends about what you've achieved over the years. To start off the thread, here are some of mine: Juventus Norge - http://juvenorge.com Description: A fansite for my favorite football club, Juventus F.C. This is my retarded love child. Been developing on it for over three years now. This is where I use most of my time on the Internet. The community has grown to about 350 really active contributors, and a lot of us meet face-to-face to share our love for this great football club. We have also managed to become an official fan club, and are distributing match tickets for our favorite club. Work: Backend systems, front-end programming and design, forum modifications and day-to-day management of the company. ---------------------------------------------------------------------------------------- Real Zaragoza Fans - http://rzfans.net Description: Another football site. This is a fan site, in english, dedicated to the spanish club Real Zaragoza . Although, it's a small site, it's driven by a small number of people who would like to share their passion for the club. It was developed over last summer, with a re-design around Christmas. Work: Built on Textpattern. Front-end programming and design and forum templating.
  5. Jeg er norsk, ja. Er du norsk? My real name is Thomas, btw. Antonio Conte is my first favorite player - and the current coach - at the Italian Football Club Juventus. You are almost right about your assumption. The function empty() does however not know if the array key exists, but it would have to be set, not to be empty.
  6. No, they are not the same. There's an important difference. $_POST Description from php.net: By using array_key_exists('contact', $_POST), you check wheter the key 'contact' exsists inside the POST array. You can't know (by this function) if it's empty, only that it's there. This is why it's so important to read the manual. It's really a great tool. Use it. I'm getting tired here. Hope this makes sense.
  7. It returns nothing. Blank. If I use 'stdClass', objects are returned. If I try 'class', 'abc' or 'anything', it does not work. I've tried to use the $params array as a second parameter. That is also failing, even with 'stdClass' as the first parameter. If I use $params as the only parameter, an empty array is returned. I found a solution, though: (With fetch_object) while ($obj = $result->fetch_object()) { // $my_obj = new Season($obj->id, $obj->seasons); // $seasonList->addObject($my_obj); // Shorter $seasonList->addObject( new Season($obj->id, $obj->seasons) ); } And the same with fetch_array: while ($obj = $result->fetch_row()) { // $my_obj = new Season($obj[0], $obj[1]); // $seasonList->addObject($my_obj); // shorter $seasonList->addObject( new Season($obj[0], $obj[1]) ); } It makes sense that this works. I really don't understand why I can't use the parameter, though. I think I like this second version best. It will allow me to reuse this syntax with all classes, only changing the parameter list for the object to be created and the name of the Class to instantiate objects from. As for overhead, etc. The fetch_array() may be faster, or what do you think, Larry/rob? Both tricks return this: Array ( [0] => Array ( [0] => Season Object ( [id:private] => 1 [season:private] => 2009/10 ) ) [1] => Array ( [0] => Season Object ( [id:private] => 2 [season:private] => 2010/11 ) ) [2] => Array ( [0] => Season Object ( [id:private] => 3 [season:private] => 2011/12 ) ) [3] => Array ( [0] => Season Object ( [id:private] => 4 [season:private] => 2012/13 ) ) [4] => Array ( [0] => Season Object ( [id:private] => 5 [season:private] => 2015/16 ) ) [5] => Array ( [0] => Season Object ( [id:private] => 6 [season:private] => 2015/16 ) ) ) Larry: In Java, you can use Class hinting. $my_object = (Season) $obj; print_r($my_obj); Can you do something like this in PHP? That might solve my problems. It would make sense, as all classes are children of stdClass? (I think). Just wondering.
  8. Yes. I changed it to: $result->fetch_object('Season')) And public function addObject( Season $object ) { } The reason why I specified stdClass i only because mysqli_fetch_objects returns an object of that class by default. This is the only way I've got it working. If I use any class_name as parameter, the script is not working. This is what I found weird. :/ Edit: The parameter actually works if I use 'stdClass' as the class to return an object from. Weird. That means it's nothing wrong with the parameter in my php version at least. $result->fetch_object('stdClass'))
  9. Dunno know exactly how these functions work, but I'm guessing they work as arrays. Remember that an array always starts with Zero, not one. If you want the first to the fourth characters, that would be position 0 to 3. (position: 0, 1, 2, 3) Dunno if this helps you anything.
  10. Just want to comfirm that the quotes on the column's not producing this error. PhpMyAdmin adds them by default in you click on a column in the query window interface. That is legal and not a problem.
  11. b is blob by definition in param bindings. Don't know, but have you tested using a blob type in your structure?
  12. You could of course check if the user is logged in or not, too. Don't display the login form is the user is logged in. If the are not logged in, they don't need the "update profile" form.
  13. Hey, everybody. I'm using the function mysqli_fetch_object. This function is returning objects of the Class stdClass by default. (Main object class if I'm not mistaken). The function has an optional parameter "class_name". This gives you opportunity to specify a class the object should be of. (A Season, Player, Team or any other class) The problem is that mysqli_fetch_object is not returning anything if I specify a Class name. Do anyone know if this is a common problem or maybe a host issue? My host is running Version 5.2.17. I have two classes and a main/run file to demonstrate this. Season class initializeses Season Objects, and SeasonList Class adds objects to an array. The Classes are simplified by removing checks/etc. Class Season: <?php class Season { // Object variables private $id; private $season; // Create Season Objects. Checks are removed for simplicity here public function __construct($id, $season) { $this->id = $id; $this->season = $season; } // Standard toString method for printing out objects. public function toString() { return $this->id . ' - ' . $this->season . '<br />'; } } ?> Class SeasonList <?php class SeasonList { // Object variables private $seasonList = array(); public static $arrayPointer = 0; // __NOTE stdClass here__. public function addObject( stdClass $object ) { $this->seasonList[self::$arrayPointer] = array($object); self::$arrayPointer++; } // Return the array (hopefully) filled with Season objects public function getAllSeasons() { return $this->seasonList; } } ?> Run file season_test.php: <?php include("db.php"); $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME); // from db.php $mysqli->set_charset("utf8"); // include the classes include("SeasonList.php"); include("Season.php"); // Initialize a SeasonList Object $seasonList = new SeasonList(); // Create query to get Seasons from DB $query = "SELECT id, seasons AS season FROM abc_seasons"; if ($result = $mysqli->query($query)) { while ($obj = $result->fetch_object()) { $seasonList->addObject($obj); } } // Print_r on the SeasonList Array to check that data is there print_r($seasonList->getAllSeasons()); ?> This produces this result: (And this is correct) Array ( [0] => Array ( [0] => stdClass Object ( [id] => 1 [season] => 2009/10 ) ) [1] => Array ( [0] => stdClass Object ( [id] => 2 [season] => 2010/11 ) ) [2] => Array ( [0] => stdClass Object ( [id] => 3 [season] => 2011/12 ) ) [3] => Array ( [0] => stdClass Object ( [id] => 4 [season] => 2012/13 ) ) [4] => Array ( [0] => stdClass Object ( [id] => 5 [season] => 2015/16 ) ) [5] => Array ( [0] => stdClass Object ( [id] => 6 [season] => 2015/16 ) ) ) ---------------------------------------- If I change to $result->fetch_object('Season') however, I get NOTHING. This is Ok as the Method addObject expects a stdClass object. However, If I change that to "Season", it's still not working. This may seem like a small problem, but really, it's not. I only want to add Season objects to the array. I also just want to know why this is not working. *Pulling hair* Thanks for any help.
  14. Agree with Jon here. Check out Mysqli. The class i available both in procedural and object-oriented style.
  15. Agree. I stopped supporting IE6 two years ago. Let it die - don't support it.
  16. Hey, guys. Relax. Without knowing anyone of you, I can only assume Jon made suggestions to help you, Matt. You are obviously a smart guy, so why take this personally? Think you just lost each other here. No harm done, huh? Going back on topic now. I actually tried to comment on this some days ago, but I could not fully picture what you wanted. With that in mind, I concluded myself that this is not a "one-big-query"-thing. The data seems related, but not how you are going to display the data. That is what I concluded with, but as I said, I tried waiting for someone smarter to comment. In my experience, you join multiple tables/queries because it will make your life easier. I could, however, not think of any easy way to display this query as ONE without MORE logic. Easy understandable code is often good code. If this code makes sense to you, Matt, it's probably a good way to do it. If this, however, feels "wrong" in any way, I would have double-checked my table structures. I don't completely understand the use of this boolean-field. Anyway. Complete this script, and come back to it later if it needs improvement. It feels like you are feed up with this task. No need to bang your head against the wall over small things. Just a little encouragement, Matt. You're a way better programmer than I am. I've seen a lot of your brilliant solutions when you've helped people out. You're really good.
  17. Thanks again, Jon. I've now implemented it in some of my scripts. It's REALLY a time saver for us.
  18. The UI is better in this one. As for headers/other design, feel free to change it.
  19. Yeah. Of course the IPB logo is breaking the design a bit, but I'm sure such things are not worth commenting on. Of course the'll be replaced in time. There will always be small tweeks after a design update. As for the theme in general, it looks very good. Better than the last one.
  20. It depends on the functionality required. I never quote less than 500-600 english pounds for a website with a CMS like TXP or Wordpress. It also depends on how complex the design process is, if it need any additional code, etc. Web developement takes time. Try to give them a perspective on that. It will make it easier for them to calculate the cost.
  21. The easiest way would be to save the query in an array. That is what I do when I need a result set more than one time. $query = "SELECT ...."; mysqli_real_escape_string($connect, $query); $result = mysqli_query($connect, $query); // create empty array and fill it... $result_array = array(); while($fetch = mysqli_fetch_array($result, MYSQLI_ASSOC)) { $result_array[] = $fetch; // fill array } /* USE RESULTS */ foreach ($result_array as &$value) { // use me } Some questions though: - Can't you build the navigation before the second result set and display it later? - Could you create one query out of two? Remember that num_rows() is also possible to do with MYSQL-functions like COUNT(*) as num or the likes.
  22. Correct: print $_POST['name']; Correct: print 'I have some text before '.$_POST['name'].' and some text after'; Correct: print "I have some text before {$_POST['name']} and some text after": Edit: Removed ( & ).
  23. To sort by date, use ORDER BY: (GROUP BY does also work) ORDER BY meeting_date ASC Hartley is probably right about that WHERE-clause. Your syntax for using variables in i query is not right. That is why it seems right. $q3 = 'SELECT meeting_date FROM btc_meetings WHERE ( '.$year.' < YEAR(meeting_date) ) ORDER BY meeting_date ASC'; mysqli_real_escape_string($q3); // some security at least
×
×
  • Create New...