Need some very simple PHP script. Will pay by BackLink

Discussion in 'PHP' started by iNfans, Jan 16, 2007.

  1. #1
    Hi everyone. Sorry for my terrible english, its because I dont speak english. As a repayment for help, I will put a BL from my PR4 site to helpers site for permanently.
    So, I need some very simple script, thats getting some info from db and some adminpanel for adding those info to db. The scheme must be like this:

    [Admin panel]
    Forms for adding info to DB:
    Must be 1 form for (Title name), and a few forms that adds info to (Title name), like a parameters. I will name them (Info1) (Info2) (Info3).
    So it must look like - [​IMG]

    FOR EXAMPLE WE ADD INFO: Title name: mysite1 ; Info1: url.com ; Info2: myhomepage ; Info3: site.gif .

    [Script file]
    Script file must get info from db by url I entered, for example I open "thisscript.php?ch=mysite1". I must get info from DB: url.com, myhomepage, site.gif.
    So it must look like:
    script:
    "
    <?php
    some script
    ?>
    <html>
    Url- <?php echo $Info1; ?> ($Info1; - is not right, I just entered like example)
    Descr- <?php echo $Info2; ?>
    Img- <?php echo $Info3; ?>
    </html>
    "
    in browser, content:
    "
    Url- url.com
    Descr- myhomepage
    Img- site.gif
    "

    If you something or nothing understand, post what, I will try to write more clearly.

    I have some experience with DB and PHP, so you can just post script without descriptions. Also send me to PM your site url, I will place it on my site.


    P.S. before I used script like this:
    "
    <?php
    if(isset($ch)){
    if ($ch == "entv") {$url= "http://www.entv.dz"; $descr= "bla bla"; $some= "info";}
    if ($ch == "qwetv") {$url= "http://www.tqwe.com"; $descr= "bla bla"; $some= "info";}
    ... over 5000 same lines..
    ?>
    <html>
    site content with <?php echo $url; ?> <?php echo $descr; ?> <?php echo $some; ?> ....
    </html>
    "
    As you see this file is very large, its loading slowly, so I need to put those info into DB to get only that info that is requested, not all... and faster page loading..
     
    iNfans, Jan 16, 2007 IP
  2. just-4-teens

    just-4-teens Peon

    Messages:
    3,967
    Likes Received:
    168
    Best Answers:
    0
    Trophy Points:
    0
    #2
    might be a bit more than you want, but couldnt you use a directory script?
     
    just-4-teens, Jan 16, 2007 IP
  3. iNfans

    iNfans Well-Known Member

    Messages:
    160
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #3
    what do you mean? I dont know so good php do edit directory script..
     
    iNfans, Jan 16, 2007 IP
  4. just-4-teens

    just-4-teens Peon

    Messages:
    3,967
    Likes Received:
    168
    Best Answers:
    0
    Trophy Points:
    0
    #4
    well with a directory script, a visitor can submite a link + a description and in your admincp you review the links and add/remove from the database as you need.
     
    just-4-teens, Jan 16, 2007 IP
  5. peaforabrain

    peaforabrain Active Member

    Messages:
    45
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    63
    #5
    This is indeed a fairly simple thing to do, but it involves a little more work than can be worth just a PR4 back link.


    What just 4 teens mentioned is your best bet, and do a search for a directory script, and install one of those on your website. It should include all the filkes you need to accomplish this.
     
    peaforabrain, Jan 16, 2007 IP
  6. iNfans

    iNfans Well-Known Member

    Messages:
    160
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #6
    So, today I finally get this script, and he is below.

    I have a new question.

    How can I get info from from different $title's DB and put in simple html template? I think its will be better for me if by include echo. For example, I will add a few $title's with $url $descrip $imglink into DB, let it be - name1 and name2 (with parameters $url $descrip $imglink). Now I wont to echo $url $descrip $imglink from name1 and name2 title's into html page, how can I do that?

    P.S. sorry for my pure english...

    Script:
    Admin pannel with password protection, pwd&login sets in config:
    <?php
    
    include("db_config.php");
    
    if(isset($login_check) && $login_check == $login && isset($password_check) && $password_check == $password){
    
    if(isset($do)){
    	
    $title = $_POST['title'];
    $url = $_POST['url'];
    $descrip = $_POST['descrip'];
    $imglink = $_POST['imglink'];
    
    $sql = "INSERT INTO urlinfo (title,url,descrip,imglink) VALUES ('".$title."','".$url."','".$descrip."','".$imglink."')";
    
    $result = mysql_query($sql);
    
    if($result) {
     print "Information inserted into Database successfully <br><br> <a href=$PHP_SELF?>EXIT</a>";
    }
    	
    } else {
    
    print"<form method=post action=$PHP_SELF>
    <input type=hidden name=login_check value=$login_check>
    <input type=hidden name=password_check value=$password_check>
    <input type=hidden name=do value=do>
    <div>Site name:</div>
    <input type=text name=title />
    <div>Url:</div>
    <input type=text name=url />
    <div>Description:</div>
    <input type=text name=descrip />
    <div>Image Link:</div>
    <input type=text name=imglink />
    <input type=submit value=Add />
    </form> <br><br> <a href=$PHP_SELF?>EXIT</a>";
    
    }
    
    } else {
    	print"
    	<form action=$PHP_SELF method=post>
    	Login: <input type=text name=login_check>
    	Password: <input type=password name=password_check>
    	 <input type=submit value=Enter>
    	</form>
    	";
    }
    ?> 
    PHP:
    Config file:
    <?
    
    $conn = @mysql_connect('localhost', 'login', 'password');
    @mysql_select_db('dbname', $conn);
    
    $login = "admincp";
    $password = "admincp";
    
    ?>
    PHP:
    Main script that get info from db:

    <?php
    
    include("db_config.php");
    
    if(isset($title)){
    $sql = "SELECT * FROM urlinfo WHERE title='$title'";
    $result = mysql_query($sql);
    
    if($result) {
    while($row = mysql_fetch_array($result)){
    echo 'Site Name: '.$row['title'].'<br />
    URL: '.$row['url'].'<br />
    Description: '.$row['descrip'].'<br />
    Image Link: '.$row['imglink'].'<br />
    ';
    } 
    } 
    }else {print"no parameters";};
    ?> 
    PHP:
    Table:
    CREATE TABLE `urlinfo` (
      `title` varchar(255) NOT NULL default '',
      `url` varchar(255) NOT NULL default '',
      `descrip` varchar(255) NOT NULL default '',
      `imglink` varchar(255) NOT NULL default ''
    ) ENGINE=MyISAM;
    Code (markup):
     
    iNfans, Jan 17, 2007 IP
  7. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #7
    
    <?php
    include("db_config.php");
    function retrieve( $title, $template )
    {
     	if(!file_exists($template))
     	{
    		die("Template file not found");
    	}
    	$result = mysql_query("SELECT * FROM `urlinfo` WHERE title='$title' LIMIT 1");
    	if( $result ) 
    	{
    		while($row = mysql_fetch_assoc($result))
    		{
    		 	$tempvars = array
    		 	(
    		 	"{SITE_NAME}",
    		 	"{URL}",
    		 	"{DESC}",
    		 	"{IMG_SRC}"
    			);
    			$tempvals = array
    			(
    			$row['title'],
    			$row['url'],
    			$row['descrip'],
    			$row['imglink']
    			);
    		 	$cache = str_replace( $tempvars, $tempvals, file_get_contents( $template ));
    		}
    		if( $cache )
    		{
    			return $cache;
    		}
    	}
    	else
    	{
    		die("Cannot query database");
    	}
    }
    /*
    Example usage.
    Either save the above php in a file by itself, or use bits of this file to do what you need it to
    */
    $result = mysql_query("SELECT * FROM `urlinfo`");
    while($all = mysql_fetch_assoc($result)) :
    
    	$content .= retrieve($all['title'], "template.html");
    
    endwhile;
    if($content != "")
    {
    	echo $content;
    }
    else
    {
    	echo "Cannot retrieve content from database";
    }
    ?>
    
    PHP:
    The above contains the function you're looking for, and an example of how to use it.

    
    Name : {SITE_NAME}<br />
    URL : {URL}<br />
    DESC : {DESC}<br />
    IMG : {IMG_SRC}<br />
    <hr />
    
    HTML:
    And the above can be saved as a .html or .php and specified for use in the function, all text contained inside {} will b replace by the appropriate value.
     
    krakjoe, Jan 17, 2007 IP
  8. iNfans

    iNfans Well-Known Member

    Messages:
    160
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #8
    Thank you very much. one second please, I will try.
     
    iNfans, Jan 17, 2007 IP
  9. iNfans

    iNfans Well-Known Member

    Messages:
    160
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #9
    So, I tested and it works. But its little not that that I wont, and its my fault. let me try to explaine more simple. I need to echo $row['url'], $row['descrip'], $row['imglink'] in html template, but I wont to set in echo from what $row['title'] to get those $row['url'], $row['descrip'], $row['imglink'] info. Can you please help me one more time again?
     
    iNfans, Jan 17, 2007 IP
  10. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #10
    That's exactly what it does do :confused:
     
    krakjoe, Jan 17, 2007 IP
  11. iNfans

    iNfans Well-Known Member

    Messages:
    160
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #11
    Maybe some overview from my mind how it must be will help you:
    "<?php
    here script
    ?>
    <html>
    content content <? echo $title=name1;descrip> content content <? echo $title=name2;imglink>
    </html>
    "
    it means, I want to echo in template in anyplace that info from $row['url'], $row['descrip'], $row['imglink'] but also set in echo from what title to get those $row['url'], $row['descrip'], $row['imglink'].
     
    iNfans, Jan 17, 2007 IP
  12. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #12
    
    <html>
    content content <br />
    <? echo retrieve("Title", "template.html"); ?> 
    content content <br />
    <? echo retrieve("Title2", "template.html"); ?>
    </html>
    
    PHP:
    It does exactly that ....
     
    krakjoe, Jan 17, 2007 IP
  13. iNfans

    iNfans Well-Known Member

    Messages:
    160
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #13
    how to echo descrip from title or title2?
     
    iNfans, Jan 17, 2007 IP
  14. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #14
    I think you misunderstand how it works, there is no need to echo the one item from the database, the idea of a template is to format the record to comply with your page, rearrange the template with just the variables you want to display on it.
     
    krakjoe, Jan 17, 2007 IP
  15. iNfans

    iNfans Well-Known Member

    Messages:
    160
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #15
    Okey, krakjoe, lets image that we have 5 titles in db with parameters url, descrip, imglink. What I must write in template file to display in different places (in content) all those 5 titles from DB with their parameters?
     
    iNfans, Jan 17, 2007 IP
  16. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #16
    You would do something like the example thats attached to the first solution, select all the data from the data base and loop over it to get all the titles.

    Then during your html use the titles to insert the preformatted template.
     
    krakjoe, Jan 18, 2007 IP
  17. iNfans

    iNfans Well-Known Member

    Messages:
    160
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #17
    Big thanks to you Joe for answers. Can you please write an example for you last mesage how to do it?
     
    iNfans, Jan 18, 2007 IP
  18. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #18
    
    $result = mysql_query("SELECT * FROM `urlinfo`");
    while($all = mysql_fetch_assoc($result)) :
    
        $content .= retrieve($all['title'], "template.html");
    
    endwhile;
    if($content != "")
    {
        echo $content;
    }
    else
    {
        echo "Cannot retrieve content from database";
    }
    
    PHP:
     
    krakjoe, Jan 18, 2007 IP