Jump to content
php.lv forumi

kaa dabuut aaraa


Klez

Recommended Posts

<?
$max = mysql_query("SELECT * FROM tabula WHERE text like '%$veriba%'");
$cik_atrod = mysql_num_rows($max);
while ($atb = mysql_fetch_array($max)){
echo $atb['text']." id=".$atb['id']." !! <br>";
}
mysql_free_result($max);
?>

 

nu lieta taada.

ieraxtus no DB daduuju. zinu arii skaitu cik ieraxtu ir atrasti. bet man vajag no atrastajiem ieraxtiem uz ekraana paraadiitu vienu tikai.

kaads varbuut zin kaa to dabuut gatavu?

:(

Link to comment
Share on other sites

ja vajag pirmo izvadiit, tad sita..

 

<?

$max = mysql_query("SELECT * FROM tabula WHERE text like '%$veriba%'");

$cik_atrod = mysql_num_rows($max);

 

$i=0;

while ($atb = mysql_fetch_array($max) || $i < 1)

{

echo $atb['text']." id=".$atb['id']." !! <br>";

$i++;

}

mysql_free_result($max);

?>

 

straadaa?

Link to comment
Share on other sites

labi, karoche taa..

 

<?

$rs = mysql_query("SELECT id, text FROM tabula WHERE text like '%$veriba%'");

$amount = mysql_num_rows($rs);

 

// izveidojam masiivu

 

$rd_array = array();

while ($row = mysql_fetch_array($rs))

{

$rd_array[] = $row['id'].";".$row['text'];

}

mysql_free_result($rs);

 

// izvadam uz random vienu

 

echo $rd_array[rand (0, $amount-1) ];

 

?>

 

vajadzeetu straadaat, kaut arii es netesteeju..

 

p.s. nosaucu cilveeciigi visus mainiigos, liidz ar to, njem kopee visu skriptu un pec tam testee.

Link to comment
Share on other sites

tenx. nodereeja. viss straadaa kaa naakas :) :) :)

Citāts no http://j.esuntu.com/2004/02/11/mysql_un_php_sikumi_nr-2/

 

MySQL

 

Lai no datubāzes uz dullo izvēlētos kādu ierakstu, nav jāraksta PHP skripts, kas noskaidro ierakstu skaitu un iespējamos id datubāzē – pietiek ar MySQL pieprasījumu:

 

SELECT * FROM tabula ORDER BY RAND() LIMIT 1;

Link to comment
Share on other sites

×
×
  • Create New...