1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Random Featured Content

Discussion in 'General PHP and MySQL Discussions' started by HoddzDJ, Jan 7, 2012.

  1. HoddzDJ

    HoddzDJ Active Member

    Okay I have literally been trawling the internet for the past few hours looking for an easy scrip of code to help me display a random bit of code on my site to cut down on the messiness but I can't find anything anywhere. I will tell you what I want any hopefully the xenForo'ers will be able to help me out!!

    I have three 'featured' sections on my website, and they are youtube, soundcloud and a flyer linked to a Facebook event page/website. All are randomly displayed used a <script> code on the page so it's very messy in my eyes so I have setup a mysql database and put all the info in there.

    I have a databse setup 'featured' with three tables in it 'soundcloud' 'youtube' and 'event' hopefully you are all following? I setup each table with two rows, 'id' and 'code' because I think it will be easier for me to do it that way although writing this now I think it may be easier to have one table with 'id' and 'code' and just enter in the 'id' field either 'youtube' 'soundcloud' or 'event' and then I can add a 'where id = "soundcloud"' or something like that?

    Basically, all I want to do is have three separate PHP codes for each of the separate featured things. I'm never going to have more than probably 10 of each at any one time so I don't really need anything that's optimised for that many entries, I just need a bit of help! I never remember it being so hard, but it has totally gone from my mind of where to even start, so rusty nowadays :(

    Hope I haven't confused anyone and thanks in advance!
  2. HoddzDJ

    HoddzDJ Active Member

    PHP:
    <?php
    // Make a MySQL Connection
    mysql_connect("localhost""username""password") or die(mysql_error());
    mysql_select_db("pukkarad_featured") or die(mysql_error());
     
    // Retrieve all the data from the "example" table
    $result mysql_query("SELECT * FROM content")
    or die(
    mysql_error()); 
     
    // store the record of the "example" table into $row
    $row mysql_fetch_array$result );
    // Print out the contents of the entry
     
    echo "Name: ".$row['code'];
     
    ?>
    I have this code, which seems to display absolutely nothing even though I have two entries in my table each with their different values in the 'code' field. Any help would be much appreciated, I am pulling my hair out!!

Share This Page