Jump to content

rahish

Members
  • Posts

    31
  • Joined

  • Last visited

    Never

Posts posted by rahish

  1. Thanks I tried both but I am still getting a can't execute query error.

     

    This is what I am now using

    <?php
    
    
    include('../dbconnection.php');
    
    
    
    $submit=$_GET['submit'];
    $id=$_GET['id'];
    $menu=$_GET['menu'];
    
    if ( $menu=='1' )
    {
    
    
    $query=mysql_query("DELETE FROM menu WHERE id = '$id'")  or die ("Couldn't execute query.");
    $query2=mysql_query("DELETE FROM pages WHERE pages_id = '$id'")  or die ("Couldn't execute query.");
    
    
    
    echo "You have now deleted entry $id from the database and entry $id from the menu<br />";
    
    echo " <a href='posts.php?id=$id'>Click here to go back</a>";    
    
    
    }
    else
    {
           
      $query=mysql_query("DELETE FROM pages WHERE page_id=$id")  or die ("Couldn't execute query.");  
      
      echo "You have now deleted entry $id from the database<br />";
      echo " <a href='posts.php?id=$id'>Click here to go back</a>";  
    }
      
    ?>

  2. I am creating a very simple cms system and have a delete statement which is supposed to delete an item from a menu table and a page table which (has an identical id) when an admin user deletes the page

     

    There is an if statement that sends and integer "1" if the admin user has clicked the html checkbox on a form to ask for the page to be deleted from the menu as well as the page itself.

     

    I can't work out the syntax of the mysql statement to do this

     

    I am not sure if this is the right forum for this question.

     

    But here is the code I am using

    <?php
    
    
    include('../dbconnection.php');
    
    
    
    $submit=$_GET['submit'];
    $id=$_GET['id'];
    $menu=$_GET['menu'];
    
    if ( $menu=='1' )
    {
    
    
    $query=mysql_query("DELETE FROM menu, pages WHERE menu.id AND pages.page_id=$id")  or die ("Couldn't execute query.");
    
    //$query = mysql_query("DELETE FROM menu WHERE id=$id") or die (mysql_error());
    
    echo "You have now deleted entry $id from the database and entry $id from the menu<br />";
    
    echo " <a href='posts.php?id=$id'>Click here to go back</a>";    
    
    
    }
    else
    {
           
      $query=mysql_query("DELETE FROM pages WHERE page_id=$id")  or die ("Couldn't execute query.");  
      
      echo "You have now deleted entry $id from the database<br />";
      echo " <a href='posts.php?id=$id'>Click here to go back</a>";  
    }
      
    ?>

     

  3. This should be easy for someone. I am trying to populate a simple html list menu with urls and link text using an array and a for loop.

     

    I cannot work out what I am doing wrong but I know I am only guessing, I have got my for loops mixed up and it is duplicating the output.

     

     

    Here is the example

    
    
    <?php
    $menu_link = array (0 =>'index.php', 'info.php', 'contact.php');
    $menu_text = array (0 =>'Home', 'Information', 'Contact');
    
    
    ?>
    
    
    <h3> Menu Example</h3>
    
    <?php  
    
    
    print_r($menu_link);
    print_r($menu_text);
    ?>
    <?php
    
    
    
    echo "<ul>";
    for ($text=0; $text < sizeof($menu_text); $text++) {
    
    
    for ($i=0; $i < sizeof($menu_link); $i++) {
    echo  "<li><a href='", $menu_link[$i], "'>$menu_text[$text] "; //$i,
    
    
    //echo  " ",$menu_text[$text], "</li>";
    
    	}	
    
    }
    
    
    echo "</a></li>";
    
    echo "</ul>";
    
    ?>

  4. Thanks

     

    Now I am getting

     

    Warning: Cannot modify header information - headers already sent by (output started at ******template.php:2) in ******template.php on line 3

     

    There is a header redirect in an index.php file, I am wondering if this code should be in template.php

     

    <?php
    
    
    
    if ($styleCookie == "") {
    $style="default";
    }
    else {
    $style=$styleCookie;
    }
    
    Header ("Location: template.php?page=home&style=$style");
    
    ?>
    

     

  5. Thanks,

    I am not getting an error at all, its just that when you try clicking on info in the list menu, it should send the variables to be picked up by template.php to load a different html file and change the style sheet. As I say this seems to work fine on localhost under xampp but on my web server on the link below it doesn't work. The variable in on the info link should send

     

    ?page=info&style=blue

     

    to template.php

     

    I echoed variables $style and $page to template.php and it still shows default and home.

     

    The page has a cookie applied also, could it be that it is not updating the information

     

     

     

    If you click on the link

     

    http://www.undesign.co.uk/computer_club/dynamic_web/PHP/alistapart_tutorials/managing_content_php/template.php?page=home&style=default

     

     

    You will see what I mean

     

     

     

     

  6. Hi I am trying to build a php template from the following tutorial  http://www.alistapart.com/articles/phpcms

     

    All I want to do is send a variable to another page, something I have done countless times before. It works fine on my local server but I cannot get it to work on my web account. It may have something to do with the way & needs to be encoded but I have corrected that and the page validates as XHTML strict but the file still won't work.

     

    Can anyone work out what I am doing wrong?

     

    template.php has menu.php as a require and the content loads dynamically when you select a menu item from menu.php the variables are in the url on the menu link.

     

    here is template.php

    <?php
    setcookie ("styleCookie", $style, time()+40000000);
    ?>
    
    <?php
    
    if ($style == "") {
    $style="default";
    }
    if ($page == "") {
    $page="home";
    }
    
    ?>
    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
        <meta http-equiv="Content-Language" content="en-us" />
    
        <title>New CMS Template - Alistapart Tutorial - Managing your content with PHP</title>
        
    <?php echo "<style type=\"text/css\" 
    media=\"all\">@import 
    \"$style.css\";> </style>"; ?>    
        
    
    <?php echo 
    "<link rel=\"alternate style sheet\" 
    type=\"text/css\" 
    href=\"default.css\" title=\"Default\" />"; ?>
    </head>
    
    <body>
    
    <?php $_GET['$style'];
    
    	$_GET['$page'];?>
    
    <?php echo "$style";?>
    <?php echo "$page";?>
    <div class="body">
    <?php //@require_once ("header.php");?>
    
    <div class="menu">
    <?php @ require_once ("menu.php"); ?>
    </div>
    
    <?php @ require_once ("$page.html"); ?>
    
    </div>
    
    
    
    </body>
    </html>

     

    and here is menu.php

     

    <?php
    $home="Home";
    $info="Information";
    $contact="Contact Details";
    $links="Links";
    
    $default="default";
    $blue ="blue";
    
    ?>
    <ul>
    <li><?php echo "<a href=\"template.php?page=home&style=$default\">$home</a>"; 
    ?></li>
    <li><?php echo "<a href=\"template.php?page=info&style=$blue\">$info</a>"; 
    ?></li>
    <li><?php echo "$contact";?></li>
    <li><?php echo "$links";?></li>
    </ul>
    

     

    the css files just have a background colour defined and the home and info pages are home.html and info.html

     

    The link to the template.php which has the error is herehttp://www.undesign.co.uk/computer_club/dynamic_web/PHP/alistapart_tutorials/managing_content_php/template.php?page=home&style=default

  7. Thanks a lot,

     

    Got it working now

     

    I realised that the remainder would always work out and output a number as a remainder that corresponded to the id of each image, it was the fact that i had an array set up to cycle the images and I was trying to get the $id into $pictures some how. So I scrapped the array altogether and removed the for loop and used a standard fetch array and put the output of $number in the sql statement.

     

    <?php
    $wk_no = date("W"); //gives the current week
    $count_sql = 'SELECT * FROM main_week_pic';// query database
    $count_result = mysql_query($count_sql);
    // Get number of articles, assign value to variable
    $count = mysql_num_rows($count_result);
    echo "The database has this many rows: $count <br />";
    echo "We are currently in week $wk_no<br />";
    $number= $week_no%$count+3;
    echo "$number";
    
    
    $query = ("SELECT * FROM main_week_pic where id = '$number'");// query database
    
    echo"<p class='imgcenter'><h3>Undesign of the Week</h3>";
    
    $result = mysql_query($query) or die ("Couldn't execute query.");
    
    // Populate cells using a mysql_fetch_array script 
    while ($row=mysql_fetch_array($result))
    {
    
    $id=$row["id"];
    $path=$row["path"];
    $more=$row["more"];
    
    
    echo '<img src = "';
    	echo $path;
    	echo '"width="180">';
    }
    
    
    
    ?>
    

  8. I think I have nearly got it,

     

    I just need to work out how to write the following in the correct syntax

     

    if $wk_no increases by one the shuffle($pictures);

     

    currently I have the following

     

    <?php 
    	include ("inc/db.php");
    
    $wk_no = date("W"); //gives the current week
    // Query database
    $count_sql = 'SELECT * FROM main_week_pic';
    $count_result = mysql_query($count_sql);
    // Get number of articles, assign value to variable
    $count = mysql_num_rows($count_result);
    echo "The database has this many fields: $count <br />";
    echo "We are currently in week $wk_no";
    
    
    $result = mysql_query($count_sql) or die ("Couldn't execute query.");
    $pictures = array();
    // Populate cells using a mysql_fetch_array script 
    while ($row=mysql_fetch_array($result))
    {
    
    $id=$row["id"];
    $path=$row["path"];
    $more=$row["more"];
    
    
    
    $pictures[$id] = $path;
    
    
    }
    
    // If week increases +1 then  $wk_no ++1 (i++1) shuffle($pictures);
               shuffle($pictures);
    
    ?>
    
    <h3>Undesign of the Week</h3>
    <p class="imgcenter">
    
    
    <?php // here is a loop that sorts the order of appearance and sets the size and location of images generated
    
    for ($i = 1; $i<2; $i++)
    {
    	echo '<img src = "';
    	echo $pictures[$i];
    	echo '"width="180">';
    }
    ?>

  9. Just to add I have now set it up to count the rows in the table

     

    // Query database
    $count_sql = 'SELECT * FROM main_week_pic';
    $count_result = mysql_query($count_sql);
    // Get number of articles, assign value to variable
    $count = mysql_num_rows($count_result);
    echo "The database has this many fields: $count";
    
    

     

    Here is a test page so you can see what I am trying to do

     

    http://www.undesign.co.uk/undesign_of_the_week.php

  10. Perhaps what you need to do is this.

     

    Count the # of 'images of the week' that exist in the database.

     

    Determine the current week number - $wk_no = date("W")

     

    Using the modulus operator (%) determine which 'image of the week' to display.

     

    That will show the same image to all visitors until the week number changes.

     

    Thanks

     

    I have added

     

    $wk_no = date("W");
    echo "$wk_no";
    

     

    the result is 21 so I assume this is the current week number

     

    Not sure where to put the % do you mean in the mysql statement?

     

    There are currently 3 images in the database, but the script should cycle the images that are in the database but weekly.

     

    I am still a bit stuck about how to proceed. Should I still be using the array/Randomize Function/For Loop combination?

     

  11. I have a section on my site that I want to show a particular image each week.

     

    I currently have a randomize function using shuffle but this seems to change the image every time you change the page. I want it to actually change weekly if possible.

     

    Any idea how I can do that?

     

    Here is the code

     

    <?php 
    include ("inc/db.php");
    
    $query = "SELECT * FROM main_week_pic ORDER by id "; //querying the database, this means select everything 
    //from the table called boxes and order by id i.e 1,2,3,4,5,6,7,8,9
    
    
    
    $result = mysql_query($query) or die ("Couldn't execute query.");
    
    
    $pictures = array();
    
    // Populate cells using a mysql_fetch_array script 
    while ($row=mysql_fetch_array($result))
    {
    
    $id=$row["id"];
    $path=$row["path"];
         $more=$row["more"];
    
    
    $pictures[$id] = $path;
    
    }
    
    //here is the randomising function
    
    srand ((float)microtime()*1000000);
    shuffle($pictures);
    
    ?>
    
    <h3>Picture of the week</h3>
    <p class="imgcenter">
    
    
    <?php // here is a loop that sorts the order of appearance and sets the size and location of images generated
    
    for ($i = 1; $i<2; $i++)
    {
    	echo '<img src = "';
    	echo $pictures[$i];
    	echo '"width="180">';
    }
    ?>

     

    One additional question. If I was to add a link to the image using $path from the database and an author's name using $more how could I make sure that when the picture changes it also shows the corresponding path and author?

     

    Here is the sql

     

    CREATE TABLE `main_week_pic` (
      `id` int(11) NOT NULL auto_increment,
      `path` text NOT NULL,
      `more` text NOT NULL,
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
    
    -- 
    -- Dumping data for table `main_week_pic`
    -- 
    
    INSERT INTO `main_week_pic` (`id`, `path`, `more`) VALUES 
    (1, 'images/valcard.jpg', 'Jasper Pattison'),
    (3, 'http://confluxfestival.org/media/projects/project441/441_public_web_image.jpg', 'confluxfestival.org'),
    (4, 'http://graphics8.nytimes.com/images/2006/04/09/weekinreview/09bruni.600.jpg', 'Ji Lee');
    

  12. Hi,

    I am running wordpress on Apache and when I post a message the time and date are set to January 1st 1970. It appears that the UTC time of the server is set to this date. I am not sure how to change it. Can I do it in the httpd.conf or is it php.ini?


    Any ideas
×
×
  • 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.