SitePoint Sponsor |
|
User Tag List
Results 1 to 12 of 12
Thread: MySQL Question
-
Dec 31, 2000, 17:44 #1
- Join Date
- Oct 2000
- Location
- Sheffield, UK
- Posts
- 437
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
OK - i have a MySQL database called Pages
in it, there are 4 fields...
page
dateadded
text
author
how would i get it so that if i typed in misc.php?page=legal and it would find the record with legal in the page column, and then display the dateadded and author below it
i'm only a beginner...so be nice to me
-
Dec 31, 2000, 17:54 #2
- Join Date
- Jul 1999
- Location
- Chicago
- Posts
- 2,629
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Something like this, assuming you were already connected:
Code:if($page == "legal") { $results = mysql_query("select * from Pages where page = 'legal';"); while($row = mysql_fetcharray($results) { echo "Lalalala $row['page'] is the page title"; }
-
Dec 31, 2000, 17:59 #3
- Join Date
- Apr 2000
- Posts
- 1,483
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I think you need something like this:
Code:<?php mysql_connect("server", "user", "pass"); mysql_select_db("db"); if ($page == "legal") { $query = mysql_query("SELECT * FROM pages WHERE page='$page'"); $record = mysql_fetch_array($query); echo("<table><tr><td>Page</td><td>" . $record["page"] . "</td></tr><tr>Date</td><td>" . $record["dateadded"] . "</td></tr> --repeat that code for the other things you want to display-- </table>"; }
darn I see Quinn beat me to it while i was typing the reply
</edit>
-
Jan 1, 2001, 02:05 #4
- Join Date
- Oct 2000
- Location
- Sheffield, UK
- Posts
- 437
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
OK...whats wrong with the code? i get parse error on line 12
Code:<HTML> <HEAD> <TITLE>Title</TITLE> </HEAD> <BODY> <?php mysql_connect("localhost", "root", "xxxxxxxx"); mysql_select_db("misc"); if ($page == "legal") { $query = mysql_query("SELECT * FROM page WHERE page='$page'"); $record = mysql_fetch_array($query); echo("<table><tr><td>Page</td><td>" . $record["pagetext"] . "</td></tr><tr>Date</td><td>" . $record["dateadded"] . "</td></tr></table>"; } ?> </BODY> </HTML>
-
Jan 1, 2001, 02:10 #5
- Join Date
- Aug 2000
- Location
- Land of the long white cloud
- Posts
- 556
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Line 12
echo("<table><tr><td>Page</td><td>" . $record["pagetext"] . "</td></tr><tr>Date</td><td>" . $record["dateadded"] . "</td></tr></table>";
should read
echo "<table><tr><td>Page</td><td>" . $record["pagetext"] . "</td></tr><tr>Date</td><td>" . $record["dateadded"] . "</td></tr></table>";
spot the difference
Hope that helps!
SiteOptions >> Services :: Products :: Contact
Developers of PHP, C++, Visual Basic, MySQL, and more!
-
Jan 1, 2001, 03:14 #6
- Join Date
- Oct 2000
- Location
- Sheffield, UK
- Posts
- 437
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
OK...another problem
i'm designing a content management system now, so that i dont need to upload the files...but i need to add the if (page == $page) (quick guess) to it to make it show up
i.e if i add misc.php?page=jokes then i need the
Code:if ($page == "jokes") { $query = mysql_query("SELECT * FROM page WHERE page='$page'"); $record = mysql_fetch_array($query); echo "<center><font=verdana><size=2><b>" . $record["pagetext"] . "<br><br>Date Added:" . $record["DateAdded"] . "<br><br>Generated via AtomicEngine 1.1" ;
any ideas
also, qslack, james and mad-onion...do you want a mention in my sites credits...this is the engine that powers the whole site and you really are helping!
Alex
-
Jan 1, 2001, 04:26 #7
- Join Date
- Apr 2000
- Posts
- 1,483
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yes you need to add another if statement for each page you want to display, eg:
Code:if ($page == "helllo") { //code for hello page } if ($page == "goodbye") { //code for goodbye page }
-
Jan 1, 2001, 04:46 #8
- Join Date
- Apr 2000
- Posts
- 1,483
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
OK I've just been told that I misunderstood the question
so I'm gonna have another go
Code:mysql_connect("localhost", "root", "pass"); mysql_select_db("db"); $query = mysql_query("SELECT * FROM page WHERE page='$page'"); $record = mysql_fetch_array($query); echo "<center><font=verdana><size=2><b>" . $record["pagetext"] . "<br><br>Date Added:" . $record["DateAdded"] . "<br><br>Generated via AtomicEngine 1.1" ;
<Edited by James on 01-01-2001 at 05:05 AM>
-
Jan 1, 2001, 04:59 #9
- Join Date
- Oct 2000
- Location
- Sheffield, UK
- Posts
- 437
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ok...error
bear in mind i have it in a template, so its a few lines extra
Fatal error: Call to undefined function: mysql_select() in c:/blds/htdocs/misc.php on line 224
you can also see its a win32 server
-
Jan 1, 2001, 05:01 #10
- Join Date
- Apr 2000
- Posts
- 1,483
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Sorry bout that Alex, mysql_select should be changed to mysql_query.
I've fixed it in my original post as well
(thats what happens when i've stayed up too late for a new years party)
-
Jan 1, 2001, 09:17 #11
- Join Date
- Oct 2000
- Location
- Sheffield, UK
- Posts
- 437
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hmmm..'nother MySQL question:
Code:<?php else: mysql_connect("localhost", "root", "oblivion"); mysql_select_db("misc"); mysql_query("INSERT INTO pages(page, Author, DateAdded, pagetext) VALUES ('$page', '$name', 2001020, '$pagetext')") endif; ?>
Alex
Thanx James
-
Jan 1, 2001, 09:25 #12
- Join Date
- Apr 2000
- Posts
- 1,483
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You could do it like this:
Code:mysql_query("INSERT INTO pages SET page='$page', Author='$author', DateAdded='20001020', pagetext='$pagetext'");
Bookmarks