Jump to content

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

 

 

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.