Building Web Page

A place for users and developers of the Xataface to discuss and receive support.

Re: Building Web Page

Postby butchseaman » Fri Jan 29, 2010 2:36 pm

Yes... I see what you are talking about. I think I just need to spend a little time working with this... but you did a great job once again...
butchseaman
 
Posts: 21
Joined: Sat Jan 23, 2010 8:51 am

Re: Building Web Page

Postby mikewassil » Fri Jan 29, 2010 4:19 pm

Actually, if you know a little php, and probably you already do, creating a frontend drawing data from the same MySQL tables that you populate with Xataface is actually pretty easy to accomplish. This frontend that advertises my business does just that:

http://www.thedocumentsguy.com/

Each page of this "document" is a database record maintained via Xataface. The front end consists of a single php script, a single MySQL query, an index.php redirect to initiate the first query and an .htaccess to format the urls. The php script calls the query and functions as a template using css to format the content.

Here's the php script:

Code: Select all
<?php
$page = @$_GET['q'] ;
include "inc/header.php";
include "dbq1.php";
?>
<!-- Body Content Begins -->
<table class='main'><tbody><tr><td width='80%' valign='top'>

<!-- Main Content Begins -->
<b class="b1"></b><b class="b2"></b><b class="b3"></b><b class="b4"></b>
<div class="contentb">
<div>
<?php echo $no; ?>
<?php echo $main; ?>
</div></div>
<b class="b4"></b><b class="b3"></b><b class="b2"></b><b class="b1"></b>
</td>
<!-- Main Content Ends -->

<!-- Menu Content Begins -->
<td valign="top">
<div class="contentm">
<div>
<?php echo $menu; ?>
</div></div>
</td>
<!-- Menu Content Ends -->

</tr></tbody></table>
<!-- Body Content Ends -->

<?php include "inc/footer.php"; ?>


Here's the query:

Code: Select all
<?php

$page = @$_GET['q'] ;

$limit=1000;

$link = mysql_connect("localhost", "user", "password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());

$query = "select * FROM Pub WHERE Name like '$page'";
$numresults = mysql_query($query);
$numrows = mysql_num_rows($numresults);

if ($numrows == 0)
  {
  $no = ("The page: &quot;" . $page . "&quot; has been renamed. Select one of the action tabs above.");
  }

if (empty($s)) {
  $s=0;
  }

$query .= " limit $s,$limit";
$result = mysql_query($query) or die("Couldn't execute query");

while ( $row = mysql_fetch_assoc($result) ){

  /*
  Content display and formatting starts here.
  */

$main = $row['Main'];
$menu = $row['Menu'];
}
mysql_close($link);
?>


Here's the .htaccess:

Code: Select all
RewriteEngine on
RewriteRule \.htaccess - [F]
RewriteRule \.(txt|gif|jpe?g|css|ico)$ - [L]
RewriteCond %{HTTP_HOST} ^(www\.thedocumentsguy\.com)?$
RewriteRule ^page/?([^/\.]+)\.html$ get1.php?q=$1 [L]


Here's the "index.php" file that starts the ball rolling:

Code: Select all
<html>
<head>
<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.thedocumentsguy.com/page/opensourceonlinedocumentation.html">
</head>
</html>


You'll likely notice that the "pages" of this document have really long and unusual page names. That came about because of Google Ads. When I first set up this site using page names like "home", "introduction", and other such single word generic names, the Google Ads I was getting were totally not related to the business I'm advertising. Such stuff as "Gay guys blah, blah, blah..." , "Hot singles, blah, blah, blah...", "Swinging this and that...". After some trial and error I discovered that the Google Ads that showed on the pages were being influenced by the "Guy" in my website name "TheDocumentsGuy" because the individual page names were not distinctive. So to get Google to throw more relevant ads, I changed the page names to what they are now. Putting "opensource" in each page name got rid of all the junk ads.

Michael
Mike Wassil
mikewassil
 
Posts: 36
Joined: Wed Dec 19, 2007 3:47 pm

Re: Building Web Page

Postby butchseaman » Sat Jan 30, 2010 7:12 am

Thanks Mike...

I will play with this a see what i get going.

Butch
butchseaman
 
Posts: 21
Joined: Sat Jan 23, 2010 8:51 am

Re: Building Web Page

Postby butchseaman » Sat Jan 30, 2010 9:02 am

Well... Mike

Guess I am missing something. all I seem to get is
The page: "" has been renamed. Select one of the action tabs above.

Just so you know what I have done..

I have a table called 'home' with a field called 'name' - in that that is where I have my body text with html tags.

I have the dbq1 query point to this db and table

I am sure I am off on how this is to work... can you point in the the right direction..?

Thanks
Butch
butchseaman
 
Posts: 21
Joined: Sat Jan 23, 2010 8:51 am

Re: Building Web Page

Postby mikewassil » Sat Jan 30, 2010 12:51 pm

butchseaman wrote:Well... Mike

Guess I am missing something. all I seem to get is
The page: "" has been renamed. Select one of the action tabs above.

Just so you know what I have done..

I have a table called 'home' with a field called 'name' - in that that is where I have my body text with html tags.

I have the dbq1 query point to this db and table

I am sure I am off on how this is to work... can you point in the the right direction..?

Thanks
Butch


Possibly a couple of things. First, I didn't intend for you just to drop in the code and it would work. The code is specifically written to work with my database and directory/file structure. So you have to modify a bit to fit your situation. You must make sure the table and field names in your database match whatever "dbq1.php" is looking for. Specifically:

Code: Select all
$query = "select * FROM Pub WHERE Name like '$page'";


change "Pub" to whatever your actual table name is, and change "Name" to whatever your actual field name for the record name is. The query is case sensitive, so be sure of matching your table and field names exactly, thus in your case:

Code: Select all
$query = "select * FROM home WHERE name like '$page'";


The query is finding your database, otherwise you'd get a php error. "The page: "" has been renamed..." means the query is not finding a record, either because it didn't find the table or didn't find a record in the table with the page name requested. I think it likely found the table, otherwise you'd get a "Couldn't execute query" error. The "$no" variable is just a more sophisticated "404 error". To see how $no works correctly, hit this link:

http://www.thedocumentsguy.com/page/new.html

If your "The page: "" has been renamed..." looks similar, you're getting close, that is, it's displaying header and footer stuff but just no page content! To avoid $no you have to have an actual record in the database table with a field labeled "name" and some content in that field. Then you can enter a URL like:

Code: Select all
http://www.<yourdomain>.com/page/<field"name"content>.html


You also have to have a field labeled "Main" with something in it in order to display any content for the page. But the page should display OK with or without any actual content. Note: you can rename the field "Main" to anything you like, but make sure you change dbq1 to match your field name:

Code: Select all
$main = $row['YourMainContentFieldName'];


Second, you must have the .htaccess file set up correctly, hence:

Code: Select all
RewriteRule ^page/?([^/\.]+)\.html$ get1.php?q=$1 [L]


"get1.php" must be the same as whatever name you gave the above "php script". I used "get1" because it's getting a single record for a single page. You can name it anything you like, but the .htaccess file must point to it in order for everything to work as designed. Here's my directory/file structure, which might help you see how things are laid out:

root (the documentsguy.com)
.htaccess
dbq1.php
get1.php
index.php
..... css (dir)
.......... default.css
..... inc (dir)
.......... header.php
.......... footer.php

Make sure you've got some html header stuff in "header.php". Put </body> and </html> in "footer.php" or at the bottom of "get1.php" (or whatever you name it) if you don't want to have a separate footer file. By the way, header.php should not contain </body> and </html> and footer.php should not contain <html> and <body>. Also, using .php instead of .html enables you to create html files that have tags missing without causing problems. In this case, since both the header and footer files are being included, get1.php combines the html elements from those two files into a single completed properly tagged html page.

Of course, for testing purposes, you can leave out the header and footer includes, and just put the correct html tags in get1.php until you get it working. If you still can't get this working, please include your database name, field names, your version of dbq1.php, get1.php and .htaccess and I might then be able to troubleshoot it for you.

Hope this helps, Michael
Mike Wassil
mikewassil
 
Posts: 36
Joined: Wed Dec 19, 2007 3:47 pm

Previous

Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 8 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved