Advertisement

08.22.2008 at 03:43AM PDT, ID: 23669769
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3

My PHP tutorial listings page with paging results in nothing when on hosting but not local

Asked by TycoonMillion in PHP and Databases

Tags:

Hey

I thought with global variables switched off on my local machine that I am now past getting errors on pages that work fine until I load them to the hosting or server but I'm wrong.

This script involves 3 files. The main one is techtutorials.php.  It will call another 2 files data.php (handles database connection and variables for dataretrieval) using function Database then theres paging.php which obviously sorts out the paging and uses class Paging.

It worked fine and now it doesnt. I had to make changes and I'm getting lost trying to make changes that fix some parts of it but still get me nowhere. I might be doing more bad than good. Right now when I arrived at techtutorials.php it should check what step were at using a value passed by URL then act on it with a specific query, that query gets passed to paging, paging returns its stuff and then I do a while loop to build a row of items.

But no items are shown whatsoever. Heres the page and incase you wonder the three boxes with images are from the database but its a seperate function called in techtutorials.php
<?php include ('process/weeklytutorials.php'); ?>

http://www.webtechglobal.co.uk/index.php?cellname=pagecells/techtutorials.php&step=start&criteria=start

The whole process is either being cut short without causing error or for some reason it actually believes there are no records but I have tested this plenty times and it works local aswel.

Tried testing it at different points of the code with var_dump to and breaking the code and every file and function seems to be in use and so far I found nothing strange with the variable values!

Any advice on how to test this more. I will show the files below thanks for any help on this one because its basically disabled a lot of my site
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
################   techtutorials.php ###################
<link rel="stylesheet" href="../css/globalstyles.css" type="text/css" />
 
<div id="pagecell1">
  	<!--pagecell1-->
	<img alt="" src="images/tl_curve_white.gif" height="6" width="6" id="tl" /> 
	<img alt="" src="images/tr_curve_white.gif" height="6" width="6" id="tr" />
 
	<div id="breadCrumb"> 
		<?php include 'inc/breadcrumb.inc'; ?>
	</div>
	
<div id="pageName">
    	<h2>Technicians Zone</h2>
</div>
 
<!-- Left hand column holding navigation -->		
<?php include 'pagenav.php'; ?>
<div id="content">
    
	<?php include ('process/weeklytutorials.php'); ?>
	
	<div class="story">
	<?php //Display a list of head options (software name, developer etc) depending on selection
	
				//Paging functions
				require('paging/data.php');
				require('paging/paging.php');
				
				//Connect to the database by the data.php 1.database 2.server 3.user 4.password
				//$database = new Database('webtg2008', 'PBPC', 'root', '25130217cmt');
				$database = new Database('w####8', 'localhost', 'w#####8', 'c#####7');
				
				//Set session for using in paging functions (links) these will allow paging.php to keep track of the search criteria
				$_SESSION['pagingurl'] = "index.php?cellname=$_SESSION[cellname]";
				
				//$limit." offset ".$start
				$start = 45;
				
				//Get variable values from URL
				$step = $_GET['step'];
				$criteria = $_GET['criteria'];
 
		if($step == "start"){
			//Step 1 - Display the main catagory selecting newbie only catagories
			$result = mysql_query("SELECT * FROM searchcriteria s JOIN topicsymbols i ON s.tag = i.imgOwner WHERE s.entryType = 'Catagory' AND s.entryZone = 'Tech' OR s.entryType = 'Catagory' AND s.entryZone = 'All' ORDER BY entryID");
			if (!$result) {
				die('Query execution problem: ' . mysql_error());
			}			
			$step = "2";
		}
		else if($step == "2"){
			//Step 2 - Display the options that match the choosing criteria for newbies
			$query = 'SELECT * FROM searchcriteria s JOIN topicsymbols i ON s.tag = i.imgOwner WHERE s.entryType = "'.$criteria.'" AND s.entryZone = "Tech" OR s.entryType = "'.$criteria.'" AND s.entryZone = "All" ORDER BY entryID';
			$result=mysql_query($query)	or die ('Query execution problem on step 2' . mysql_error());  
			$step = "3";
		}
		else if($step == "3"){
			//Step 3 - Display the resulting list of tutorials,guides,downloads etc
			$query = 'SELECT * FROM tutorials t JOIN topicsymbols i ON t.software = i.imgOwner OR t.developer = i.imgOwner WHERE t.software = "'.$criteria.'" OR t.developer = "'.$criteria.'" ORDER BY entryID';
			$result=mysql_query($query)	or die ('Query execution problem on step 3' . mysql_error());  
			$step = "4";
		}
		else if($step == "4"){
			//Should not arrive here the URL set by step 3 should take user to final tutorial selected
		}
		else{
			//Error
			echo "Error: All steps to retreive records failed on techzone.php";
		}
 
			//GLOBAL TABLE ALL RESULTS ARE DISPLAYED IN THIS FORMAT 
			//If no errors then a query should be choosen so pass it to paging and then display results
 
			$paging = new Paging($query, 10, 'result', $database);			
 
			//Decide what step were at in search then Display results
			if($step == "start" || $step == 2 || $step == 3){
				echo "<table width='100%' cellpadding='0' cellspacing='0'>";
				while ($rs = $paging->fetch()){
					echo"<tr>
							<td align='center' bgcolor='#FFFFFF'><font size='4'>$rs->entryID</font></td>
							<td bgcolor='#FFFFFF'>
								<a href='index.php?cellname=pagecells/techtutorials.php&criteria=$rs->imgOwner&step=$step&tutid=$rs->entryID'>
								<img src='images/topicsymbols/$rs->imgName' align='left' border='0'>
								<strong><font face='Arial' size='3'>$rs->entryTitle</font></strong></a>
								<br>$rs->entryComment
								<br>
							</td>
							<td align='center' bgcolor='#FFFFFF'>
								<a href='index.php?cellname=pagecells/techtutorials.php&criteria=$rs->imgOwner&step=$step&tutid=$rs->entryID' style='text-decoration: none;'>
								Visits</a>
								<br>$rs->entryViews
							</td>
						</tr>";
				}
			}
			else if($step == 4){
				echo "<table width='100%' cellpadding='0' cellspacing='0'>";
				while ($rs = $paging->fetch()){
					echo"<tr>
							<td align='center' bgcolor='#FFFFFF'><font size='4'>$rs->entryID</font></td>
							<td bgcolor='#FFFFFF'>
								<a href='index.php?cellname=pagecells/tutorials.php&tutid=$rs->entryID'>
								<img src='images/topicsymbols/$rs->imgName' align='left' border='0'>
								<strong><font face='Arial' size='3'>$rs->entryTitle</font></strong></a>
								<br>$rs->entryComment
								<br>
							</td>
							<td align='center' bgcolor='#FFFFFF'>
								<a href='index.php?cellname=pagecells/tutorials.php&tutid=$rs->entryID' style='text-decoration: none;'>
								Visits</a>
								<br>$rs->entryViews
							</td>
						</tr>";
				}				
			}
			else{
				//Should not get to this step
				echo "Error: No layout selected";
			}
			echo "</table>";
			echo '<br/><br/>';
			echo $paging->get_links();	
	
?>			
	</div>
</div>
 
<div id="siteInfo">
  	<?php include 'cellfoot.php'; ?>
</div>
<!--end pagecell1-->
<br />
 
################  data.php ##################################
 
<?php
 
class Database{
 
	var $queries, $result = null, $server, $user, $password, $database;
 
	function __construct($database, $server, $user, $password) {
		$this->queries = 0;
		$this->server = $server;
		$this->user = $user;
		$this->password = $password;
		$this->database = $database;
		$this->connect();
  }
 
	function connect() {
		mysql_connect($this->server, $this->user, $this->password) 
			or die('Server connection failed.');
		mysql_select_db($this->database) 
			or die('Database connection failed.');
	}
	
	function query($query) {
		$this->queries++;
		$this->result = mysql_query($query);
		return $this->result;
	}
 
	function unique($query) {
		$result = $this->query("$query LIMIT 1");
		$line = mysql_fetch_row($result);
		return $line[0];
	}
 
	function fetch_object($result = null) {
    $result = $result == null ? $this->result : $result;
		if ($result == null || mysql_num_rows($result) < 1) {
			return null;
		} else {
			return mysql_fetch_object($result);
		}
  }
	
	function num($result = null) {
		if ($result == null){
 			return mysql_num_rows($this->result);
		}
		else{
			return mysql_num_rows($result);
		}
	}
	
	function data_seek($result, $seek) {
		return mysql_data_seek($result, $seek);
	}
 
	function close() {
		mysql_close();
	}
}
?>
 
#################  paging.php #########################
<?php
class Paging {
 
	var $result, $pagesize, $page, $rs, $param, $db;
	
	function __construct($query, $pagesize, $param, $db) {
		@$resultpage = $_GET[$param];
		$this->db = $db;
		$this->result = $this->db->query($query);
		$this->pagesize = $pagesize;
		$this->param = $param;
		if ((int)$resultpage <= 0) {
			$resultpage = 1;
		}
		if ($resultpage > $this->get_num_pages()) {
			$resultpage = $this->get_num_pages();
		}
		$this->set_page_num($resultpage);
	}
	
	function get_num_pages() {
		if (!$this->result) {
			return false;
		}
		return ceil($this->db->num($this->result)/(float)$this->pagesize);
	}
	
	function set_page_num($pagenum) {
		if ($pagenum > $this->get_num_pages() or $pagenum <= 0) {
			return false;
		}
		$this->page = $pagenum;
		$this->rs = 0;
		$this->db->data_seek($this->result,($pagenum-1) * $this->pagesize);
	}
	
	function get_page_num()	{
		return $this->page;
	}
	
	function is_last_page() {
		return ($this->page >= $this->get_num_pages());
	}	
	
  function is_first_page() {
		return ($this->page <= 1);
	}
  
	function fetch() {
    if ($this->rs >= $this->pagesize || !$this->result) {
			return false;
		}
    $this->rs++;
		return $this->db->fetch_object($this->result);
  }
  	//PLEASE SET URL VALUES IN SESSIONS ON PAGE PRIOR TO CALLING THIS FUNCTION $_SESSION['pagingurl']
	//This allows the function to be used by numerous applications on the same site especially if the URL is passing values
	function get_links($params = '') {
		$links = '';
		$params = !empty($params) ? "&$params" : '';
		if (!$this->is_first_page()) {
			$links .= "<a href=\"$_SESSION[pagingurl]$this->param=".($this->get_page_num()-1).''.$params.'">Back</a> ';
	}
		if ($this->get_num_pages() > 1) {
			for ($i = 1; $i <= $this->get_num_pages(); $i++) {
		 		if ($i==$this->page) {
					$links .= "$i ";
        } else {
        	$links .= "<a href=\"$_SESSION[pagingurl]$this->param={$i}".$params."\">{$i}</a> ";
				}
      }
    	if (!$this->is_last_page()) {
      	$links .= "<a href=\"$_SESSION[pagingurl]$this->param=".($this->get_page_num()+1).''.$params.'">Next</a> ';
			}
		}
		return $links;
	}
}
?>
 
Loading Advertisement...
 
[+][-]08.22.2008 at 08:37AM PDT, ID: 22291130

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: PHP and Databases
Tags: PHP
Sign Up Now!
Solution Provided By: jausions
Participating Experts: 1
Solution Grade: A
 
 
[+][-]08.22.2008 at 10:15AM PDT, ID: 22292068

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.22.2008 at 10:44AM PDT, ID: 22292326

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.22.2008 at 11:34AM PDT, ID: 22292836

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.23.2008 at 08:53AM PDT, ID: 22297496

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-43 / EE_QW_2_20070628