Jump to content

AdRock

Members
  • Posts

    913
  • Joined

  • Last visited

Everything posted by AdRock

  1. Can anyone please help me insert this line of html and javascript into my php code? I have a radio button which when clicked will open delete_news.php I want to put that in the php code so every record will have the radio button next to it so it can be deleted. [code]<input style="border:none;" type="radio" name="loc" onClick="go('index.php?page=delete_news');">[/code] [code]while($code = mysql_fetch_object($q)) {     echo("[b]<h3>[/b]".$code->title."</h3><BR>");}[/code] I would like the HTML to replace the <h3> but becuase the HTML has " in it i'm not sure how to insert it
  2. Right......here is my index.php switch statement [code]<?php switch ($_GET['page'])     {             case "contact": include('contact.php'); break; case "news": include('newsitem.php'); break;       default: include('home.php');     } ?>[/code] and here is the pagination script i'm using in news.php [code]<? //REMEMBER TO CONNECT TO DATABASE! include_once("includes/connection.php");     @mysql_connect($host, $user, $password) or die("ERROR--CAN'T CONNECT TO SERVER");     @mysql_select_db($database) or die("ERROR--CAN'T CONNECT TO DB"); //**EDIT TO YOUR TABLE NAME, ECT. $t = mysql_query("SELECT * FROM `news`");   if(!$t) die(mysql_error());     $a                = mysql_fetch_object($t); $total_items      = mysql_num_rows($t); $limit            = $_GET['limit']; $type            = $_GET['type']; $page            = $_GET['page']; //set default if: $limit is empty, non numerical, less than 10, greater than 50 if((!$limit)  || (is_numeric($limit) == false) || ($limit < 10) || ($limit > 50)) {     $limit = 2; //default } //set default if: $page is empty, non numerical, less than zero, greater than total available if((!$page) || (is_numeric($page) == false) || ($page < 0) || ($page > $total_items)) {       $page = 1; //default } //calcuate total pages $total_pages    = ceil($total_items / $limit); $set_limit          = $page * $limit - ($limit); //query: **EDIT TO YOUR TABLE NAME, ECT. $q = mysql_query("SELECT * FROM `news` LIMIT $set_limit, $limit");   if(!$q) die(mysql_error());     $err = mysql_num_rows($q);       if($err == 0) die("No matches met your criteria."); //Results per page: **EDIT LINK PATH** echo("  <a href=?page=newsitem?limit=10&amp;page=1></a> <a href=?page=newsitem?limit=25&amp;page=1></a> <a href=?page=newsitem?limit=50&amp;page=1></a>"); //show data matching query: while($code = mysql_fetch_object($q)) {     echo("item: ".$code->title."<BR>"); } $id = urlencode($id); //makes browser friendly //prev. page: **EDIT LINK PATH** $prev_page = $page - 1; if($prev_page >= 1) {   echo("<b>&lt;&lt;</b> <a href=?page=newsitem?limit=$limit&amp;page=$prev_page><b>Prev.</b></a>"); } //Display middle pages: **EDIT LINK PATH** for($a = 1; $a <= $total_pages; $a++) {   if($a == $page) {       echo("<b> $a</b> | "); //no link     } else {   echo("  <a href=?page=newsitem?limit=$limit&amp;page=$a> $a </a> | ");     } } //next page: **EDIT THIS LINK PATH** $next_page = $page + 1; if($next_page <= $total_pages) {   echo("<a href=?page=newsitem?limit=$limit&amp;page=$next_page><b>Next</b></a> &gt; &gt;"); } //all done ?>[/code] if you can make sense of why it's not displaying page=2 etc please let me know
  3. I have looked at www.php.net/switch and have noticed a post on nested switch. Could that be a solution to the problem and if so how do I implement it. As for the 2 pages, page=2 is in the pagination script
  4. Hello there......I have a huge problem and have no idea how to sort it I use a switch statement to display each of my pages (only some of them are shown to save space) [code]<?php switch ($_GET['page']) { case "contact": include('contact.php'); break; default: include('home.php'); } ?>[/code] and i have a pagination script to display a set number of record per page.  The first page displays ok but when i click on the next page link it defaults back to the default page (obviuosly because the switch statement isn't set up to handle it) The link that appears in the browser window is [b]http://www.mysite.co.uk/index.php?page=newsitem?limit=2&page=2[/b] but no page is displayed How do I sort this problem out?  ???
  5. I am having trouble redirecting to another page after form information has been entered into a database Here is the code that I use to insert into the database [code]<?php include_once("../includes/connection.php"); $title=$_POST['title']; $content=$_POST['content']; mysql_connect($host,$user,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "INSERT INTO news VALUES ('','$title','$content','')"; mysql_query($query); mysql_close(); header ('location:http://www.mysite.com/index.php?page=confirm'); ?>[/code]There is no html or head just what you see in the code. I am trying to open a confirmation page telling the user that the data has been stored after they click the submit button
  6. [quote author=hitman6003 link=topic=101320.msg400923#msg400923 date=1153444173] 30 seconds on phpfreaks.com yeilded: http://www.phpfreaks.com/tutorials/43/0.php [/quote] I used the tutorial and it does exactly what I want but i noticed if you click the PREV link while on page 1 the usual "Page cannot be displayed" error message appears.  Is there a way you can have the page return to page 1  like it does when you try to move past the last page. Many thanks in advance
  7. Can anyone please tell me how I can display a set number of records per page? What I want to do is have 5 records displayed on the page at a time and a link to show the next 5 records much like you see on the forum here. I intend to have lots of news items and if there are about 50 i want a link at the bottom i.e. [color=blue]previous 1 2 3 4 next[/color] I have seen it done on a guestbook script but i don't know enough about php to pick out what i need. If someone could point me in the right direction I would be grateful
  8. I've installed php etc on my local machine and set up my database I changed the form action from [code]<form action="index.php?page=insert" method="post">[/code] to [code]<form action="insert.php" method="post">[/code] and now it works  i can insert records and I can display them. Is there no way I can use the switch statement so i can use the original form action? Here is the switch statement on the index.php page [code]<?php switch ($_GET['page'])     {             case "contact": include('contact.php'); break; case "news": include('news.php'); break; case "news1": include('news1.php'); break;       default: include('home.php');     } ?>[/code]If there is no way around it i'll have to stick with it
  9. I am having problems displaying data from a database onto a page.  i haven't used php for months so am getting back into it slowly. I am sure I have been able to add a record becuase everything seems fine but the page is displaying nothing when i try to view the content.  Is there a way i can see what records exist in the database? Here is how i insert a new record [code]<form action="index.php?page=insertnews" method="post"> <p class="style1">Please enter a title for the news item. <input style="width:400px;" type="text" size="50" name="title"></p> <p class="style1">Please enter the content for the news item. <textarea style="width:400px;" name="content" cols="30" rows="10"> </textarea></p> <input class="submit-button" style="margin-left:0"  type="Submit" value="Submit"><input class="submit-button" style="margin-left:2px" type="reset" value="Reset"> </form>[/code] this is insertnews.php [code]<?php include_once("../includes/connection.inc"); $title= $_POST['title']; $content= $_POST['content']; mysql_connect($host,$user,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "INSERT INTO news VALUES ('','$title','$content')"; mysql_query($query); mysql_close(); ?>[/code] And this is the page that the content is to be displayed on.  I use a switch ($_GET['page']) to open pages [code]<h3><?php include_once("includes/connection.inc");                 mysql_connect($host,$user,$password);     @mysql_select_db($database) or die( "Unable to select database");   $result = @mysql_query("SELECT title FROM news");   if (!$result) {               echo("<p>Error performing query: " . mysql_error() . "</p>");     exit();            } while ( $row = mysql_fetch_array($result) ) {   echo("<p>" . nl2br($row["title"]) . "</p>"); } ?></h3> <p class="style3"><?php include_once("includes/connection.inc"); $result = @mysql_query("SELECT content FROM news"); if (!$result) {             echo("<p>Error performing query: " . mysql_error() . "</p>");     exit();            } while ( $row = mysql_fetch_array($result) ) {     echo("<p>" . nl2br($row["content"]) . "</p>"); } mysql_close(); ?></p>[/code]
  10. Hello I am thinking of creating a guestbook for a website which isn't a problem but I want to know how to set the number of messages per page. Say I wanted to display 10 messages per page and had 50 messages to be displayed, how would I include a link somewhere to move to the next set of messages and to display the number of pages? Any help would be appreciated
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.