Help with PHP project I'm working on.
Posted: Mon Dec 07, 2009 8:35 pm
Hi.
I've been having problems getting this script of mine to work, but before I dive into the script, let me explain the theory and idea behind it first. There is a file named config.php which holds variables for everything called inside the main script (index.php) in alphabetical order; i.e. $a is the MySQL connection, and when you get further into the script $h subtracts the total number of records in my database from the number I want to show per page ($h = $d - $b;). At the beginning of index.php of course, config.php is included.
Here is the error I get when I go to localhost/phpquickjournal/index.php:
And here is config.php:
I have tried other methods however those are no longer with me, because I overwrote the files.
Can anyone offer some support? I've been working on this for quite a while now.
I've been having problems getting this script of mine to work, but before I dive into the script, let me explain the theory and idea behind it first. There is a file named config.php which holds variables for everything called inside the main script (index.php) in alphabetical order; i.e. $a is the MySQL connection, and when you get further into the script $h subtracts the total number of records in my database from the number I want to show per page ($h = $d - $b;). At the beginning of index.php of course, config.php is included.
Here is the error I get when I go to localhost/phpquickjournal/index.php:
Here is index.php:Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\xampplite\htdocs\phpquickjournal\config.php on line 12
Warning: Division by zero in C:\xampp\xampplite\htdocs\phpquickjournal\config.php on line 13
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\xampplite\htdocs\phpquickjournal\config.php on line 15
Warning: mysql_connect() expects parameter 1 to be string, resource given in C:\xampp\xampplite\htdocs\phpquickjournal\index.php on line 30
Code: Select all
<?php
/* PHP Quick Journal RC1
* Developed by Payton Bice
* http://paytonbice.com/phpquickjournal/
* PHP Quick Journal ((C) 2009) is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.
* Under this license, you are allowed to:
* >> To Share: To copy, distribute and transmit the work
* >> To Remix: To adapt the work
* Under the following conditions:
* >> Attribution —
* You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
* >> Share Alike -
* If you alter, transform, or build upon this work, you may distribute the resulting work only under the same, similar or a compatible license.
* With the understanding that:
* >> Waiver -
* Any of the above conditions can be waived if you get permission from the copyright holder.
* >> Other Rights -
* In no way are any of the following rights affected by this license:
* # Your fair dealing or fair use rights;
* # Apart from the remix rights granted under this license, the author's moral rights;
* # Rights other persons may have either in the work itself or in how the work is used, such as publicity or privacy rights.
* NOTICE:
* For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this web page.
* Further license information can be found at http://paytonbice.com.
*/
include 'config.php';
mysql_connect($a);
if (!$a) //Display a MySQL error if we couldn't connect.
{
die(mysql_error());
}
else //If we connected to the database successfully, you will move forward.
{
//Move on into the HTML.
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $title; //The title of the page. ?></title>
<link rel="stylesheet" type="text/css" href="styles/default/theme.css" />
</head>
<body>
<div id="container">
<div id="header" class="header">
<img src="styles/default/header.png" alt="Header" />
</div>
<div class="bodycontainer">
<?php
//Now we dive into the fun stuff. Goody goody.
mysql_select_db($l); //Select the database.
if (!$c) //Pages = 0.
$c = 0;
mysql_query($f); //Selecting from the database. More information is in the config.php file.
//And now time to output data from the database onto the page.
echo $g['title'] . " - " . $g['date'] . " - " . "Posted by:" . " " . $g['author'] . " " . "<br /> <br />"; //Title, date, posted by: author. Two line breaks.
echo $g['content'] . " " . "<br /> <br />"; //Shows the post, then adds two line breaks.
echo "Comments."; //A placeholder for the comments section, which is being worked on.
echo "<hr />"; //A horizontal line to repeat the process of blog posts.
if (!($c<=0)) //If the page is less than or equal to 0, let us navigate back some pages.
echo "<a href='index.php?page=$h'>Previous</a> ";
if ($c!=$k) //If 'page' is not equal to $k...
echo " <a href='index.php?page=$k'>$j</a> "; //Echo the first page.
else
echo " <a href='index.php?page=$k'><b>$j</b></a> ";
$j++;
if (!($c>=$d-$b)) //If $c is greater than or equal to $d minus $b...
echo " <a href='index.php?page=$i'>Next</a>"; //Show the next link.
echo "<hr />"; //Horizontal rule.
//Blog information.
echo "<br />";
echo "Blog created by " . " " . $author; //Blog created by $author as defined in the config.php file.
echo " - "; //Space.
echo "Click here to read more about the author."; //Currently this is a placeholder for the about page.
//We're done. Time to close the MySQL connection.
mysql_close($a);
}
?>
</div>
</div>
</body>
</html>Code: Select all
<?php
$title = "Test Journal"; //The site's title.
$author = "Payton Bice"; //The author of the blog.
/*Below are variables that have been set up that we call all throughout the script.
For more information please visit the wiki. */
$a = mysql_connect("localhost","root","password"); //Set up our connection under the variable $a.
$b = 1; //How many journal entries we're going to show per page.
$c = $_GET['page']; //The suffix that takes us to new pages. Example: index.php?page=3
$d = mysql_num_rows($f); //Count how many records are in our database.
$e = $b / $d; //$e is our maximum number of pages, calculated by dividing $b and $d.
$f = mysql_query("SELECT * FROM phpqj_articles ORDER BY date DESC LIMIT $c, $b");
$g = mysql_fetch_array($f); //$g fetches the array $f.
$h = $d - $b; //The total number of records minus how many we display on a page.
$i = $c + $b; //'page' plus however many records we display on a page.
$j = 1; //Set the variable for the first page.
$k = 0;$k<$d;$k=$k+$b; //$k is equal to 0; but if $k is less than or equal to $d, then $k is however many blog posts we want on a page ($b).
$l = mysql_select_db("journal",$a); //Select the database.
?>Can anyone offer some support? I've been working on this for quite a while now.