Help Required - PHP Program - Possible payment

Discussion in 'PHP' started by Thizzle, Jul 23, 2010.

  1. #1
    Alright, here's what I want my website (http://gift-for-men.com/) to do. When someone visits the index page the index.php file is runned. What I want to index file to do is grab a random row from the database then redirect people to random page based on the id of the row grabbed.For example, I visit gift-for-men.com/ then I'm redirected to gift-for-men.com/page?=1 ( 1 is the id ) it could be the id 2, 3, 440, whatever row from the database was grabbed. I added the page?= to make it prettier if you can do this.

    Also in when the row is grabbed I have other columns that I want to echo throughout the entire document. So if it can be stored in a array I would appreciate it.

    Anyone who helps thanks. If you write the entire program we can discuss payment.
     
    Thizzle, Jul 23, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    Place the following code right at top of (http://gift-for-men.com/) index.php:

    <?php
    //retrieve random id from table... - replace table_name with the name of your table...
    $result = mysql_query("SELECT id FROM table_name ORDER by rand() LIMIT 1");
    
    $id = mysql_result($result, 0, 0);
    
    //perform redirect...
    header("Location: http://gift-for-men.com/page?={$id}");
    ?>
    PHP:
     
    danx10, Jul 23, 2010 IP
  3. Thizzle

    Thizzle Peon

    Messages:
    115
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I get the following error: Warning: Cannot modify header information - headers already sent by (output started at /home/content/00/6453700/html/index.php:4) in /home/content/00/6453700/html/index.php on line 10
     
    Thizzle, Jul 25, 2010 IP
  4. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #4
    Hmm thats a typical problem, usually occured due to output being sent before the header() redirect...theirfore this should resolve it (quick fix):

    Add to the very top of index.php, straight after the php tag (<?php):
    ob_start();
    PHP:
    And at the end just before the closing php tag (?>):
    ob_end_flush();
    PHP:
     
    danx10, Jul 25, 2010 IP
  5. Thizzle

    Thizzle Peon

    Messages:
    115
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Same Error. Also thanks for helping me I appreciate it.
     
    Thizzle, Jul 25, 2010 IP
  6. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #6
    Post the entire contents of index.php
     
    danx10, Jul 25, 2010 IP
  7. Thizzle

    Thizzle Peon

    Messages:
    115
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Sorry I should of done that in the first place...

    <!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">
    
    <?php
         include 'include/simple.php';
         $query  = "SELECT * FROM suggestions ORDER BY Rand() LIMIT 1";
         $result = mysql_query($query);
         $row = mysql_fetch_array($result);
         ?> 
     
    
        <head>
             <title>Gift For Men</title>             
             <meta name="keywords" content="Gift For Men, Gift" />
             <meta name="description" content="Don't know what to get a man? With Gifts-For-Men.Com we'll randomly make suggestions to you!" />
             <link rel="stylesheet" type="text/css" href="assets/Stylesheet.css" />
    </head>
    
    <!--HEADER-->
    <body>
    
    <div id="fb-root"></div>
    
          <div id="contain" class="header">      
                  <div id="contain" class="title">
                            <h1><a href="http://gift-for-men.com/" title="Gift For Men">Gift For Men</a></h1>
                       <?php
                            echo "Get your man " , $row['link'];
    	                    ?>
                  </div>
                  
                        <div id="contain" class="logo">
                        <center><img src="http://i983.photobucket.com/albums/ae320/Hamiltoncameron33/logo.png" width="115" height="160" alt="Gift For Men Logo" /></center>
                        </div>
    </div>
    
    
    <!--BODY -->
    
    <div id="funny">
                    <?php
                         echo $row['funny'];
    	                 ?>
    </div>
    
    
    
    <div id="body" class="contain">
          <div id="body" class="amazon">
                                       <?php
                                            echo $row['product'];
    	                                    ?>
          </div>
    </div>
    <!--FOOTER -->
    
          <div id="suggest">
          <a href="http://gift-for-men.com/" title="Need another suggestion?">Need another suggestion?</a>
          </div>
    
    
    <div id="footer" class="contain">
    
        
          <div id="footer" class="copyright">
          <p><a href="http://gift-for-men.com/" title="Gift For Men">Gift For Men</a> - Copyright 2010 &copy;</p>
          </div>
          <div id="footer" class="facebook">
          <iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fgift-for-men.com%2F&amp;layout=standard&amp;show_faces=false&amp;width=320&amp;action=like&amp;colorscheme=dark&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:320px; height:35px;" allowTransparency="true"></iframe>
          </div>
    </div>
       
    </body>
    </html>
    PHP:
     
    Thizzle, Jul 26, 2010 IP
  8. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #8
    <?php
         include 'include/simple.php';
         $query  = "SELECT * FROM suggestions ORDER BY Rand() LIMIT 1";
         $result = mysql_query($query);
         $row = mysql_fetch_array($result);
         //perform redirect...
         header("Location: http://gift-for-men.com/page?={$row['id']}");
         ?> 
    
    <!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>
             <title>Gift For Men</title>             
             <meta name="keywords" content="Gift For Men, Gift" />
             <meta name="description" content="Don't know what to get a man? With Gifts-For-Men.Com we'll randomly make suggestions to you!" />
             <link rel="stylesheet" type="text/css" href="assets/Stylesheet.css" />
    </head>
    
    <!--HEADER-->
    <body>
    
    <div id="fb-root"></div>
    
          <div id="contain" class="header">      
                  <div id="contain" class="title">
                            <h1><a href="http://gift-for-men.com/" title="Gift For Men">Gift For Men</a></h1>
                       <?php
                            echo "Get your man " , $row['link'];
                            ?>
                  </div>
                  
                        <div id="contain" class="logo">
                        <center><img src="http://i983.photobucket.com/albums/ae320/Hamiltoncameron33/logo.png" width="115" height="160" alt="Gift For Men Logo" /></center>
                        </div>
    </div>
    
    
    <!--BODY -->
    
    <div id="funny">
                    <?php
                         echo $row['funny'];
                         ?>
    </div>
    
    
    
    <div id="body" class="contain">
          <div id="body" class="amazon">
                                       <?php
                                            echo $row['product'];
                                            ?>
          </div>
    </div>
    <!--FOOTER -->
    
          <div id="suggest">
          <a href="http://gift-for-men.com/" title="Need another suggestion?">Need another suggestion?</a>
          </div>
    
    
    <div id="footer" class="contain">
    
        
          <div id="footer" class="copyright">
          <p><a href="http://gift-for-men.com/" title="Gift For Men">Gift For Men</a> - Copyright 2010 &copy;</p>
          </div>
          <div id="footer" class="facebook">
          <iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fgift-for-men.com%2F&amp;layout=standard&amp;show_faces=false&amp;width=320&amp;action=like&amp;colorscheme=dark&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:320px; height:35px;" allowTransparency="true"></iframe>
          </div>
    </div>
       
    </body>
    </html>
    PHP:
     
    danx10, Jul 26, 2010 IP
  9. Thizzle

    Thizzle Peon

    Messages:
    115
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    No error this time but it doesn't display the URL like we want... Sorry, if you're getting irritated man.
     
    Thizzle, Jul 26, 2010 IP
  10. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #10
    'URL like we want', what you mean?
     
    danx10, Jul 26, 2010 IP