Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] php/mysql accessing wikimedia database
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
Rukie
l33t
l33t


Joined: 26 Jan 2004
Posts: 692
Location: SE Wi, Home of cheese and cowtippers.......

PostPosted: Wed May 03, 2006 1:37 am    Post subject: [SOLVED] php/mysql accessing wikimedia database Reply with quote

I'm building a site but there has to be an easy way of writing to the file. I need something with a simple easy end user interface. It was suggested to me to use wikimedia. Anyways, I have it set up but I cannot seem to figure out how to setup the sql query and fetch. I just need to access the text.

http://meta.wikimedia.org/wiki/Page_table This is what I was workign off of, however I do have a wiki_ prefix on my tables in the database CCHS.
I can connect fine and retrieve information.. I just can't seem to figure out how to retrieve the RIGHT information.

I'm also using a variable, $homebody to choose what to select, what to look for.

I'm on apache2 linux with php5 and sql, a little home server thing I'm working on atm that will hopefully be uploaded onto another server.

Any ideas/help would be greatly appreciated. Thankyou

select old_text from wiki_page, wiki_revision, wiki_text where page_title = 'Mrs._Harford' and page_latest = rev_id and rev_text_id = old_id;
works fine in the mysql prompt..

I need a $homebody where Harford is, but neither one works in the php... heh
_________________
Gentoomania! Support the Open Source!
http://www.rukie.ath.cx


Last edited by Rukie on Thu May 04, 2006 12:55 am; edited 1 time in total
Back to top
View user's profile Send private message
Rukie
l33t
l33t


Joined: 26 Jan 2004
Posts: 692
Location: SE Wi, Home of cheese and cowtippers.......

PostPosted: Wed May 03, 2006 11:21 am    Post subject: Reply with quote

any help at all?
_________________
Gentoomania! Support the Open Source!
http://www.rukie.ath.cx
Back to top
View user's profile Send private message
Aurisor
Guru
Guru


Joined: 20 Sep 2003
Posts: 361
Location: Boston MA

PostPosted: Wed May 03, 2006 2:27 pm    Post subject: Reply with quote

What exactly are you trying to make? Your post isn't exactly clear, but it sounds like you're trying to just make a kind of beginner web site using a database and frontend. If that's the case, a wiki is totally overblown for what you need. If you just go to a SQL prompt and do something like this:

Code:

CREATE TABLE `articles` (
  `id` int(11) NOT NULL auto_increment,
  `text` text NOT NULL,
  PRIMARY KEY  (`id`)
);


That'll create a table in your database. Then you can go like this:

Code:

<html>
<body>
<?php
//connect to the database (fill in these vars yourself)
$db = mysql_pconnect($host,$user,$pass);
//connect to your database (fill in the database yourself)
mysql_select_db("database",$db);

//if the user went to article.php?id=2 retrieve the article
$id = $_GET['id'];
$txt = $_POST['txt'];

if($_GET['id']){
   mysql_query("select `text` from articles where id = '{$_GET['id']}' limit 1");
   $myrow = mysql_fetch_array();
   $txt = $myrow[0];
}

//otherwise check to see if they're submitting an edit
if($_POST['id']){
   //update article
   mysql_query("update articles set `text` = '" . addslashes($_POST['text']) . "' where id = '{$_POST['id']}'");
} else if($_POST['text']){
   //or saving a new article
   mysql_query("insert into articles (`text`) values('" . addslashes($_POST['text']) . "')");
   mysql_query("select last_insert_id()");
   $myrow = mysql_fetch_array();
   $id = $myrow[0];   
}

//here's the actual form, show the text if we're editing
?>
<form action='' method='post'>
<textarea name='text'><?= $txt; ?></textarea><br/>
<?php if($id) echo "<input type='hidden' name='id' value='$id'/>\n";
<input type='submit'>
</form>
</body>
</html>


Be warned, I haven't bugtested that at all, and I don't know what your background is like, so that may be a bit overwhelming. However, that example there will let you save and edit articles using a SQL database...it contains all the concepts you'd need to store and retrieve documents.
Back to top
View user's profile Send private message
Rukie
l33t
l33t


Joined: 26 Jan 2004
Posts: 692
Location: SE Wi, Home of cheese and cowtippers.......

PostPosted: Wed May 03, 2006 7:18 pm    Post subject: Reply with quote

I'm able to read and understand code very well, I just can't replicate it/write it on my own yet :p
I'm using wikimedia, similar to wikipedia to create a frontend for editing/updating content with multiple users. I then want to display this information on my own frontend, but I'm having difficulty accessing the right information from the database. I'm in school now but as soon as I get home I will look at my code again and try to fix any errors there may be. Thank you for the reply and I hope it helps :)

If someone else has any good knowledge of wikipedia and how to query its database, it would be helpful :)
Personally, I would like to use the frontend from blogcms for updating content but I don't have the time to construct such a huge website. As I have more time I will try to phase out wikimedia, but for the time being its the easiest way.

Thanks again.
_________________
Gentoomania! Support the Open Source!
http://www.rukie.ath.cx
Back to top
View user's profile Send private message
Rukie
l33t
l33t


Joined: 26 Jan 2004
Posts: 692
Location: SE Wi, Home of cheese and cowtippers.......

PostPosted: Wed May 03, 2006 9:13 pm    Post subject: Reply with quote

ok.. I think I'm making progress. I believe nothign was working because of the quotes, those things get confusing :p
The next thing.. now it displays the result "Resource ID #3"
here's my current code.
Quote:

if (! $thiscontent = mysql_query('SELECT old_text from wiki_page, wiki_revision, wiki_text where page_title = "Mrs._Harford" and page_latest = rev_id and rev_text_id = old_id'))
{
die("Cannot execute the query: ".mysqlerror());
}
else
{echo $thiscontent;}


however, the same command above works perfectly fine in a terminal when I use mysql..
_________________
Gentoomania! Support the Open Source!
http://www.rukie.ath.cx
Back to top
View user's profile Send private message
mesch.t
n00b
n00b


Joined: 25 Oct 2004
Posts: 33

PostPosted: Wed May 03, 2006 10:33 pm    Post subject: Reply with quote

hi!
you should google for some php tutorial..

Quote:

if (! $thiscontent = mysql_query('SELECT old_text from wiki_page, wiki_revision, wiki_text where page_title = "Mrs._Harford" and page_latest = rev_id and rev_text_id = old_id'))
{
die("Cannot execute the query: ".mysqlerror());
}
else
{echo $thiscontent;}


after you have executed the query you have to loop over the produced result, like this

Code:

   if (mysql_num_rows($thiscontent) > 0)
   {
           // iterate through resultset
           while($row = mysql_fetch_row($thiscontent))
           {
                   echo $row[0];
           }
    }

Back to top
View user's profile Send private message
Rukie
l33t
l33t


Joined: 26 Jan 2004
Posts: 692
Location: SE Wi, Home of cheese and cowtippers.......

PostPosted: Wed May 03, 2006 10:54 pm    Post subject: Reply with quote

heh, just checked this and ya, I used mysql_fetch_array, works great :-D
Now I just need to setup a parser and I'm done :-D
_________________
Gentoomania! Support the Open Source!
http://www.rukie.ath.cx
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum