0
I have this script, I needed to include a select randomly.
<?php
$sql_veiculos = mysqli_query($config, "SELECT ma.categoria, m.modelo, m.versao, m.ano, m.motor, t.transmissao, m.portas, c.combustivel, m.cor, m.km, m.carroceria, m.condicoes, m.descricao, m.visivel, m.placa, m.destaque, m.id, ma.slug, m.slug, m.id, m.valor FROM tb_modelos m LEFT JOIN tb_categorias AS ma ON (m.marca = ma.id) LEFT JOIN tb_transmissao AS t ON (m.transmissao = t.id) LEFT JOIN tb_combustiveis AS c ON (m.combustivel = c.id) WHERE m.visivel = 'S' ORDER BY m.destaque DESC, m.data_cadastro, RAND() DESC LIMIT $limite") or die(mysqli_error($config));
?>
The RAND(), in this case, is leaving the random select, this part is correct. But there are more items featured in the database.
It would be possible to read all the highlighted items, display randomly, limiting by the determined amount?
yes is possible, you can read all the records, by an array and randomly draw what you want to display
– Ricardo Pontual
What is your query returning? It no longer sorts the highlights first and returns the defined LIMIT?
– Woss
Yes, exact! But it only sorts and returns the items defined in LIMIT. For example, there are 30 items marked as visible in the database, but only 10 can be displayed. This sql only sorts the latest 10. The question arose whether it would be possible to read all the records marked as highlight, and keep displaying them randomly, by the defined limit. I will try to put in an array.
– Rogério Pancini