Jump to content

array 2 dimensions and random selection


lmcm2008

Recommended Posts

Hi: I would like to do something really easy, but I never know how to do it. Please help me.

I have a data base where I make the selection in this way:

$cadena="SELECT * FROM table WHERE (TYPE='2')";
$result=mysql_query($cadena) or die(mysql_error());
$totalreg=mysql_num_rows($result);

 

Ok, here not problem... I get all the registers with that condition....

Now is the problem...

 

I want to make this...

 

ARRAY [1][iD register 1]

ARRAY [2][iD register 2]

ARRAY [3][iD register 3]

 

and so on until finish when no more registers whave that condition...

for example:

 

ARRAY [66][iD register 66]  <--- of $totalreg before.

 

So I have 66 (or XXX ) records selected in the array, and know the Id of every register that I selected before.

 

AND NOW...

 

I want to make a random selection on that array and operate with the register of that selection and make a select to the database on the ID register X...

 

Can you help me??

 

Thanks a lot.

 

 

Regards

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/267594-array-2-dimensions-and-random-selection/
Share on other sites

Hi:

Ok, I made this...

$cadena="SELECT * FROM mytable WHERE (TIPO='2')";
$result=mysql_query($cadena) or die(mysql_error());
$totalreg=mysql_num_rows($result);
echo "Registros: $totalreg<br>"; // running perfectly the selection...


// begin the array

$contador=0;
while ( $registro=mysql_fetch_array($cadena) )
{
$numeros[$contador]=$registro["ID"]; // ID is my field in the database 
$contador++;
}

$elementos=sizeof($numeros-1);

//debug
echo"Elementos: $elementos<br>";

 

Ok, In the debug line that I make a echo...

 

echo"Elementos: $elementos<br>";

 

I receive -1

Why??? It seems that the array is looking good.. or not?? How can I be sure that I fill the array correctly and I have all the items that I received from the data base ???

 

How can I make an echo from all the array to see if is good filled or not??

 

Please, help...

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.