using CMS to open page - php

this is the index.php
<table align="center" border="0" cellpadding="0" cellspacing="0">
<tbody>
<?php include 'header.php'; ?>
<tr>
<td class="row_2">
<!-- header_eof //-->
<!-- body //-->
<table class="main_table" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<?php
if($cond)
include 'left.php'; ?>
<!-- body_text //-->
<?php get_page(); ?>
<!-- body_text_eof //-->
<?php
if($cond)
include 'right.php'; ?>
</tr>
<tr>
<?php
if(!$cond)
include 'contents/contact_us.php';?>
</tr>
</tbody>
</table>
<!-- body_eof //-->
<!-- footer //-->
</td>
</tr>
<?php include 'footer.php'; ?>
</tbody>
</table>
This is header.php . I have created link from database
<?php
$menus = db_query("select * from menus where type=0 order by weight");
$sr = 0;
while($menu = mysql_fetch_object($menus)) { ?>
<?php if(($sr++) > 0){ ?>
<td class="menu_separator"><img src="<?php echo SROOT;?>images/menu_separator.png" alt="" class="png" width="2" border="0" height="49"></td>
<?php } ?>
<td id="<?php echo get_id($menu->page_name); ?>" <?php echo get_event($menu->page_name); ?> onClick="document.location='<?php echo SROOT . $menu->page_name;?>'" nowrap="nowrap"><?php echo $menu->title; ?></td>
<?php } ?>
this is the get_page function
function get_page() {
$page = arg(0);
$page = (empty($page)) ? 'home' : $page;
$cat = db_query("select * from mb_category where title='".$page."'");
$page = (mysql_num_rows($cat)) ? 'brands' : $page;
include 'contents/'. $page .'.php';
}
I have everything in the right place.The same code is working for my friend but we are unable to understand the problem here. I get error cannot find page. His is working fine.
When i click link it says cannot find page..but his goes to page
Can anyone please help and tell me what i am doing wrong

Edited:
The part I don't understand is this:
$page = arg(0);
$page = (empty($page)) ? 'home' : $page;
$cat = db_query("select * from mb_category where title='".$page."'");
What is "arg(0)?, so how do you get $page?
Ok, I understand this is a drupal function or alike.
But, pls, verify that arg(0) returns sth.
If you are not sure of the path the include is taken, I would change this line:
include 'contents/'. $page .'.php';
for:
include $_SERVER["DOCUMENT_ROOT"]."/contents/'. $page .'.php';

Related

Create a simple pagination

Here's a screenshot of the page that I want to put a pagination Below is my code and I want to create a simple pagination. I tried some examples available in this site but unfortunately it doesn't work for me or I might have missed something in the code.
<?php
session_start();
$server = 'localhost';
$user = 'root';
$pass = 'root';
$connect = mysql_connect($server,$user,$pass)
or die(mysql_error());
$selectdb = mysql_select_db('des')
or die(mysql_error());
?>
<form method="post" name="action_form" action="admin2.php">
<div id="gallery1" class="lbGallery">
<table class="table" width="100%" cellpadding="10">
<tbody>
<?php
$allRecords = mysql_query('select * from cms ORDER BY id DESC limit 4');
if(is_resource($allRecords))
{
while($row = mysql_fetch_assoc($allRecords))
{
?>
<tr><ul>
<td width="30%"><li style="list-style:none"><a href="uploads/<?php echo $row['image'];?>"/><img src="uploads/<?php echo $row['image'];?>"/></li></td>
<td style="float:left; font-size:16px"><?php echo $row['name']; ?></td>
</ul>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div>
</form>
Try this. What is does is:
create a contant $amount en a variable $offset
Create a link (next) with which sends the value of $offset back to the script
Catch the value in $_GET['offset'];
Add the value of $amount to $offset to create a new offset.
Run MySQL statement again with the new values for LIMIT
I didn't actualy test this code for typo's, but you'll get the general idea. Hope this is of any help.
(Best to use the new mysqli statement by te way).
<?php
$amount = 4;
if (!empty($_GET['offset']))
{
$offset = $_GET['offset'] + $amount;
}
else
{
$offset = 1;
}
$allRecords = mysql_query('select * from cms ORDER BY id DESC limit $amount,$offset');
if(is_resource($allRecords))
{
while($row = mysql_fetch_assoc($allRecords))
{
?>
<tr><ul>
<td width="30%"><li style="list-style:none"><a href="uploads/<?php echo $row['image'];?>"/><img src="uploads/<?php echo $row['image'];?>"/></li></td>
<td style="float:left; font-size:16px"><?php echo $row['name']; ?></td>
</ul>
</tr>
<tr>
<td colspan="2">
Next
</td>
</tr>
<?php
}
}
?>

How to make numbering navigation after break; in PHP?

Hi all I have searching for method but not luck. Help me I want to make numbering navigation. Here is my code:
<ul>
<?php
$kw = file_get_contents('keywords.txt');
$kw = explode("\n", $kw);
asort($kw);
$i = 0;
foreach($kw as $k) {
if($i==30) { break; }
?>
<li>
<?php echo ucwords($k);?>
</li>
<?php $i++; } ?>
</ul>
The above code just displayed 30 result from 1500 keyword I have. I want to make Page Numbering navigation also shorting A-Z. So user can Short Keyword by Alphabetic above it and page numbering after it.
Use Datatables.
Table
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>KeyWord</th>
</tr>
</thead>
<tbody>
<?php foreach($kw as $k) { ?>
<tr>
<td><?php echo ucwords($k);?></td>
</tr>
<?php } ?>
</tbody>
</table>
Javascript
$(document).ready(function() {
$('#example').DataTable();
} );
Do include the proper plugin files for js & css. from - Datatables

the request url not found in php

my home.php is
required("conn.php");
<html>
<body>
<form action="like.php" name="art" method="post">
<?php
//$email=$data['email'];
?>
<table align="center" border="2">
<tr><th colspan="4"><h2 align="center">Articals</h2></th></tr>
<tr> <th>Name</th><th>Artical</th><th>Status</th><th colspan="2">option</th>
</tr>
<?php
$r = mysql_query("select * from ar ");
while($ro=mysql_fetch_array($r)){
?>
<tr>
<td> <?php echo $ro["fname"]?></td>
<td><textarea rows="2" cols="25"><?php echo $ro["post"]?></textarea></td>
<td><?php echo $ro["status"]?></td>
<td><a name="like" href="like.php?id=<?php echo $ro['id']?>"> like</a></td>
<!--<td><a href="delart.php?id=<?php //echo $row["id"]?>" >Delete</a></td>
<td>Upadate</td>
-->
</tr>
<?php
}
mysql_close($con);
?>
</form>
</table>
</body>
</html>
and like.php is
<?php
session_start();
if(!isset($_SESSION['user']))
{
header('Location:index.php');
}
require("conn.php");
$id=$_GET['id'];
mysql_query("insert into `like` ar where id='$id'");
?>
when i am click on link like so the error "The requested URL /25-8/like.php was not found on this server." is come pls help i am new to php
i want there to count the no of like and on click on that like button it automatically change to unlike
YOu Must put the home.php and like.php in the same directory?

Include same file multiple times in PHP

Basically I have a list of particular members that I am calling with their member ID, and displaying the td's afterwards on each one..
So I have the table like this
<table id="sortable" class="tablesorter" width="100%">
<thead>
<tr>
<th class="header"><strong>Game Username</strong></th>
<th class="header"><strong>Rank</strong></th>
<th class="header"><strong>Game Played</strong></th>
<th class="header"><strong>Playing On</strong></th>
<th class="header"><strong>Age</strong></th>
<th class="header"><strong>Time On</strong></th>
<th class="header"><strong>Location</strong></th>
</tr>
</thead>
<tbody>
<?php include ("users.php"); ?>
</tbody>
And the users.php file looks like this, but right now at over 50 lines of the same code as below, with only the $id= number changed..
<tr><td class="username"><a href="<?php $id='1'; include ("fields.php"); ?>
<tr><td class="username"><a href="<?php $id='2'; include ("fields.php"); ?>
<tr><td class="username"><a href="<?php $id='3'; include ("fields.php"); ?>
<tr><td class="username"><a href="<?php $id='4'; include ("fields.php"); ?>
<tr><td class="username"><a href="<?php $id='5'; include ("fields.php"); ?>
The fields.php file is the remainder of the table rows etc., starting with the below code to close off this td.
<?php echo $domain; $member_id = $id; $user_info = get_userdata($id);echo $user_info-> user_login.""; ?>"><?php echo xprofile_get_field_data( "$field_gamename" , $member_id); ?></a>
</td>
I'm trying to avoid including the fields.php file over 50 times in the users.php file. Anyone got an idea of the most efficient way?
Thanks!
This should work:
<?php for ($i=0; $i<50; $i++): ?>
<tr><td class="username"><a href="<?php $id=$i; include ("fields.php"); ?>
<?php endfor; ?>
On the other hand, you should probably re-factor your code so that you do not need to include the file on each loop, probably by either putting the code inline or (much better) by creating a function that does whatever you need to be done, something like this:
<?php for ($i=0; $i<50; $i++): ?>
<tr><td class="username"><a href="<?php do_some_stuff($i); ?>
<?php endfor; ?>
EDIT:
Since you want this to work for a defined list of IDs, you should create an array with that list and loop through it using the foreach() statement, like this:
<?php
$IdArray = array(1, 2, 25, 38);
foreach ($IdArray as $id): ?>
<tr><td class="username"><a href="<?php include ("fields.php"); ?>
<?php endforeach; ?>
Notice that I have removed the "$id = $i", since I am feeding the $id variable directly inside the foreach statement! ;)
BTW, you should close the tr, td and a tags before the "endforeach", ok?
Good luck!
Yes, a loop.
for ($i = 1; $i <= 50; $i++) {
//Do stuff with $i.
}
<?php
for($i = 0; $i <= 50; $i++) {
?>
<tr>
<td class="username">
<?php $href = $domain . $user_info->get_userdata($i) . $user_info->user_login;?>
<?php echo xprofile_get_field_data( "$field_gamename" , $i); ?>
</td>
</tr>
<?php
}
?>

Parse error: syntax error, unexpected T_IS_GREATER_OR_EQUAL in

over the past few weeks ive been learning php, its been quite a daunting task but stack overflow has helped me alot. I am currently having issues with a parse error,
<?php
include('config.php');
function html($html)
{
return htmlentities($html, ENT_QUOTES, 'utf-8');
}
?>
<html xmlns="http://www.w3.org/1999/xhtml"/>
<head>
<meta http-equiv="content-type" content="text/html"/>
<link href="<?php echo $design ?>/style.css" rel="stylesheet" title="Style">
<title><?php echo $title ?></title>
</head>
<body>
<html>
<div class="header">
<a href="<?php echo $root ?>" img src="<?php echo $design ?>/images/<?php echo $logo ?>" alt="home"/>
</div>
<table class="home" cellpadding="0" cellspacing="0">
<tr>
<th class="rank_th">Ranking</th>
<th class="site_th">Site</th>
<th class="votes_th">Votes</th>
</tr>
<?php
//we get #sites
$req1 = mysqli_fetch_array(mysqli_query('SELECT COUNT(id) as # FROM Sites WHERE status="ok"'));
//we get current top
IF (isset($_GET['Page'])) {
$page = intval($_GET['page']);
} else {
$page = 1;
}
//calculate #pages & display page links
$nbpage = ceil($req1['nb'] / $nbpage);
if ($page < 1 or $page > $nbpage);
{ >= 'Pages: ';
if ($page > 1) {
$pages_site .= ''last ';
}
for ($i=1;$i<=$nbpage;$i++)
{
if ($i==$page){
$pages_site .=<strong> .$i. </strong>';
}
}
if ($page < $page<$nbpage){
$pages_site .= 'next')''
}
?>
<tr>
<td colspan="3" class="pages"><?php ECHO $pages_site; ?></td>
</tr>
<div class="new">Please register or to add your website. </div>
<?php
//calculate order
$first_site = ($page-1)*$nbpage;
$last_site = $first_site +$nbpage;
$i=$first_site ;
//display sites
$req2 = mysqli_query('select id, url, name, description, banner, votes FROM sites where status="ok" order .by votes desc limit ' .$first_site . ',' .$last_site .);
while($dnn2 = mysqli_fetch_array($req2))
{
$i++;
}
?>
<tr>
<td class="ranking"><?php echo $i; ?> </td>
<td class="site"><?php echo html($dnn2['name']); ?><br />
<?php echo html($dnn2['description']); ?><br />
<?php echo html($dnn2['url']); ?>
<div style="text-align:center;"<img src="<?php echo html($dnn2['banner'],?>" alt="<?php echo html($dnn2['name']); ?>" style="max-width:500px;max-height:200px;" /></div></td>
<td class="votes"><?php echo html($dnn2['votes']); ?> <br />vote</td>
</tr>
<?php
}
//display page # again
?>
<tr>
<td colspan="3" class="pages"> <?php echo $pages_site; ?></td>
</tr>
</table>
<div class="footer">
<?php echo $footer ?>
</div>
</body>
</html>
/**
* Created by PhpStorm.
* User: weller
* Date: 19/12/13
* Time: 11:41 AM
*/
is the index.php page.
<?php
//change to your details.
$host = 'localhost';
$user = 'username';
$pass = 'password';
$dbname = 'database';
//connects here(dont change)
$db = mysqli_connect($host, $user, $pass, $dbname);
//webmaster email
$mail1 = 'webmaster#site.com';
//site root url
$root = 'www.site.com/';
//homepage filename
$index = 'index.php';
//pages per index
$nbpages = '10';
//css name
$design = 'default';
//site title
$title = 'LOLOLOL';
//Footer msg
$footer = 'LOLOL';
?>
/**
* Created with PhpStorm.
* User: weller
* Date: 19/12/13
* Time: 11:31 AM
*/
is the config.php
and my parse error is:
Parse error: syntax error, unexpected T_IS_GREATER_OR_EQUAL in /home3/crazycr1/public_html/index.php on line 37
every parse error ive had sofar ive been able to solve with google but this one has had me stumped for an hour now.
i have tried moving the >= around and i did try a few other ways of doing it but i keep getting the same issue.
any help at all is welcome && feel free to check for easier or more secure ways of doing things. THANKS :D
weller.
here is the correct from. Thanks
/**
* Created by PhpStorm.
* User: weller
* Date: 19/12/13
* Time: 11:41 AM
*/
include('config.php');
function html($html)
{
return htmlentities($html, ENT_QUOTES, 'utf-8');
}
?>
<html xmlns="http://www.w3.org/1999/xhtml"/>
<head>
<meta http-equiv="content-type" content="text/html"/>
<link href="<?php echo $design ?>/style.css" rel="stylesheet" title="Style">
<title><?php echo $title ?></title>
</head>
<body>
<html>
<div class="header">
<a href="<?php echo $root ?>" img src="<?php echo $design ?>/images/<?php echo $logo ?>" alt="home"/>
</div>
<table class="home" cellpadding="0" cellspacing="0">
<tr>
<th class="rank_th">Ranking</th>
<th class="site_th">Site</th>
<th class="votes_th">Votes</th>
</tr>
<?php
//we get #sites
$query = "SELECT COUNT(id) as # FROM Sites WHERE status=`ok`";
$req1 = mysqli_fetch_array(mysqli_query($query, $db));
//we get current top
IF (isset($_GET['Page'])) {
$page = intval($_GET['page']);
} else {
$page = 1;
}
//calculate #pages & display page links
$nbpage = ceil($req1['nb'] / $nbpage);
if ($page < 1 or $page > $nbpage);
{
$pages_site = 'Pages: ';
if ($page > 1) {
$pages_site .= 'last';
}
for ($i=1;$i<=$nbpage;$i++)
{
if ($i==$page){
$pages_site .='<strong> .$i. </strong>';
}
}
if ($page < $nbpage){
$pages_site .= 'next';
}
?>
<tr>
<td colspan="3" class="pages"><?php ECHO $pages_site; ?></td>
</tr>
<div class="new">Please register or to add your website. </div>
<?php
//calculate order
$first_site = ($page-1)*$nbpage;
$last_site = $first_site +$nbpage;
$i=$first_site ;
//display sites
$query1 = 'select id, url, name, description, banner, votes FROM sites where status="ok" order .by votes desc limit ' .$first_site . ',' .$last_site;
$req2 = mysqli_query($query1, $db);
while($dnn2 = mysqli_fetch_array($req2))
{
$i++;
}
?>
<tr>
<td class="ranking"><?php echo $i; ?> </td>
<td class="site"><?php echo html($dnn2['name']); ?><br />
<?php echo html($dnn2['description']); ?><br />
<?php echo html($dnn2['url']); ?>
<div style="text-align:center;"<img src="<?php echo html($dnn2['banner']);?>" alt="<?php echo html($dnn2['name']); ?>" style="max-width:500px;max-height:200px;" /></div></td>
<td class="votes"><?php echo html($dnn2['votes']); ?> <br />vote</td>
</tr>
<?php
}
//display page # again
?>
<tr>
<td colspan="3" class="pages"> <?php echo $pages_site; ?></td>
</tr>
</table>
<div class="footer">
<?php echo $footer ?>
</div>
</body>
</html>
corrections:
/**
* Created by PhpStorm.
* User: weller
* Date: 19/12/13
* Time: 11:41 AM
*/
this needed to in a php tag.
">
bracket expected.
'select id, url, name, description, banner, votes FROM sites where status="ok" order .by votes desc limit ' .$first_site . ',' .$last_site .
extra dot put and also db connect link wasn't in the param.
if ($page < $page
quotes are not put correctly.
$title = 'LOLOLOL';
//Footer msg
$footer = 'LOLOL';
You missed semicolons at the end of both statements.
Errm...
if ($page < 1 or $page > $nbpage);
{ >= 'Pages: ';
if ($page > 1) {
Pretty sure that's not supposed to be there...
if ($page < 1 or $page > $nbpage);
{ >= 'Pages: ';
In the above code you have the error.
you have end the if condition there so remove the ;.
there is >= 'Pages: ' without any condition so remove that or make it right.
So do this:
if ($page < 1 or $page > $nbpage)
{
......
And in the below line you have error:
$pages_site .= ''last ';
^^^ extra comma
this must be as following:
$pages_site .= 'last ';

Categories