Debt Help - Adverse Credit Remortgage - Cheap Flights - Loans - Debt Consolidation

PDA

View Full Version : MySql Query Question


SpankedNutz
Oct 9th 2005, 7:50 am
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

TheHoff
Oct 9th 2005, 8:10 am
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.

SpankedNutz
Oct 9th 2005, 8:16 am
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";

}

?>