Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: script problem

  1. #1
    Banned
    Join Date
    Aug 2002
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    script problem

    What I am doing is I try to put different three pictures whenever a user visits my site.

    but it is not working yet

    Here is an error message.
    PHP Code:
    Parse errorparse errorunexpected T_VARIABLE in c:itomypicture.php on line 11 
    Here is my script
    PHP Code:
    <?php
    $con
    =mysql_connect("localhost","itohideo",1234) or die("couldn't connect'");
    $db=mysql_select_db("itohideo",$con) or die("couldn't select'");
    $num_displayed=3;
    $sql="select * from myimage limit $num_displayed";
    $result=mysql_query($sql,$con)or die("couldn't excute");
    while(
    $row=mysql_fetch_array($result)){

    $images[]=array("link"=>$row['link'],"mypic"=>$row['mypic'])
    }
    $count=$_POST["count"];
    $pick=$_POST["pick"];

    $count=count($images);
    $pick=rand(0,$count);

    echo 
    "<a href=\""$images[$pick]["link"]. "\"><img src=\"".$images[$pick]["mypic"]."\" border=0 alt=\""."\"><br>

    ?>

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    If all you are wanting to do is create a random image display then a database is really not needed. That will just slow things down. You can just put all the images in a directory and have php read the contents of the directory and randomly pick one of the images to display.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •