Hi all. I'm just starting to learn php and sql on my own before I go to college for it. I am understanding how to write the sql and php codes easily enough. I understand how to create a database and post queeries to it and have them show up in the queery results. What I am not seeing anywhere in any of the tutorials is how to get the queeries to show up on a page. example: If I use a simple php page with the opening and closing tags of php on it and insert the following code it should show up on the page in the browser correct? $sql = "SELECT * FROM memb_info LIMIT 0, 30 "; I cant get this to show on the page. Am I missing a step somewhere? I've also tried it with calling the database as well using use database; above that in the tags.
Check out the book "PHP6 MySQL Bible" I have a copy of it. It has virtually everything in it with examples. Also google the php manual, it is always usefull. You can get the book on amazon, it isn't very expensive: http://www.amazon.com/PHP6-MySQL-Bible-Steve-Suehring/dp/0470384506
Actually you are missing a lot of things.. I will give a fair idea of things u need to do to get the query display results for you : 1. Make a mysql database 2. Make an user 3. Assign all privileges to that user for that particular database 4. Open database and make a table in it 5. Put some entries in the table Now comes the coding part You first need to get a connection to the database You can do it using the following code (Modify it according to your needs) mysql_connect("localhost", "your_username_here", "your_password") or die(mysql_error()); PHP: Then select the database : mysql_select_db("your_database_name_here") or die(mysql_error()); PHP: Now take the query you need to execute in a variable, for e.g. : $sql = "SELECT name,addr,phno FROM customer"; PHP: Execute the query, and since it will produce some results, store it in a variable : $result = mysql_query($sql); PHP: Now, you have the results in the variable $result Now to print them using php use the following code while ($row = mysql_fetch_assoc($result)) { echo $row['name'] . " " . $row['addr'] . " " . $row['phno'] . "<br/>"; } PHP: The above code will print the name, address and phone no. taken from your database for every row selected by executing the query earlier. Hope this gets you going... (And once you get started with it, start using google to get help. Its not that hard as it seems )
Hey thanks for the code. Got it to work just fine. I also asked this same question in another forum and they gave me basicly the same code except that theirs was 3 times longer and didn't have the or die in the code. Now I just need to figure out how to put each variable returned into it's own html table on the page. Got a lot to learn but I enjoy it.
Oh ok ok! i just tried to provide you things from which i had learnt Glad that it was helpful And yep there's lots to learn, try making websites from innovative ideas, it helps you create new algorithms and hence search and learn new things when you get stuck at something.