1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

MySql Query Question

Discussion in 'MySQL' started by SpankedNutz, Oct 9, 2005.

  1. #1
    Hi there,

    I have a mysql/php driven site.
    Every week i get list of galleries that I can import into the db.
    That works fine now....took me a while but it works like a baby.

    Anyways, the problem is here:
    I get multiple gallery urls from sponsers. When I import the galleries they all have different urls.

    The problem is that when clicking on the links all the urls from the same sponser are the same, but in the DB they are different. The query somehow uses the first sponser link and doesn't go on to next sponser gallery.

    This is the query I use now:

    The query at the top of the PHP:
    $sql = "SELECT * FROM `galleries` ORDER by RAND()";


    Just to point out: The name field is the same for the same sponser, the only difference between the entries are the urls
    I want to have a page with all the entries linking to the right galleries

    Cheers
     
    SpankedNutz, Oct 9, 2005 IP
  2. TheHoff

    TheHoff Peon

    Messages:
    1,530
    Likes Received:
    130
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Please show all of the PHP code you are using to sift through the galleries after the select. Your Select statement is fine; I'm guessing the problem is that you're not sorting through the entries correctly.

    while ($entry = mysql_fetch_array($entries))
    {
    // do stuff here
    }

    It sounds like you're just loading one entry and not whileing through the array.
     
    TheHoff, Oct 9, 2005 IP
  3. SpankedNutz

    SpankedNutz Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Heya, here's what i use for my other sites:
    For the other site I want 1 entry per site/domain. This works fine there.
    I added in the db an ID field (auto increment) In the last couple of lines you can see that i added the ID field...it adds it to the output url but the gallery doesn't load.





    <?

    $result = mysql_query($sql) or die (mysql_error()); // query the DB

    $y = (int)(mysql_num_rows($result) / 3);

    //echo $y;

    for ($x = 0;$x < mysql_num_rows($result);$x++)

    {

    $row = mysql_fetch_assoc($result);

    #echo $row[Sitename_open];

    $closed = str_replace(" ","",$row[Sitename_closed]);

    echo "<a href=http://www.domain.com/galleries/$row[id]/".$closed."/ title=".$row[Sitename_open]."><p><li>".$row[Sitename_open]."&nbsp; -&nbsp; ".$row[Message]."</a></p>\n";
    #echo "<a href=http://www.domain.com/alleries/".$closed."/ title=".$row[Sitename_open]."><p><li>".$row[Sitename_open]."&nbsp; -&nbsp; ".$row[Message]."</a></p>\n";
    print ($x % $y) ? "" : "\n";

    }

    ?>
     
    SpankedNutz, Oct 9, 2005 IP