Jump to content

quyen

Member
  • Posts

    44
  • Joined

  • Last visited

Everything posted by quyen

  1. Thanks for your reply, Yeah you're right, I've used Header(); quite a lot in my php pages, ofcourse I used it for different purposes, I've been trying to comment all the //Headers, and use print "somthing"; to replaces Header commands, it works fine, but Whenever I remove one of the comment lines, the warning will appear straight away. I am sure I did something wrong, but I haven't found it yet. Maybe I already used Header in the file which is required in the php page. But I think you can use multiple Headers command on the same page or include or require, right? Thanks a lot for your help but really I don't want to use javascript in this case, because users can turn it off anytime, that means my website won't work ok without JS Quyen,
  2. <?php $arr = array("record1", "record2", "record3", "conditions"); $cond = "conditions"; foreach ($arr as $key => $value) { if($value == $cond){ print " $value "; } else{ print " $value "; } } ?>
  3. I've been trying to solve my problem by using http://www.desilva.biz/php/phprefresh.html and http://www.tizag.com/javascriptT/javascriptredirect.php, but I haven't solved my problems yet, I will try some other solutions, but I am still looking for someone to help me. I know "Warning: Cannot modify header information - headers already sent by (output started at C:\Inetpub\vhosts\qwebdesign.net\httpdocs\admin\index.php:15) in C:\Inetpub\vhosts\qwebdesign.net\httpdocs\admin\user_manager.php on line 319" is just a warning, not an error, but the thing is I don't want this warning to show up on the page, and whenever this warning is occurs, it stops redirecting. I will try to use Adam's solution and see what'll happen.... Thank you very much Adam, Quyen,
  4. Thanks a lot Wickham and falkencreative, I am sure I can solve my problems soon. Thanks again. Quyen,
  5. Well, I've tried that before but when you use headers to show a message before redirect to a page, actually you cannot see the message, the headers will execute straight away. Anyway thanks a lot ! Quyen,
  6. Thanks for you reply, I might have look at those links, and try to fix my problems. By the way, Do you know somehow we can redirect to a page without using header("Location: $url") ?. In my case: I want to show a message before redirect to any pages? Thank you very much for that. Quyen,
  7. Hello everybody, This is a warning i've got whenever I use "header("Location: $url"); ". Warning: Cannot modify header information - headers already sent by (output started at C:\Inetpub\vhosts\qwebdesign.net\httpdocs\admin\index.php:15) in C:\Inetpub\vhosts\qwebdesign.net\httpdocs\admin\user_manager.php on line 319 Is there any solution to redirect to a url without using "header("Location: $url"); Or somehow I can fix the above problem? I've been reading some topics on some websites, and they are all about how to use header("Location: $url"); but i haven't found any right answer for my situation. Note: "header("Location: $url");" runs ok on localhost at my computer, I only got this problem when I upload my project to a hosting. Thank a lot for helping me! Quyen,
  8. Hi, I just help you to fix the problem. I hope it works fine on your pc. Have a nice day (~_~) ! <?php /* BEFORE YOU RUN THIS FILE, YOU SHOULD CHANGE THE PASSING VALUES FOR CONSTRUCTOR. * THEN IT WILL WORK OK. */ ////////////////////////////////////////////////////////////////////////////////// /* Acctually This object connect to db, but haven't done anything on the * database 'mysql' yet. */ $myObj = new DBConnect("localhost","root","","mysql"); $myObj ->connectToMySQL(); /* You need to pass the values to the arguments for the constructor from superclass DBConnect. If not $dbData won't know how to connect to database. */ $dbData = new DBData("localhost","root","","information_schema"); /* You need to connect to MySQL before work on any databases. */ $dbData ->connectToMySQL(); /* - Because the class DBData defined only one method selectDB(); - Whenever you want to work with a database, you need to connect to MySQL first. - In your situation, You didn't call method connectToMySQL() from superclass DBObject. --> That's why You cannot select any databases.(Thats why you've got the errors) */ $dbData ->selectDB(); class DBConnect{ ///////////////////////////////////////////////// // PROTECTED PROPERTIES ///////////////////////////////////////////////// protected $hostname, $username, $password,$db_name, $con ; /** * Constructor * @param String $hostname,$username,$password,$db_name. * All information we need to provide whenever connect to db. */ public function __construct($hostname,$username,$password,$db_name){ $this->hostname = $hostname; $this->username = $username; $this->password = $password; $this->db_name = $db_name; } /** * Connect to MySQL. * @return void */ public function connectToMySQL(){ $this->con = mysql_connect($this->hostname,$this->username,$this->password); if($this->con){ echo " Connected sucessfully to MySQL . "; } else{ die( " Could not connect to MySQL" . mysql_error() . ". "); } } } /* * DBData class extends DBConnect */ class DBData extends DBConnect{ /* This class doesn't define any constructors. Whenever you create a object from * this class, The object will automaticaly refer to constructor of * super class (DBObject class). cause DBData extends from DBConnect class */ public function selectDB(){ $result = mysql_select_db($this->db_name,$this->con); if($result){ echo " Connected sucessfully to database ' ".$this->db_name." ' . "; } else{ die( " Could not connect to database ' ". $this->db_name. " ' ".mysql_error() . ". "); } } } /* You don't need to create a class just for closing a connection. * This method you can build in DBConnect or DBObject class. But anyhow this is your option * Maybe you have some special reason to have this class. */ class DBClose extends DBConnect{ function closeConnection(){ mysql_close(); } } //GOODLUCK ?> Quyen,
  9. 100% sure this won't work. I will reply to you soon, cause i am working now. But goodluck.
  10. Hi, Sorry I haven't replied to you yet! Cause I just take a look at CSS forum(*_*). About your question: - To open a connection to a database or close this connection is not complicate, right? But the thing is how to organize your coding in php file? For me I won't put them in a seperate files. Cause close or open is methods (behaviors) of objects. With mysql_connect() and mysql_close() Why don't you write some methods like this: function connectToMySQL(){ //You write your code here } function closeConnection(){ //Do something else here and at the end you can mysql_close();//For example } And then: Whenever you create a object from the class above, after you are done everything like select a database, execute sql queries,....After you're done you just need a line of coding like: objectName.closeConnection(); Notes: For me, I don't care much about number of php files, I care more about what my object can do? Is it enough or need some more fields, methods,.... If your object is perfect, that mean you did a great job (*_*). Don't worry about how many php file you going to create, lets care about how many object do u need in your project? And all fields & methods of your objects are enough or not? And one more thing I guess you need to read some more is about OOP. Cause whenever you want your object do something, you will go and create a object and then call the suitable method of the object for it. All the methods you create in your projects are called by objects (*_*). I am not sure if this could help u! but still hope that you understand what i mean! Let me know if you need something! Quyen,
  11. Hi kitster79, I just take a look at your html and css file. And now I guess I know why you have the purple background between "#indexThmbs" and "#indexHeader1". Let edit your css file at this ID = "indexThmbsInner" like this: #indexThmbsInner { width: 900px; margin-right: auto; margin-left: auto; height: 130px; margin-top: 0px; } I have no idea why you want to put margin-top: 65px; (*_*). But it was the problem for you layout. Check it out soon. Hope this can help you! have a nice day. Quyen,
  12. Hi again, I just finished it, have look and I hope this could help you a bit (*_*). Notes: In this database, I created a table called 'yum' , 2 fields are 'id' and 'name'. When you test this example, try to created a database has the same my database information. If not then you will get some errors. OR you can set the database name and table name in the code below. DBObject.php > <?php /* Created by Quyen. 11 July 2009 * Email : cuncon.it@gmail.com * DBObject.php */ /* * I just create a very simple class called DBObject */ class DBObject{ ///////////////////////////////////////////////// // PRIVATE PROPERTIES ///////////////////////////////////////////////// private $hostname, $username, $password, $db_name, $con, $table_name; /** * Constructor * @param String $hostname,$username,$password,$db_name. * All information we need to provide whenever connect to db. */ public function __construct($hostname,$username,$password,$db_name){ $this->hostname = $hostname; $this->username = $username; $this->password = $password; $this->db_name = $db_name; } /** * Connect to MySQL. * @return void */ public function connectToMySQL(){ $this->con = mysql_connect($this->hostname,$this->username,$this->password); if($this->con){ echo " Connected sucessfully to MySQL . "; } else{ die( " Could not connect to MySQL" . mysql_error() . ". "); } } /** * Select a database you will work with. * @return void */ public function selectDB(){ $result = mysql_select_db($this->db_name,$this->con); if($result){ echo " Connected sucessfully to database ' ".$this->db_name." ' . "; } else{ die( " Could not connect to database ' ". $this->db_name. " ' ".mysql_error() . ". "); } } /** * Get back the name of database. * @return String $db_name */ public function getDBName(){ return $this->db_name; } /** * Set table name that you want to select data from. * @return void */ public function setTableName($table_name){ $this->table_name = $table_name; } /** * Get back the name of a table * @return String $table_name */ public function getTableName(){ return $this->table_name; } /** * View data of a table */ public function viewTableData($db_name,$table_name){ mysql_select_db($db_name); $sql = "Select * from $table_name"; $result = mysql_query($sql); $count_fields = mysql_num_fields($result); $count_rows = mysql_num_rows($result); $index = 0; echo " </pre> <table border="1" width="50%">This is '$table_name' table dataID Fruit name".$row['id']."".$row['name']."</table> <br> "; <br> }<br><br> /**<br> * Show a simple message.<br> * @return void<br> */ <br> public function showMessage(){<br> echo "<br><br><br> I don't have much time, because I have something to do tomorrow, then if you<br> have some time, read some more about MVC (Model - View - Control) to organize your <br> object better.For now I just put all them together. Work more on your database (*_*)....<br><br> Have a good time!<br><br> ";<br> }<br><br> }<br>?&gt CreateObject.php <?php //Include DBObject.php file include ("DBObject.php"); //Create objects from DBObject class. $myObj = new DBObject("localhost","root","","mydb"); //Call methods of objects. $myObj ->connectToMySQL(); $myObj ->selectDB(); $myObj ->setTableName("yum"); $myObj ->viewTableData($myObj->getDBName(),$myObj->getTableName()); $myObj ->showMessage(); ?> If you have any question, just email me at cuncon.it@gmail.com. or leave your reply in this forum. Goodnight. Quyen,
  13. Did you mean that: 1. You want to select your data from table called 'yum'. This table has two fields: 'id' and 'fruit'. 2. You need to select all the records from the table above, and fill up them in a table? like id name 1 banana 2 apple 3 warter melon .. ................... Is that what you mean?(*_*) Quyen,
  14. Hi, You are welcome, i am not sure this will be a good example for you but I hope so. DBObject.php <?php /* Created by Quyen. 11 July 2009 * Email : cuncon.it@gmail.com * DBObject.php */ /* * I just create a very simple class called DBObject */ class DBObject{ ///////////////////////////////////////////////// // PRIVATE PROPERTIES ///////////////////////////////////////////////// private $hostname, $username, $password, $db_name, $con; /** * Constructor * @param String $hostname,$username,$password,$db_name. * All information we need to provide whenever connect to db. */ public function __construct($hostname,$username,$password,$db_name){ $this->hostname = $hostname; $this->username = $username; $this->password = $password; $this->db_name = $db_name; } /** * Connect to MySQL. * @return void */ public function connectToMySQL(){ $this->con = mysql_connect($this->hostname,$this->username,$this->password); if($this->con){ echo " Connected sucessfully to MySQL . "; } else{ die( " Could not connect to MySQL" . mysql_error() . ". "); } } /** * Select a database you will work with. * @return void */ public function selectDB(){ $result = mysql_select_db($this->db_name,$this->con); if($result){ echo " Connected sucessfully to database ' ".$this->db_name." ' . "; } else{ die( " Could not connect to database ' ". $this->db_name. " ' ".mysql_error() . ". "); } } /** * Later you can write some methods to set and get value of Fields (Variables). * @ */ public function setDBName() {} /** * Show a simple message. * @return void */ public function showMessage(){ echo " Now you can execute any queries or create a database or do what ever you like (*_*).... Have a good time! "; } } ?> CreateObject.php <?php //Include DBObject.php file include ("DBObject.php"); //Create objects from DBObject class. $myObj = new DBObject("localhost","root","","mysql"); $anotherObj = new DBObject("localhost","root","","information_schema"); //Call methods of objects. $myObj ->connectToMySQL(); $myObj ->selectDB(); //$myObj ->showMessage(); $anotherObj->connectToMySQL(); $anotherObj ->selectDB(); $anotherObj ->showMessage(); ?> Have a nice day! Quyen,
  15. Hi, I just created an object today, If you like I can share it with you. My object just does something simple like connect to mysql, select any database that you want to work with. Let me know if you interested this. Quyen,
  16. Hi, You know I don't speak English well, I was replying to Akurtula, and I just tried to give him some of my ideas. Sorry if I didn't explain it that well.
  17. Hi, I think Stefan's right, After you read some more about Model - Control - View, You may understand what does he mean by that. For now I have some comment for you like these: for Q2: Acctually I don't think there are any rule to say that your class has to be this long or that long. Number of fields and methods in a class, it depends on your object you are creating. for Q3: You should read some more about OOP. if you understand OOP then you might have something to do with this object (the object i mentioned here is about the object in your question Q3). How to organize your php files??? (0_0). Let's think about your question. You can have different classes in a file. thats ok. Lets think your php file (You have different classes in this file) look like a library php file wherever you want to create an object, you can include that library file in and create your object. You also create different library php files depend on how you want to organize your projects. Thats all I can say now. Hope it can help you. Sorry my english is pretty bad, then still hope that you can understand what i mean. Quyen,
  18. Hi, Well, i think it depends on what is your purpose? what do you want it to do? and tags are both very helpful. programmers use tag : 1. To create a link to another document, by using the href attribute 2. To create a bookmark inside a document, by using the name attribute example: http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_link_test The tag is used to define a client-side image-map. An image-map is an image with clickable areas. The name attribute is required in the map element. This attribute is associated with the 's usemap attribute and creates a relationship between the image and the map. The map element contains a number of area elements, that defines the clickable areas in the image map. This example will help you to choose the best options : http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_areamap Quyen,
  19. "CSS is the acronym for: ?Cascading Style Sheets?. CSS is an extension to basic HTML that allows you to style your web pages." I think this is the best choice. I don't know if someone could think of something else check this out : http://www.csstutorial.net/introductionCSS.php
  20. This is a example of hyperlink: home page | categories | contact us |
×
×
  • Create New...