Jump to content

Mr_CHISOL

Members
  • Posts

    404
  • Joined

  • Last visited

Everything posted by Mr_CHISOL

  1. Mr_CHISOL

    PHP and AJAX

    Hi!I have some suggestions, but I would need to see your code (both JS and PHP, and perhaps awhat yo get from responseText), before I can give you a good help...
  2. Yes.Can't see any reason to why you should use (or need...) more than one table for this (other than usermanagement, but you didn't need that, so).If you would have a table for every user you would end up with ALOT of tables (say 1 mil. messages > [guessing] 10 000 - 50 000 individuals, or say 100 000 posts > 500 - 10 000 individs) It would be a nightmare to manage/administrate...Good Luck and Don't Panic!
  3. Mr_CHISOL

    Simple PHP Call

    You can go thru them like this: ...echo "<ul>\n";foreach ($xml->INFOBLOG->SITE as $site) { // Work with the SITE in $site: echo '<li><a href="'.$site->LINK.'" title="'.$site->DESC.'">'.$site->NAME.' - '.$site->DESC."</a></li>\n";}echo "</ul>\n"; Note: I ignored the attribute url to LINK (I used the content of LINK as the url), as I couldn't figure out the reason for the url-attribute...To get the attribute use the following: $site->LINK['url']
  4. First:Well it works, but the reason to why I recommend having a default is that you are much more like to have it on the top (as a "rule") and having it in the middle on much lesser cells (as an "exception"). By using a default you never have to worrie about setting vat on every cell, instead it's there by default.Yes, it saves code, but the main reason to it is to save some writing (I know; same thing) and headakes, mainly when you forgot to add vat to some cells (then you need to go over your code again to find the cells).If you still want to use to seperate class (and no default) you should set class="vat" to all cells in your table...
  5. When I have that problem I use that rule than this class for cells that need the content in the middle: .vac { vertical-align: middle } (vac as in vertical align center)
  6. Hi!I don't think it's a problem with the PHP, instead (as usual) it's IE that miss things up...try adding this into your head-tag (or the CSS-file, then remove the style-tags) <style type="text/css"> td { vertical-align: top }</style> It should make the content to be at the the top in all the cells (including the ones in the "inner" table).When it comes to PHP you can remove the double quotes, and emove whith singlequotes instead (looks better): // Orig:echo "<table width=\"\" border=\"1\" cellpadding=\"1\" cellspacing=\"0\" bgcolor=\"#999999\" bordercolor=\"#B51628\">";// Better:echo '<table border="1" cellpadding="1" cellspacing="0" bgcolor="#999999" bordercolor="#B51628">'; I also remove the with argument as there's no reason to use it when empty (Not sure on that it's eaven supported anymore [XHTML])Then I would recommend using CSS for all formating/layout colors etc. It's much easier and you get much cleaner code.EDIT:Missed the images (guess you added them later). Looks like you have problems with the height also... Remove any empty arguments (including height="") and try it in IE, if that doesn't work use CSS (for example try the "holy hack") to give the table a minimum height: table { height: 1%; } or soomething like that (not realluy holy hack, but still...Good Luck and Don't Panic!
  7. Mr_CHISOL

    Simple PHP Call

    There would also be a problem with this: $xml->load($sites.xml); I don't know what's in $sites, but I guess it's the beginning of the filename, change it to one of the below: $xml->load($sites . '.xml');or$xml->load('sites.xml'); (The value of the var. $sites with the .xml extension added, or a file called sites.xml)But you don't need DOM to open a file to then use with SimpleXML (Constructor info), just open it with SimpleXML from the beginning: <?php$xml = new SimpleXMLElement('sites.xml', NULL, true);print($xml->INFOBLOG->SITE->NAME);unset( $xml );?> Good Luck and Don't Panic!
  8. :?)Ok, that's a good reason. ;?)
  9. Ok, Why isn't it possible?
  10. I know that you know the quires, they was anly a "bi-product" of what I was writing.The essential part of my post was the other text.I Can't see another way, and I don't think it's "unenfficiant". A use of a seperate table for each user would be a bad way.Eaven with a million posts there shouldn't be a problem (unless you're going to display all at once ;?) ), not when it comes to getting the messages, but perhaps when it comes to space.One thing to do is perhaps a "cleanup"; once a week remove all messages that are more than a month old.
  11. Hi!I would start with a table for the messages, then how I would proceed depends on if I allow any visitor to post, or only those who has a login..If any visitor is allowed to post, you only need one table with mess. and then store the name as a string. To see all posts by that author you just get the name and compares it as so SELECT * FROM messages WHERE name = '$name' One problem with is that different visitors can post using the same name.The other way, to only let "members" to post, requires a second table with the informat abou the users (name/username, password, email etc)Then you just use the users id to assosciate the post with the user: SELECT * FROM messages WHERE id=$id Something, like that. Very abstract, but still...Good Luck and Don't Panic!
  12. Sorry, Missed the function, Hard to see without a "code field".I would still recommend you usin readline().I know I had this problem a few years ago in C++ (hade course in school), as what I can remember is that there were problems with newlines in the output, that it read to the next newline, which for some reason was one that was outputted. Don't remember exactly how I fixed the problem (it was the same, it got the first input, but not the second).Sorry to not be more helpfull
  13. Unless you don't have an OLD version of PHP (< 4.3) you shouldn't have a problem using ctype_digit() (If you have an old version DO UPGRADE).When it comes to is_int() it will return false if the variable is a string, so there's three ways to get this working:1. use ctype_digit() (!)2. use is_numeric(), note that this works on strings (as you get from POST/forms) and will return true if it's for ex. "2", BUT it will also return true if it's hex (0xFF), float (3.14) or exponential (+0123.45e6)3. "Cast" the value into int first or in the check using settype() Note that this will remove characters from the string, if there's any, and still return true...Hope that helped!Good Luck and Don't Panic!
  14. Since When???I use variables in strings like that frequently with no problem at all.BUT, you can't include a variable directly if you use single quots ('), only if you use double quots (").Then I didn't find read() in the PHP manual, but try readline() instead, to see if that works better.Good Luck and Don't Panic!
  15. Try calling the function _after_ you hace declared it....
  16. Hm I think you have some errors, among this: var xmlHttpfunction showUser(str)...should be:var xmlHttp;function showUser(str)... I preffer using XML to send the information, rather than sending and repling a select. To use XML also means that you can include more data for different selects/fields or places with no hassle...Take a look at this post and see if it can help you: http://w3schools.invisionzone.com/index.php?showtopic=11742#A tip if you use Firefox is to use the Error Console, if you don't already have it you should find it in the extension library (Developer Tools). It's a great help when working with JS, but also when working with XHTML/XML and CSS.Hope that helped..Good Luck and Don't Panic!
  17. Mr_CHISOL

    echo a number

    You also use mysql_fetch_array() (which returns an normal array), use mysql_fetch_assoc() to get it as an assoc. array/"hasmap" (as you use it)or just use $row[0] as you only get one field..
  18. Take a look at this: http://php.net/manual/en/function.imagecre...color.php#66448
  19. Was there some unclariyies? (It prob. were...)You could find some more info about ajax here: http://www.w3schools.com/ajax/.The code I gave you is mostly done (ask if you have any questions), it's just to copy and paste.. ;?)
  20. Firtst: You are creating the image(s) in every loop (a new image in every loop), I would put his above the loop (and remove it from the loop): $im = imagecreatetruecolor( 20*strlen($text), 20 ); Don't forget to destroy $image in the end of each loop (as you create a new every time)Than you might have a problem with GIF-transparancy, nut sure on how to solve that though...Last: I think this line is wrong: 0 = $x; It's backwardsHope that helped..Good Luck and Don't Panic!
  21. Hi All!Wrote a small, but usefull script today that I would like to share with anyone that might need it.It extracts specific constants that's used to translate projects:(It can be a #### to get all the constants manually. I guess I'm not alone with this problem, and not alone on solving it, but here's my code anyway) <?php$contents = file_get_contents( 'file.php' );$prefix = 'MYPROJ';$save_to_file = false;$filename = "english.php";$matches = array();preg_match_all( '/_'.$prefix.'[A-Z0-9_]+/', $contents, $matches );$text = "<?php/*** @package MyProject* @version v0.1b* @copyright It's Me* @license CC-GNU GPL v2*/\n\n";foreach ($matches[0] as $match) { $text .= 'define( '.$match.', "" );'."\n";}$text .= "\n?>\n";if ($save_to_file) { file_put_contents( $filename, $text );} else { echo $text;}?> (You can also download it via https://kachtus.net/projects/get_trans_strings.phps or https://kachtus.net/projects/get_trans_strings.phpt)You can change the values to what you need (filenames, projectname atc). The script can output to either a file (using $filename) or to standard output (console, browser etc).I prefer the last, and do like this (console) $ php5 get_trans_strings.php > languages/english.php You can also put it up on your server (together with the "latest" project code) and give the link to the script to let translators to get the latest translation file.Some modifications to the script might be: Getting info from more than one file Getting the filename to save to from input Getting the file to get the info from from input etc The script is adaptet for this sort of "translation constants" that look like this: <span><?php echo _MYPROJ_TITLE ?></span> and the language file: <?phpdefine( _MYPROJ_TITLE, "My Project" );?> I now there other ways to translate a script (using assoc. arrays etc), but this is the way I like the most. One advantage is that if there's no definition of the constant, the name of the constant is displayed instead, which is very helpfull..Good Luck and Don't Panic!
  22. Sorry I can't help you as much with the code at the moment, but here's some tips that you might find usefull:Use an loop to put how many rows/bands you want. You can create a form with just a select-box (maybe a "go-button", if you don't wnat to use onchange="document.form[0].submit()" on the select) that let's the buyer select how many band she/he wants to order, then put that many "rows" using the loop: for ($I = 0;$I < $num_of_bands; $I++) { /// The row.. ?><tr> <td>Band <?php echo $I+1 ?></td> <td><input type="radio" name="colour[]" /></td>...</tr><?php} Note the square brackets in the name, you don't wan't to set a default value (checked="checked") as this will stop the rest to work as intended.On page 2 you get each "field" (colour etc) as arrays in $_POST (you can use print_r($_POST); if you wnat a better "view"): $colour_arr = $_POST['colour'];... Just loop thru the color array, using for (not foreach) (as there should be as many in the other arrays, you can use the same "index").The one's without a value wont be send to the server.All this means that you can have any number of bands (from 1 to 100 and upwards...)How to you plan to save the order without an db? A db would simplify handling of the data about the customer and the orders, billing and which order has been sent to the buyer etc...Hope that helped!Good Luck and Don't Panic!
  23. :?)Sory, no, only http://www.w3schools.com/php/And found this att google: http://www.tutorialized.com/tutorials/PHP/News-Publishing/1
  24. In the case of AJAX you could also return the data as an xml-structure and parse it using JS and add to the select/combo box.The JS could look something like this function StateChanged(){ if (XmlHttp.readyState == 4) { var XmlDoc = XmlHttp.responseXML; // Clear the select var sel = document.getElementById('districts'); for (I = 0; I < sel.length; ) { sel.remove( 0 ); } // The the districts (DOM) Districts = XmlDoc.getElementsByTagName("district"); // Loop thru the districts for (var I = 0; I < Districts.length; I++) { // Get the districtname var District = Districts[I].firstChild.nodeValue; var DistrictId = Districts[I].item(0).getAttribute( 'id' ); // Create a new option var elOptNew = document.createElement('option'); elOptNew.text = District; elOptNew.value = DistrictId; // Get the select var elSel = document.getElementById('districts'); // Add the option/district try { elSel.add(elOptNew, null); // standards compliant; doesn't work in IE } catch(ex) { elSel.add(elOptNew); // IE only } } }function GetDistricts( Province ){ XmlHttp = GetXMLHTTPObject(); if (XmlHttp==null) { alert ("Your browser does not support AJAX!!"); return; } XmlHttp.onreadystatechange = StateChanged; var URL = "getdistricts.php"; URL = URL + "?province=" + Province; XmlHttp.open( "GET", URL, true ); XmlHttp.send(null);}function ProvinceSelected() { // Get the number/index (in the select) of the selected province var ProvinceNum = document.getElementById('provinces').selectedIndex; // Get the id of the province var Province = document.getElementById('provinces').options[ ProvinceNum ].value; // Get districts GetDistricts( Province );}.....<select id="provinces" name="provinces" onchange="ProvinceSelected()">{Provinces:<option value="ID">PROVINCE</option>}</select><select id="districts" name="districts"></select> The getdistricts.php-file could look something like this: <?php// Open db and so on...$query = "SELECT * FROM District WHERE ProvinceID=".$_GET['province'];$res = mysql_query( $query );echo '<?xml version="1.0"?>'."\n";echo '<province id="'.$_GET['province']."\">\n";while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) { echo ' <district id="'.$row['DistrictId'].'">'; echo $row['DistrictName']; echo " </district>\n";}echo "</province>\n";// Close DB and so on..?> Hope that helped...Good Luck and Don't Panic!
  25. Well, there's more simpler things (from "Hello World" to an calculator..).But make a news script is quit simple, but you will also learn more on that, than what you would with a simpler project.A news script is a good place to start, you get both integration with db/MySQL; getting and inserting data, displaying it in different "levels" ( a front page with headlines that links to the full text) and so on.
×
×
  • Create New...