Jump to content

Random Row Selection with MultiTable lookup


Jerzxu

Recommended Posts

HELLO!

I am working on a featured users for my site and and it has to grab a random userid from the main accounts table then it goes to the pages table and grabs more info after it has grabbed the username from the main accounts table. It has to do this 3 times and echo the same code 3 times.

Now oddly I don't get ANY errors with this code. It just doesn't do anything.

 

//Featured
$UID = mysql_query("SELECT * FROM `Accounts` WHERE 'Activated'='Yes' ORDER BY RAND() LIMIT 3");
for ($i=0;$i<3;$i++) {
   	while ($recs = mysql_fetch_array($UID)) {
	$recs1 = $recs['Username'];
	$usernamequery = mysql_query("SELECT `Username` FROM `Accounts` WHERE `UID`='$recs1'");
	$username = mysql_result($usernamequery,0);
	$pagequery = mysql_query("SELECT `Page` FROM `Accounts` WHERE `UID`='$recs1'");
	$page = mysql_result($pagequery,0);
	$imagequery = mysql_query("SELECT `Img` FROM `UserPics` WHERE `Username`='$username'");
	$image = mysql_query($imagequery,0);
	if ($page == "Normal") {
		//Grab About INFO
		$aboutquery = mysql_query("SELECT `About` FROM `Page_Normal` WHERE `Username`='$username'");
		$about = mysql_result($aboutquery,0);
	}
	echo "<div class=featured1>
        <div class=\"padfeat1\" align=\"left\">
        <img src=\"stylesheets/images/seperator_03.png\" align=\"left\" hspace=\"5\" />
        Pad<br />
        <img src=padfeat.jpg style=\"margin-top:1px;\" onclick=\"parent.location=''\" /><img src=padfeat.jpg hspace=\"3\" onclick=\"parent.location=''\" /><img src=padfeat.jpg onclick=\"parent.location=''\" /><img src=padfeat.jpg hspace=\"3\" onclick=\"parent.location=''\" /><br />
        <center><a href=\"\">View More</a></center>
        </div>
    <img src=\"resize-image.php?image=".$image."\" width=\"62\" height=\"62\" hspace=\"2\" align=\"left\" onclick=\"parent.location=''\" />
    <a href=\"http://www.ekoed.com/".$username."\">".$username."</a><br />
    <a href=\"http://www.ekoed.com/users.php?account=".$page."\">".$page."</a><br />
    About Them: ".$about."<br />
    </div>";
}
}

 

Now I was reading somewhere that if you have ALOT of accounts that using RAND() would take some time. Not that I will have many users on my site, but is there a way to make it go faster?

Link to comment
Share on other sites

if you're not seeing anything it's probably because one or more of you SQL statements is incorrect. when i use mysql_query(), i always include or die(mysql_error()) in case my SQL is bad.

 

$result = mysql_query($sql) or die(mysql_error());

 

i would add some die's and see if your SQL is bad.

Link to comment
Share on other sites

I edited it abit just to see if it would even grab non random codes. Still doesnt work.

$UID = mysql_query("SELECT * FROM `Accounts` WHERE 'Activated'='Yes'");
for ($i=0;$i<3;$i++) {
   	while ($recs = mysql_fetch_array($UID)) {
	$username = $recs['Username'];
	$imagequery = mysql_query("SELECT `Img` FROM `UserPics` WHERE `Username`='$username'");
	$image = mysql_query($imagequery,0);
	if ($recs['Page'] == "Normal") {
		//Grab About INFO
		$aboutquery = mysql_query("SELECT `About` FROM `Page_Normal` WHERE `Username`='$username'");
		$about = mysql_result($aboutquery,0);
	}
	if ($recs['Page'] == "Band") {
		//Grab About INFO
	}
	if ($recs['Page'] == "Business") {
		//Grab About INFO
	}
	if ($recs['Page'] == "Studio") {
		//Grab About INFO
	}
	if ($recs['Page'] == "Portfolio") {
		//Grab About INFO
	}
	if ($recs['Page'] == "Website") {
		//Grab About INFO
	}
	echo "<div class=featured1>
        <div class=\"padfeat1\" align=\"left\">
        <img src=\"stylesheets/images/seperator_03.png\" align=\"left\" hspace=\"5\" />
        Pad<br />
        <img src=padfeat.jpg style=\"margin-top:1px;\" onclick=\"parent.location=''\" /><img src=padfeat.jpg hspace=\"3\" onclick=\"parent.location=''\" /><img src=padfeat.jpg onclick=\"parent.location=''\" /><img src=padfeat.jpg hspace=\"3\" onclick=\"parent.location=''\" /><br />
        <center><a href=\"\">View More</a></center>
        </div>
    <img src=\"resize-image.php?image=".$image."\" width=\"62\" height=\"62\" hspace=\"2\" align=\"left\" onclick=\"parent.location=''\" />
    <a href=\"http://www.ekoed.com/".$recs['Username']."\">".$recs['Username']."</a><br />
    <a href=\"http://www.ekoed.com/users.php?account=".$recs['Page']."\">".$recs['Page']."</a><br />
    About Them: ".$about."<br />
    </div>";
}
}

 

As for the output. Just go to www.ekoed.com and that page is it. What is echoed is at the bottom of the page (just error checking underneath the copyright), which is the $UID. If $UID echo's but everything else doesnt.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.