Jump to content

How To Limit and Randomize The Data Displayed


swbdesigns

Recommended Posts

Hello,

I have a stock page on my site and want to use the code to display a small stock area on my home page. I am not sure on how I would limit the number of records or randomize the records shown. The code is

 <?php
	  	$coachselect=mysql_query("SELECT * FROM coaches WHERE DISPLAY = '1' ORDER BY STOCK")or die(mysql_error());
				while($row = mysql_fetch_array($coachselect)){
				?>
                    
                    <ul class="stock-home">
                    <li><h4><a href="details-id-<?php echo $row['ID']; ?>.html" target="_blank"></a></h4></li>
                    <li><img src="./<?php echo $row['IMAGES'] . "/" . $row['DEFAULT_IMAGE'] ; ?>" width="187" height="138" alt="lehel virage for sale"  class="fl"/></li>
                    <li><?php echo $row['NAME']; ?></h3></li><li><?php echo $row['DESC_SHORT']; ?></li>
                    <li><a href="details.php?id=<?php echo $row['ID']; ?>" target="_blank">more info...</a></li>
<li><?php echo $row['DESC_2']; ?></li>
                    
                    </ul><!--close stock home-->
    
    <?php
			}
			?>

 

 

I am guessing that something needs to be added here

$coachselect=mysql_query("SELECT * FROM coaches WHERE DISPLAY = '1' ORDER BY STOCK")or die(mysql_error());
				while($row = mysql_fetch_array($coachselect)){
				?>

 

 

But am not sure how to do it? Does anyone have any advice or could point me to a tutorial?

 

 

Here is the rest of the code, from the top of the page.

 

$CON=mysql_connect($DB_SERVER, $DB_USER, $DB_PASS) or die(mysql_error());
$DB_SELECT=mysql_select_db($DATABASE) or die(mysql_error());

if (isset($_POST)) {
foreach ($_POST as &$value) {
    $value = trim(htmlspecialchars($value, ENT_QUOTES));
}
}

if (isset($_GET)) {
foreach ($_GET as &$value) {
    $value = trim(htmlspecialchars($value, ENT_QUOTES));
}
}

$_SERVER['PHP_SELF'] = filter_var($_SERVER['PHP_SELF'], FILTER_SANITIZE_STRING);

?>

 

Many Thanks

 

Dan

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.