Re: [PHP-DB] Random pick

2010-01-25 Thread Karl DeSaulniers

Yes, $req_user_level is an int between 0 and 9.

Yes, the other code worked great.
Thank you for your response though.
That is definitely a good way to cross check.
Thanks again for your responses.
Best,

Karl


On Jan 25, 2010, at 2:24 PM, Peter Beckman wrote:


On Mon, 25 Jan 2010, Karl DeSaulniers wrote:


Thank you for this as well.
Question? What part is "in_array" playing?
Is it comparing $req_user_level to array()?
Because the text "Guest", etc.. is not in $req_user_level on the  
database.
In other words, is it checking the value of $req_user_level to see  
if "Guest" is in it?


 Sorry, I missed the question mark.  in_array isn't appropriate  
here.  The
 previous poster has it right, assuming $req_user_level is an  
integer of

 0..9.

 $levels = array("Guest", "Regular User", 'Intl. User', ...)
 // the array is   0,  1,   2 , ...)

 Going a little further:

if (!empty($levels[$req_user_level])) {  // is both set and  
doesn't evaluate to false

echo "The user is a {$levels[$req_user_level]}.\n";
} else {
//  The $req_user_level was not a valid level.
echo "The returned req_user_level was not valid.\n";
}

 Which would output, if $req_user_level was 1 (one):

The user is a Regular User.

 Then you know you have a valid user level.  Careful though --  
sometimes 0

 will be returned on a failure, depending on your SQL.

Beckman
-- 
-
Peter Beckman   
Internet Guy
beck...@angryox.com http:// 
www.angryox.com/
-- 
-


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Karl DeSaulniers
Design Drumm
http://designdrumm.com



Re: [PHP-DB] Random pick

2010-01-25 Thread Peter Beckman

On Mon, 25 Jan 2010, Karl DeSaulniers wrote:


Thank you for this as well.
Question? What part is "in_array" playing?
Is it comparing $req_user_level to array()?
Because the text "Guest", etc.. is not in $req_user_level on the database.
In other words, is it checking the value of $req_user_level to see if "Guest" 
is in it?


 Sorry, I missed the question mark.  in_array isn't appropriate here.  The
 previous poster has it right, assuming $req_user_level is an integer of
 0..9.

 $levels = array("Guest", "Regular User", 'Intl. User', ...)
 // the array is   0,  1,   2 , ...)

 Going a little further:

if (!empty($levels[$req_user_level])) {  // is both set and doesn't 
evaluate to false
echo "The user is a {$levels[$req_user_level]}.\n";
} else {
//  The $req_user_level was not a valid level.
echo "The returned req_user_level was not valid.\n";
}

 Which would output, if $req_user_level was 1 (one):

The user is a Regular User.

 Then you know you have a valid user level.  Careful though -- sometimes 0
 will be returned on a failure, depending on your SQL.

Beckman
---
Peter Beckman  Internet Guy
beck...@angryox.com http://www.angryox.com/
---

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Random pick

2010-01-25 Thread Karl DeSaulniers

Thank you for this as well.
Question? What part is "in_array" playing?
Is it comparing $req_user_level to array()?
Because the text "Guest", etc.. is not in $req_user_level on the  
database.
In other words, is it checking the value of $req_user_level to see if  
"Guest" is in it?


Karl

On Jan 25, 2010, at 1:32 PM, Peter Beckman wrote:


On Mon, 25 Jan 2010, Karl DeSaulniers wrote:


Hello List,
Trying to learn the right way to code this line.
Can anyone tell me if I am doing this the right way?

if $req_user_level == 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 ||  
9 ? "Guest" || "Regular User" || "Intl. User" || "Contractor" ||  
"Employee" || "Sales" || "Investor" || "Human Resources" ||  
"Administrator";


I am wanting to stray from the if(foo == bar) { routine. ;)


 if (in_array($req_user_level, array 
(0,1,2,3,4,5,6,7,8,9,"Guest",...))) {

 // do stuff
 }

-- 
-
Peter Beckman   
Internet Guy
beck...@angryox.com http:// 
www.angryox.com/
-- 
-


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Karl DeSaulniers
Design Drumm
http://designdrumm.com



Re: [PHP-DB] Random pick

2010-01-25 Thread Olavi Ivask

Don't you like my solution?

Regards,
Olavi

On Jan 25, 2010, at 9:39 PM, Karl DeSaulniers wrote:


Hi,
$req_user_level is a MySql return result and I am trying to utilize  
shortened code to evaluate whither $req_user_level == 0 || 1 || 2 ||  
3 || 4 || 5 || 6 || 7 || 8 || 9, if it matches a number, return the  
text associated with that number.
"Guest" || "Regular User" || "Intl. User" || "Contractor" ||  
"Employee" || "Sales" || "Investor" || "Human Resources" ||  
"Administrator";


Karl


On Jan 25, 2010, at 1:31 PM, Olavi Ivask wrote:


Hi,

did you mean something like this?

$level_names = array("Guest", "Regular User", "Intl. User",  
"Contractor", "Employee",

"Sales", "Investor", "Human Resources", 
"Administrator");

$user_level = $level_names[$req_user_level];

Regards,
Olavi Ivask


On Jan 25, 2010, at 9:13 PM, Karl DeSaulniers wrote:


Hello List,
Trying to learn the right way to code this line.
Can anyone tell me if I am doing this the right way?

if $req_user_level == 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 ||  
9 ? "Guest" || "Regular User" || "Intl. User" || "Contractor" ||  
"Employee" || "Sales" || "Investor" || "Human Resources" ||  
"Administrator";


I am wanting to stray from the if(foo == bar) { routine. ;)

Thanks,

Karl DeSaulniers
Design Drumm
http://designdrumm.com





Karl DeSaulniers
Design Drumm
http://designdrumm.com




--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Random pick

2010-01-25 Thread Karl DeSaulniers

I am trying to avoid doing this:

if ($req_user_level == 0) {
$req_user_level = "Guest";
} else if ($req_user_level == 1) {
req_user_level = "Regular User"
}
etc..


Karl DeSaulniers
Design Drumm
http://designdrumm.com



Re: [PHP-DB] Random pick

2010-01-25 Thread Karl DeSaulniers

Hi,
$req_user_level is a MySql return result and I am trying to utilize  
shortened code to evaluate whither $req_user_level == 0 || 1 || 2 ||  
3 || 4 || 5 || 6 || 7 || 8 || 9, if it matches a number, return the  
text associated with that number.
"Guest" || "Regular User" || "Intl. User" || "Contractor" ||  
"Employee" || "Sales" || "Investor" || "Human Resources" ||  
"Administrator";


Karl


On Jan 25, 2010, at 1:31 PM, Olavi Ivask wrote:


Hi,

did you mean something like this?

$level_names = array("Guest", "Regular User", "Intl. User",  
"Contractor", "Employee",

"Sales", "Investor", "Human Resources", 
"Administrator");

$user_level = $level_names[$req_user_level];

Regards,
Olavi Ivask


On Jan 25, 2010, at 9:13 PM, Karl DeSaulniers wrote:


Hello List,
Trying to learn the right way to code this line.
Can anyone tell me if I am doing this the right way?

if $req_user_level == 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 ||  
9 ? "Guest" || "Regular User" || "Intl. User" || "Contractor" ||  
"Employee" || "Sales" || "Investor" || "Human Resources" ||  
"Administrator";


I am wanting to stray from the if(foo == bar) { routine. ;)

Thanks,

Karl DeSaulniers
Design Drumm
http://designdrumm.com





Karl DeSaulniers
Design Drumm
http://designdrumm.com



Re: [PHP-DB] Random pick

2010-01-25 Thread Peter Beckman

On Mon, 25 Jan 2010, Karl DeSaulniers wrote:


Hello List,
Trying to learn the right way to code this line.
Can anyone tell me if I am doing this the right way?

if $req_user_level == 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 ? 
"Guest" || "Regular User" || "Intl. User" || "Contractor" || "Employee" || 
"Sales" || "Investor" || "Human Resources" || "Administrator";


I am wanting to stray from the if(foo == bar) { routine. ;)


 if (in_array($req_user_level, array(0,1,2,3,4,5,6,7,8,9,"Guest",...))) {
 // do stuff
 }

---
Peter Beckman  Internet Guy
beck...@angryox.com http://www.angryox.com/
---

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Random pick

2010-01-25 Thread Olavi Ivask

Hi,

did you mean something like this?

$level_names = array("Guest", "Regular User", "Intl. User",  
"Contractor", "Employee",

"Sales", "Investor", "Human Resources", 
"Administrator");

$user_level = $level_names[$req_user_level];

Regards,
Olavi Ivask


On Jan 25, 2010, at 9:13 PM, Karl DeSaulniers wrote:


Hello List,
Trying to learn the right way to code this line.
Can anyone tell me if I am doing this the right way?

if $req_user_level == 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 ||  
9 ? "Guest" || "Regular User" || "Intl. User" || "Contractor" ||  
"Employee" || "Sales" || "Investor" || "Human Resources" ||  
"Administrator";


I am wanting to stray from the if(foo == bar) { routine. ;)

Thanks,

Karl DeSaulniers
Design Drumm
http://designdrumm.com




--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Random pick

2010-01-25 Thread Karl DeSaulniers

Hello List,
Trying to learn the right way to code this line.
Can anyone tell me if I am doing this the right way?

if $req_user_level == 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 ||  
9 ? "Guest" || "Regular User" || "Intl. User" || "Contractor" ||  
"Employee" || "Sales" || "Investor" || "Human Resources" ||  
"Administrator";


I am wanting to stray from the if(foo == bar) { routine. ;)

Thanks,

Karl DeSaulniers
Design Drumm
http://designdrumm.com



Re: [PHP-DB] Random pick

2009-12-21 Thread David McGlone
On Saturday 19 December 2009 03:54:34 Karl DeSaulniers wrote:
> Dont know if you found anything, but I ran accross this in on of my
> other searches.
> 
> http://php.about.com/od/finishedphp1/p/day_redirect.htm
> 
> Karl
> 
> On Dec 18, 2009, at 10:10 AM, Philip Thompson wrote:
> > On Dec 15, 2009, at 6:02 PM, David McGlone wrote:
> >> On Monday 14 December 2009 21:44:24 Chris wrote:
> >>> Chris wrote:
>  David McGlone wrote:
> > On Monday 14 December 2009 21:02:37 Chris wrote:
> >> David McGlone wrote:
> >>> Hi everyone,
> >>>
> >>> I've been lurking in the shadows on the list for quite some
> >>> time and
> >>> now
> >>> I'm in need of a little info or advise.

Thanks everyone. I tried everybody's suggestions and I learned a lot. Someone 
else also suggested using a cron job to run the rand script at certain 
intervals and insert the result into another table. This also works.

I probably could've used javascript, which was my initial reaction, but I'm 
trying to learn PHP/MYSQL and adding java to the mix, would only add to the 
confusion.

-- 
Blessings
David M.
I have been driven to my knees many times by the overwhelming conviction that 
I had nowhere else to go.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Random pick

2009-12-19 Thread Karl DeSaulniers
Dont know if you found anything, but I ran accross this in on of my  
other searches.


http://php.about.com/od/finishedphp1/p/day_redirect.htm

Karl


On Dec 18, 2009, at 10:10 AM, Philip Thompson wrote:


On Dec 15, 2009, at 6:02 PM, David McGlone wrote:


On Monday 14 December 2009 21:44:24 Chris wrote:

Chris wrote:

David McGlone wrote:

On Monday 14 December 2009 21:02:37 Chris wrote:

David McGlone wrote:

Hi everyone,

I've been lurking in the shadows on the list for quite some  
time and

now
I'm in need of a little info or advise.

I'm looking for a way to grab a record out of a database on a
certain day
each month and I'm wondering if this can be accomplished with  
just a

mysql query or would I need to use PHP also?


A mysql query would do it but you'd use something to talk to  
mysql and
process the results (whether it's php, perl, python, ruby etc  
depends

on your other requirements).


What I'm trying to do is to have a record picked from the  
database at
random on the 1st of every month and display it on the page.  
Here is

some code I have been working with:

$query = "SELECT DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)";
$result = @mysql_query($query);
if (!$result){

$query = "SELECT * FROM monthlyPooch ORDER BY RAND() LIMIT 1";
$result = @mysql_query($query);

while ($row = mysql_fetch_array($result)){
echo "$row[poochName] ";
echo "$row[Birthdate]";

}
}


You can check the day of the month in php then do your other query:

$today = date('j');


See http://php.net/date for date formats and what they return.


if ($today !== 1) {
 echo "Today isn't the first. No need to continue.\n";
 exit;
}
..
random query etc here.




Hmmm. This isn't exactly what I'm looking for. What I'm trying to  
do is get a
new picture on the 1st of every month and display it for that  
whole month.


Could you not just create a mysql table that contains the month and  
a url to a file?


$sql = "SELECT `image_location` FROM `monthly_images` WHERE `month`  
= $currentMonth LIMIT 1";

$result = mysql_query($sql);
list ($loc) = mysql_result ($result);

header ("Content-type: image/png");
readfile ($loc);
exit;
?>

And then in your HTML:



I just wrote that code here in the email, but it should get you  
going in the right direction. Hope that helps!


~Philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Karl DeSaulniers
Design Drumm
http://designdrumm.com



Re: [PHP-DB] Random pick

2009-12-18 Thread Philip Thompson
On Dec 15, 2009, at 6:02 PM, David McGlone wrote:

> On Monday 14 December 2009 21:44:24 Chris wrote:
>> Chris wrote:
>>> David McGlone wrote:
 On Monday 14 December 2009 21:02:37 Chris wrote:
> David McGlone wrote:
>> Hi everyone,
>> 
>> I've been lurking in the shadows on the list for quite some time and
>> now
>> I'm in need of a little info or advise.
>> 
>> I'm looking for a way to grab a record out of a database on a
>> certain day
>> each month and I'm wondering if this can be accomplished with just a
>> mysql query or would I need to use PHP also?
> 
> A mysql query would do it but you'd use something to talk to mysql and
> process the results (whether it's php, perl, python, ruby etc depends
> on your other requirements).
 
 What I'm trying to do is to have a record picked from the database at
 random on the 1st of every month and display it on the page. Here is
 some code I have been working with:
 
 $query = "SELECT DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)";
 $result = @mysql_query($query);
 if (!$result){
 
 $query = "SELECT * FROM monthlyPooch ORDER BY RAND() LIMIT 1";
 $result = @mysql_query($query);
 
 while ($row = mysql_fetch_array($result)){
 echo "$row[poochName] ";
 echo "$row[Birthdate]";
 
 }
 }
>>> 
>>> You can check the day of the month in php then do your other query:
>>> 
>>> $today = date('j');
>> 
>> See http://php.net/date for date formats and what they return.
>> 
>>> if ($today !== 1) {
>>>  echo "Today isn't the first. No need to continue.\n";
>>>  exit;
>>> }
>>> ..
>>> random query etc here.
>> 
> 
> Hmmm. This isn't exactly what I'm looking for. What I'm trying to do is get a 
> new picture on the 1st of every month and display it for that whole month.

Could you not just create a mysql table that contains the month and a url to a 
file?



And then in your HTML:



I just wrote that code here in the email, but it should get you going in the 
right direction. Hope that helps!

~Philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Random pick

2009-12-15 Thread David McGlone
On Monday 14 December 2009 21:44:24 Chris wrote:
> Chris wrote:
> > David McGlone wrote:
> >> On Monday 14 December 2009 21:02:37 Chris wrote:
> >>> David McGlone wrote:
>  Hi everyone,
> 
>  I've been lurking in the shadows on the list for quite some time and
>  now
>  I'm in need of a little info or advise.
> 
>  I'm looking for a way to grab a record out of a database on a
>  certain day
>  each month and I'm wondering if this can be accomplished with just a
>  mysql query or would I need to use PHP also?
> >>>
> >>> A mysql query would do it but you'd use something to talk to mysql and
> >>> process the results (whether it's php, perl, python, ruby etc depends
> >>> on your other requirements).
> >>
> >> What I'm trying to do is to have a record picked from the database at
> >> random on the 1st of every month and display it on the page. Here is
> >> some code I have been working with:
> >>
> >> $query = "SELECT DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)";
> >> $result = @mysql_query($query);
> >> if (!$result){
> >>
> >> $query = "SELECT * FROM monthlyPooch ORDER BY RAND() LIMIT 1";
> >> $result = @mysql_query($query);
> >>
> >> while ($row = mysql_fetch_array($result)){
> >> echo "$row[poochName] ";
> >> echo "$row[Birthdate]";
> >>
> >> }
> >> }
> >
> > You can check the day of the month in php then do your other query:
> >
> > $today = date('j');
> 
> See http://php.net/date for date formats and what they return.
> 
> > if ($today !== 1) {
> >   echo "Today isn't the first. No need to continue.\n";
> >   exit;
> > }
> > ..
> > random query etc here.
> 

Hmmm. This isn't exactly what I'm looking for. What I'm trying to do is get a 
new picture on the 1st of every month and display it for that whole month.

-- 
Blessings
David M.
I have been driven to my knees many times by the overwhelming conviction that 
I had nowhere else to go.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Random pick

2009-12-14 Thread Chris

Chris wrote:

David McGlone wrote:

On Monday 14 December 2009 21:02:37 Chris wrote:

David McGlone wrote:

Hi everyone,

I've been lurking in the shadows on the list for quite some time and 
now

I'm in need of a little info or advise.

I'm looking for a way to grab a record out of a database on a 
certain day

each month and I'm wondering if this can be accomplished with just a
mysql query or would I need to use PHP also?

A mysql query would do it but you'd use something to talk to mysql and
process the results (whether it's php, perl, python, ruby etc depends on
your other requirements).



What I'm trying to do is to have a record picked from the database at 
random on the 1st of every month and display it on the page. Here is 
some code I have been working with:


$query = "SELECT DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)";
$result = @mysql_query($query);
if (!$result){

$query = "SELECT * FROM monthlyPooch ORDER BY RAND() LIMIT 1";
$result = @mysql_query($query);

while ($row = mysql_fetch_array($result)){
echo "$row[poochName] ";
echo "$row[Birthdate]";

}
}


You can check the day of the month in php then do your other query:

$today = date('j');


See http://php.net/date for date formats and what they return.


if ($today !== 1) {
  echo "Today isn't the first. No need to continue.\n";
  exit;
}
..
random query etc here.




--
Postgresql & php tutorials
http://www.designmagick.com/


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Random pick

2009-12-14 Thread Chris

David McGlone wrote:

On Monday 14 December 2009 21:02:37 Chris wrote:

David McGlone wrote:

Hi everyone,

I've been lurking in the shadows on the list for quite some time and now
I'm in need of a little info or advise.

I'm looking for a way to grab a record out of a database on a certain day
each month and I'm wondering if this can be accomplished with just a
mysql query or would I need to use PHP also?

A mysql query would do it but you'd use something to talk to mysql and
process the results (whether it's php, perl, python, ruby etc depends on
your other requirements).



What I'm trying to do is to have a record picked from the database at random 
on the 1st of every month and display it on the page. Here is some code I have 
been working with:


$query = "SELECT DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)";
$result = @mysql_query($query);
if (!$result){

$query = "SELECT * FROM monthlyPooch ORDER BY RAND() LIMIT 1";
$result = @mysql_query($query);

while ($row = mysql_fetch_array($result)){
echo "$row[poochName] ";
echo "$row[Birthdate]";

}
}


You can check the day of the month in php then do your other query:

$today = date('j');

if ($today !== 1) {
  echo "Today isn't the first. No need to continue.\n";
  exit;
}
..
random query etc here.

--
Postgresql & php tutorials
http://www.designmagick.com/


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Random pick

2009-12-14 Thread David McGlone
On Monday 14 December 2009 21:02:37 Chris wrote:
> David McGlone wrote:
> > Hi everyone,
> >
> > I've been lurking in the shadows on the list for quite some time and now
> > I'm in need of a little info or advise.
> >
> > I'm looking for a way to grab a record out of a database on a certain day
> > each month and I'm wondering if this can be accomplished with just a
> > mysql query or would I need to use PHP also?
> 
> A mysql query would do it but you'd use something to talk to mysql and
> process the results (whether it's php, perl, python, ruby etc depends on
> your other requirements).
> 

What I'm trying to do is to have a record picked from the database at random 
on the 1st of every month and display it on the page. Here is some code I have 
been working with:

$query = "SELECT DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)";
$result = @mysql_query($query);
if (!$result){

$query = "SELECT * FROM monthlyPooch ORDER BY RAND() LIMIT 1";
$result = @mysql_query($query);

while ($row = mysql_fetch_array($result)){
echo "$row[poochName] ";
echo "$row[Birthdate]";

}
}

I suspect this code isn't going to work, because I think on the 1st day of the 
month it's going to choke.

What do you think?

-- 
Blessings
David M.
I have been driven to my knees many times by the overwhelming conviction that 
I had nowhere else to go.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Random pick

2009-12-14 Thread Chris

David McGlone wrote:

Hi everyone,

I've been lurking in the shadows on the list for quite some time and now I'm 
in need of a little info or advise.


I'm looking for a way to grab a record out of a database on a certain day each 
month and I'm wondering if this can be accomplished with just a mysql query or 
would I need to use PHP also?


A mysql query would do it but you'd use something to talk to mysql and 
process the results (whether it's php, perl, python, ruby etc depends on 
your other requirements).


--
Postgresql & php tutorials
http://www.designmagick.com/


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Random pick

2009-12-14 Thread David McGlone
Hi everyone,

I've been lurking in the shadows on the list for quite some time and now I'm 
in need of a little info or advise.

I'm looking for a way to grab a record out of a database on a certain day each 
month and I'm wondering if this can be accomplished with just a mysql query or 
would I need to use PHP also?

My hunch is mixing the two, but I'm not very prolific with mysql at this point 
so I thought It would be better to ask before I go and get myself all mixed 
up.

Any suggestions?

-- 
Blessings
David M.
I have been driven to my knees many times by the overwhelming conviction that 
I had nowhere else to go.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] Random content from MySql DB

2008-08-26 Thread Simcha

If the past questions are 1,2,3,4:

Select * from `questions` where id not in (1,2,3,4) order by RAND();



Simcha Younger

-Original Message-
From: A. Joseph [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, August 26, 2008 7:38 PM
To: php-db@lists.php.net
Subject: [PHP-DB] Random content from MySql DB

I`m creating a small application that let users take test online, the
user will login and visit the test page, questions and answers are
stored in MySql database,

i want to display each randomly without repeating.

test must to completed between some specific amount of time or else
the application will forcefully submit the form and calculated the
completed ones (Eac question come up at a time and you choose the
answer and submit, then another come show up again, just like that),

I have plan of saving user`s progress and user may continue next time
if he/she has not spent the total test time.

I need your help on how to random the questions without repeating any
and if a user may need to continue from he/her past, the random should
also exclude the past questions stored inside the user progress table.

What is your best advice, i want to start creating the mysql table soon.

Thank you

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

No virus found in this incoming message.
Checked by AVG - http://www.avg.com 
Version: 8.0.138 / Virus Database: 270.6.7/1632 - Release Date: 25/08/2008
07:05


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Random content from MySql DB

2008-08-26 Thread A. Joseph
I`m creating a small application that let users take test online, the
user will login and visit the test page, questions and answers are
stored in MySql database,

i want to display each randomly without repeating.

test must to completed between some specific amount of time or else
the application will forcefully submit the form and calculated the
completed ones (Eac question come up at a time and you choose the
answer and submit, then another come show up again, just like that),

I have plan of saving user`s progress and user may continue next time
if he/she has not spent the total test time.

I need your help on how to random the questions without repeating any
and if a user may need to continue from he/her past, the random should
also exclude the past questions stored inside the user progress table.

What is your best advice, i want to start creating the mysql table soon.

Thank you

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] random 'card number' generator

2006-11-24 Thread Jeffrey

D.

Go to the manual at http://be2.php.net/manual/en/function.rand.php and 
look at the User contributed notes further down the page. You'll find a 
couple of solutions.


Whatever you do, you will presumably need to check the generated number 
against the db to see if it is already in use and, if not, generate a 
new random number.


Good luck,

Jeffrey

Desmond Coughlan wrote:

X-No-Archive: true

Hello,
I'm learning PhP and trying to write a library catalogue system, that uses a PostgreSQL back-end.  My db looks like this ... 


http://www.chez.com/desmondcoughlan/unix/bibliotheque.sql

I had originally planned to have a username in place of 'card_number', but 
realised that there was no point.  What I need now is the PhP code that will 
create a card number, and rather than having a sequence, I want a random 
three-digit number.  Can someone point me in the direction of where and how PhP 
can do this?

Thanks.

D.


-
 Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! 
Profitez des connaissances, des opinions et des expériences des internautes sur 
Yahoo! Questions/Réponses.


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] random 'card number' generator

2006-11-24 Thread Desmond Coughlan
X-No-Archive: true

Hello,
I'm learning PhP and trying to write a library catalogue system, that uses a 
PostgreSQL back-end.  My db looks like this ... 

http://www.chez.com/desmondcoughlan/unix/bibliotheque.sql

I had originally planned to have a username in place of 'card_number', but 
realised that there was no point.  What I need now is the PhP code that will 
create a card number, and rather than having a sequence, I want a random 
three-digit number.  Can someone point me in the direction of where and how PhP 
can do this?

Thanks.

D.


-
 Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! 
Profitez des connaissances, des opinions et des expériences des internautes sur 
Yahoo! Questions/Réponses.

Re: [PHP-DB] Random Password problem

2005-03-08 Thread Jochem Maas
J. Connolly wrote:
I am using this php in order to create, store and send random passwords 
to people who want to join my mailing list.

your seeding the randomizer with the value zero each time!
the expression:
(integer) md5(microtime())
is (almost) always going to equal zero (unless it
happens to start with one or more numeric chars).
basically get rid of the code that seeds the randomizer,
unless your using a really old version of php, because
you don't need to seed the randomizer at all.
if you remove the line:
mt_srand($seed);
your passwords will drastically increase in 'randomness'
$password = mt_rand(1,);
$password = substr(md5($password), 3,9);
return $password;
}
?>

I seem to be getting the same number very often which makes me fear that 
"fear causes hesitation, hestitation causes your worse fears to come 
true."
 (yadda yadda, that film is sooo pre-Matrix ;-)
this is not so random. I am a noob so I do not know if this is 
coincidence or a fault in my coding.
Right now, I have been setting up passwords manually, but would like 
users to be as free from me as possible. Any direction would be helpful.

BTW, I keep getting the following number an absurd amount of times. I 
have deleted cookies and even gone to other machines, and yet it still 
generates this number.

8f31a3
Thank you,
jozef
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP-DB] Random Password problem

2005-03-08 Thread Bastien Koert
and my version
function change_password($id, $password)
{
	//generate a random password
	$pass = "";
	$salt = "abchefghjkmnpqrstuvwxyz0123456789";
	srand((double)microtime()*100);
			$i = 0;
			while ($i <= 7) {
		$num = rand() % 33;
		$tmp = substr($salt, $num, 1);
		$pass = $pass . $tmp;
		$i++;
			}
	//change the password in the db
	$sql = "update cust_info set cust_pw	='".md5($pass)."', temp_pass = 1 where 
cust_lg = '$id' and cust_pw = '$password'";
	$result = connect($sql);
	if ($result){
		return $pass;
	}else{
		change_password($id, $password);
	}

bastien
From: "Wendell Frohwein" <[EMAIL PROTECTED]>
To: "'J. Connolly'" <[EMAIL PROTECTED]>,"'PHP list'" 
Subject: RE: [PHP-DB] Random Password problem
Date: Tue, 8 Mar 2005 11:51:59 -0800
This is one I like to use jozef.
function generate_password($length = 10) {
  $allowable_characters = "abcdefghjkmnopqrstuvwxyz23456789";
  $ps_len = strlen($allowable_characters);
  mt_srand((double)microtime()*100);
  $pass = "";
  for($i = 0; $i < $length; $i++) {
   $pass .= $allowable_characters[mt_rand(0,$ps_len-1)];
  }
return $pass;
}
Its been working well for me for sometime.

-Wendell Frohwein
-Original Message-
From: J. Connolly [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 08, 2005 11:41 AM
To: PHP list
Subject: [PHP-DB] Random Password problem
I am using this php in order to create, store and send random passwords
to people who want to join my mailing list.


I seem to be getting the same number very often which makes me fear that
this is not so random. I am a noob so I do not know if this is
coincidence or a fault in my coding.
Right now, I have been setting up passwords manually, but would like
users to be as free from me as possible. Any direction would be helpful.
BTW, I keep getting the following number an absurd amount of times. I
have deleted cookies and even gone to other machines, and yet it still
generates this number.
8f31a3
Thank you,
jozef
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP-DB] Random Password problem

2005-03-08 Thread Wendell Frohwein
This is one I like to use jozef.

function generate_password($length = 10) {
  $allowable_characters = "abcdefghjkmnopqrstuvwxyz23456789";
  $ps_len = strlen($allowable_characters);
  mt_srand((double)microtime()*100);
  $pass = "";
  for($i = 0; $i < $length; $i++) {
   $pass .= $allowable_characters[mt_rand(0,$ps_len-1)];
  }
return $pass;
}


Its been working well for me for sometime.



-Wendell Frohwein

-Original Message-
From: J. Connolly [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, March 08, 2005 11:41 AM
To: PHP list
Subject: [PHP-DB] Random Password problem

I am using this php in order to create, store and send random passwords 
to people who want to join my mailing list.





I seem to be getting the same number very often which makes me fear that

this is not so random. I am a noob so I do not know if this is 
coincidence or a fault in my coding.
Right now, I have been setting up passwords manually, but would like 
users to be as free from me as possible. Any direction would be helpful.

BTW, I keep getting the following number an absurd amount of times. I 
have deleted cookies and even gone to other machines, and yet it still 
generates this number.

8f31a3

Thank you,
jozef

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Random Password problem

2005-03-08 Thread Stephen Johnson
I know that true randomness only exists in nature.  However, the
randomization in PHP is fairly good. I have only used it on fairly small
scales (i.e. Randomizing 200 quotes to give a random quote when people log
onto a page.) 

For passwords I have always gone an easier route.

$password = time();

This will produce an impossible to guess string of numbers I think about 9
or 10 characters in length.

I am sure others here will have better options.  But this has worked well
for me and is very very easy.



http://www.thelonecoder.com
[EMAIL PROTECTED]

562.924.4454 (office)
562.924.4075 (fax) 

continuing the struggle against bad code

*/ 
?>

> From: "J. Connolly" <[EMAIL PROTECTED]>
> Date: Tue, 08 Mar 2005 14:41:11 -0500
> To: PHP list 
> Subject: [PHP-DB] Random Password problem
> 
> I am using this php in order to create, store and send random passwords
> to people who want to join my mailing list.
> 
>  function random_password () {
> $seed = (integer) md5(microtime());
> mt_srand($seed);
> $password = mt_rand(1,);
> $password = substr(md5($password), 3,9);
> return $password;
> }
> ?>
> 
>  $msg = random_password();
> echo $msg;
> ?>
> 
> I seem to be getting the same number very often which makes me fear that
> this is not so random. I am a noob so I do not know if this is
> coincidence or a fault in my coding.
> Right now, I have been setting up passwords manually, but would like
> users to be as free from me as possible. Any direction would be helpful.
> 
> BTW, I keep getting the following number an absurd amount of times. I
> have deleted cookies and even gone to other machines, and yet it still
> generates this number.
> 
> 8f31a3
> 
> Thank you,
> jozef
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Random Password problem

2005-03-08 Thread J. Connolly
I am using this php in order to create, store and send random passwords 
to people who want to join my mailing list.



I seem to be getting the same number very often which makes me fear that 
this is not so random. I am a noob so I do not know if this is 
coincidence or a fault in my coding.
Right now, I have been setting up passwords manually, but would like 
users to be as free from me as possible. Any direction would be helpful.

BTW, I keep getting the following number an absurd amount of times. I 
have deleted cookies and even gone to other machines, and yet it still 
generates this number.

8f31a3
Thank you,
jozef
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP-DB] Random Character String

2005-03-05 Thread Bastien Koert
i use this function to generate a random 7 letter password...simple change 
to make it 8
function change_password($id, $password)
{
	//generate a random password
	$pass = "";
	$salt = "abchefghjkmnpqrstuvwxyz0123456789";
	srand((double)microtime()*100);
			$i = 0;
			while ($i <= 7) {
		$num = rand() % 33;
		$tmp = substr($salt, $num, 1);
		$pass = $pass . $tmp;
		$i++;
			}
	//change the password in the db
	$sql = "update cust_info set cust_pw	='".md5($pass)."', temp_pass = 1 where 
cust_lg = '$id' and cust_pw = '$password'";
	$result = connect($sql);
	if ($result){
		return $pass;
	}else{
		change_password($id, $password);
	}
}//end function

SQL is case insensitive for most queries. but you can use UPPER or LOWER to 
force case to one or the other if you feel its a problem

for the html tag
http://www.robotstxt.org/wc/meta-user.html
bastien

From: "Ron Piggott" <[EMAIL PROTECTED]>
To: "PHP DB" 
Subject: [PHP-DB] Random Character String
Date: Sat, 5 Mar 2005 09:38:35 -0500
Is there a way of generating an 8 character random string in PHP?
Is there a way to ignore UPPER and lower case when you are using the SELECT
command to find a record in the mySQL table?
I know this isn't an HTML forum ... I have one more question which is more
HTML in nature.  I don't want some of the web pages to be indexed that my
PHP scripts are creating.  Is there a tag you know of to prevent this from
happening?
Ron
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Random Character String

2005-03-05 Thread Ron Piggott
The robots that index the web.

Bastien gave me a web site to use for this.

Thanks.

Ron
- Original Message -
From: Zareef Ahmed <[EMAIL PROTECTED]>
To: Ron Piggott <[EMAIL PROTECTED]>
Cc: PHP DB 
Sent: Saturday, March 05, 2005 11:56 AM
Subject: Re: [PHP-DB] Random Character String


> Hi,
> Look at uniqueid function,
> but it gives some lengthy string. You can use string functiions for
> your specific purpose.
> http://in.php.net/uniqueid
>
> On Sat, 5 Mar 2005 09:38:35 -0500, Ron Piggott
> <[EMAIL PROTECTED]> wrote:
> > Is there a way of generating an 8 character random string in PHP?
> >
> > Is there a way to ignore UPPER and lower case when you are using the
SELECT
> > command to find a record in the mySQL table?
> >
> > I know this isn't an HTML forum ... I have one more question which is
more
> > HTML in nature.  I don't want some of the web pages to be indexed that
my
> > PHP scripts are creating.  Is there a tag you know of to prevent this
from
> > happening?
>
> what do you mean by indexed here? indexed by whom? search engines?
>
> zareef ahmed
>
> >
> > Ron
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>
> --
> Zareef Ahmed :: A PHP Developer in India ( Delhi )
> Homepage :: http://www.zareef.net
>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Random Character String

2005-03-05 Thread Zareef Ahmed
Hi, 
Look at uniqueid function, 
but it gives some lengthy string. You can use string functiions for
your specific purpose.
http://in.php.net/uniqueid

On Sat, 5 Mar 2005 09:38:35 -0500, Ron Piggott
<[EMAIL PROTECTED]> wrote:
> Is there a way of generating an 8 character random string in PHP?
> 
> Is there a way to ignore UPPER and lower case when you are using the SELECT
> command to find a record in the mySQL table?
> 
> I know this isn't an HTML forum ... I have one more question which is more
> HTML in nature.  I don't want some of the web pages to be indexed that my
> PHP scripts are creating.  Is there a tag you know of to prevent this from
> happening?

what do you mean by indexed here? indexed by whom? search engines?

zareef ahmed

> 
> Ron
> 
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 


-- 
Zareef Ahmed :: A PHP Developer in India ( Delhi )
Homepage :: http://www.zareef.net

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Random Character String

2005-03-05 Thread Ron Piggott
Is there a way of generating an 8 character random string in PHP?

Is there a way to ignore UPPER and lower case when you are using the SELECT
command to find a record in the mySQL table?

I know this isn't an HTML forum ... I have one more question which is more
HTML in nature.  I don't want some of the web pages to be indexed that my
PHP scripts are creating.  Is there a tag you know of to prevent this from
happening?

Ron

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Random Number generating and adding it to he database..

2005-01-23 Thread Samar
On Sun, 23 Jan 2005 10:43:03 +0400, Radwan Aladdin
<[EMAIL PROTECTED]> wrote:

> I wanted to know the best Random Function for PHP.. But please I don't want 
> >duplications to happen at the same second.. because I receive many 
> customers..
 
For that purpose, mt_rand ( [int min, int max]) function is your best
friend, I guess.
See http://in2.php.net/manual/en/function.mt-rand.php for more details.

> And also how can I add [EMAIL PROTECTED], whic "abc" is a variable... and 
> >"localhost.com" is a static text??
> So I only request from the user to enter the "abc" only and it will 
> automatically >be : [EMAIL PROTECTED]

//Do you mean --
$user = "someuser"; 
echo $user; 
//And you wish to make [EMAIL PROTECTED] ?
//Then,
$email_address = $user . "@localhost.com"; 
echo $email_address;
//Will output [EMAIL PROTECTED]

The dot (.) is the cocatenation (string-joining) operator.

Regards,
Samar M. 

= Warning: Dates in Calendar are closer than they appear.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DB] Random Number generating and adding it to he database..

2005-01-22 Thread Radwan Aladdin
Hi all!

I wanted to know the best Random Function for PHP.. But please I don't want 
duplications to happen at the same second.. because I receive many customers..

And also how can I add [EMAIL PROTECTED], whic "abc" is a variable... and 
"localhost.com" is a static text??
So I only request from the user to enter the "abc" only and it will 
automatically be : [EMAIL PROTECTED]


Thanks!
Radwan Aladdin


Re: [PHP-DB] Random select -- Where am I going wrong?

2004-07-05 Thread Alvaro Zuniga
See Below

On Sun, 2004-07-04 at 05:54, Ronald "The Newbie" Allen wrote:
> Here is my code I keep on getting a Resource id #2 ..whatever that
> meansany help would be appreciated!
> 
> 
> 
> 
> 
> Top Frame
> 
> 
> 
>  alink="#ff">
> 
>  
> $db_host  = '##;
> $db_user  = '##';
> $db_pass  = '##';
> $db_name  = '##';
> 
> $conn = mysql_connect($db_host,$db_user,$db_pass);
> 
> if ($conn == true) {
> 
> 
> // Select the database.
>   mysql_select_db($db_name,$conn);
> 
> 
> $db_table = 'music';
> $music = mysql_query ("Select * from $db_table ORDER BY RAND() Limit 1");
> 
> if(!$music) die("Query Failed.");
> 
> while($row = mysql_fetch_row($music))
> 
> print "$music";


you need something like print $row

however, that still will not work.

print_r( $row ) will give you all the values.

print( $row->the_table_name would yield each value.

NOTE: the syntax above is for a call to $row = mysql_fetch_object(
$music )

lookup the correct syntax for mysql_fetch_row( $table ). You might want
to check mysql_fetch_assoc and mysql_fetch_array to have even more fun!

If you really wish to know more check out mysql_result( ) quite useful
when you only seek a couple values from the resultset.

hope that helps

Alvaro Zuniga
(337) 654 6515
www.zunitek.com
Zunitek Solutions







> }
> ?>
> 
> 
> 
> 
> 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Random select -- Where am I going wrong?

2004-07-04 Thread Larry E . Ullman
Here is my code I keep on getting a Resource id #2 ..whatever 
that
meansany help would be appreciated!


$music = mysql_query ("Select * from $db_table ORDER BY RAND() Limit 
1");
if(!$music) die("Query Failed.");
while($row = mysql_fetch_row($music))
print "$music";
}
This is because you're printing $music--which is the resource ID--when 
you should be working with $row. Also, you're going to need to actually 
print $row[0] or $row['column'], not just $row.

Larry
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DB] Random select -- Where am I going wrong?

2004-07-04 Thread Ronald \"The Newbie\" Allen
Here is my code I keep on getting a Resource id #2 ..whatever that
meansany help would be appreciated!





Top Frame












-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Random not working?

2003-03-01 Thread Doug Thompson
This recent thread from the mysql list explains a lot about the
problem.
http://lists.mysql.com/cgi-ez/ezmlm-cgi?1:mss:15034


hth,
Doug

On Sat, 1 Mar 2003 12:24:57 +0100, Frank Keessen wrote:

>Hi All,
>
>I'm trying to get a random record each time this script runs; Only it's giving me 
>everytime the first record back.. No random at all..
>
>// generate and execute query
>$query = "SELECT stedenid, naamstad, stadomschrijvk FROM steden ORDER BY RAND() LIMIT 
>1";
>$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
>$row = mysql_fetch_object($result);
>echo $row->naamstad;
>
>
>Version info;
>
>PHP 4.3.1
>Mysql 3.23.54 
>
>When i'm trying to excute the SELECT statement in phpmyadmin; i'm only getting the 
>first record back and when i'm taking off the LIMIT 1 it will display all the records 
>in ascending order so also not in random..
>
>
>Regards,
>
>Frank
>
>
>
>
>
>



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Random not working?

2003-03-01 Thread Frank Keessen
Hi All,

I'm trying to get a random record each time this script runs; Only it's giving me 
everytime the first record back.. No random at all..

// generate and execute query
$query = "SELECT stedenid, naamstad, stadomschrijvk FROM steden ORDER BY RAND() LIMIT 
1";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
$row = mysql_fetch_object($result);
echo $row->naamstad;


Version info;

PHP 4.3.1
Mysql 3.23.54 

When i'm trying to excute the SELECT statement in phpmyadmin; i'm only getting the 
first record back and when i'm taking off the LIMIT 1 it will display all the records 
in ascending order so also not in random..


Regards,

Frank







RE: [PHP-DB] random rows...what about tables

2002-12-18 Thread Matthew Moldvan
to get all the table names, then return a random table name, try the
following:



dont forget, when you use a mysql_query(), it returns a result set with more
than one value for each row returned. ie, $array[$i] could be anything from
the table name to its size to its whatever ...

Regards,
Matthew Moldvan

---
 System Administrator
 Trilogy International, Inc
 http://www.trilogyintl.com/ecommerce/
---

-Original Message-
From: Hutchins, Richard [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, December 17, 2002 9:26 AM
To: 'Bruce Levick'; [EMAIL PROTECTED]
Subject: RE: [PHP-DB] random rows...what about tables


I think it's because mysql_list_tables returns a resource identifier
($result). You have to iterate through the resource identifier ($result)
with a while() loop to get the actual table names out. From the PHP.NET
site:



In the example above, I think the output would just be one table name.
However, you're going to have (and want) a list of multiple table names, if
I understand your problem correctly. In which case you'd have to put the
table names in an array called $tablenames so your array_rand($tablenames)
will work.

Haven't tested this out or done this specifically before, so I hope this
helps.
> -Original Message-
> From: Bruce Levick [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, December 17, 2002 9:19 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP-DB] random rows...what about tables
> 
> 
> Sorry,
> Have updated my script with a little help. Upon output i am 
> recieving this.
> 
> Warning: Argument to array_rand() has to be an array in
> C:\WORKING\portfolio\vivamotion\site\php\request.php on line 51
> 
> this is the code below.
> //
> //
> /
> 
>  //listing table in database
> $alltables = mysql_list_tables("portfolio");
> 
> //random array
>  $randomtable = array_rand($alltables);
> 
>  $all = mysql_query("SELECT * FROM Illustrations");
>  $totalRows_Recordset1 = mysql_num_rows($all);
>  $rndm = mysql_query("SELECT * FROM Illustrations ORDER BY 
> RAND() LIMIT
> 4,$totalRows_Recordset1");
>  if (!$rndm) {
>   echo("Error performing query: " .
>mysql_error() . "");
>   exit();
> }
> 
>  $randrow = mysql_fetch_array($rndm);
>  ?>
> 
> //output to browser
>  print "$randomtable\n";
> ?>
> 
> 
> Hope that helps
> 
> 
> 
> 
> - Original Message -
> From: "Jason Wong" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Tuesday, December 17, 2002 11:48 PM
> Subject: Re: [PHP-DB] random rows...what about tables
> 
> 
> > On Tuesday 17 December 2002 21:38, Bruce Levick wrote:
> > > Bruce Levick - Vivamotion
> > > Been searching for an answer to selecting a random table 
> and then a
> random
> > > row within the selected table.
> > >
> > > I have this code which successfully selects a random row 
> within a hard
> > > coded table. But just can't get the random table working.
> >
> > [snip]
> >
> > > Anybody see the solution??
> >
> > First we need to know _what_ the problem is. I think we can 
> assume your
> code
> > doesn't work the way you expected. Can you tell us _how_ it 
> doesn't work?
> > Error messages?
> >
> > --
> > Jason Wong -> Gremlins Associates -> www.gremlins.biz
> > Open Source Software Systems Integrators
> > * Web Design & Hosting * Internet & Intranet Applications 
> Development *
> >
> >
> > /*
> > We place two copies of PEOPLE magazine in a DARK, HUMID mobile home.
> > 45 minutes later CYNDI LAUPER emerges wearing a BIRD CAGE 
> on her head!
> > */
> >
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] random rows...what about tables

2002-12-17 Thread Jason Wong
On Tuesday 17 December 2002 22:18, Bruce Levick wrote:
> Sorry,
> Have updated my script with a little help. Upon output i am recieving this.
>
> Warning: Argument to array_rand() has to be an array in
> C:\WORKING\portfolio\vivamotion\site\php\request.php on line 51
>

OK, start from the basics. There's an example in the manual which shows you 
how to use mysql_list_tables(). Get that working, _then_ adapt it to return 
random tables.

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *


/*
QOTD:
"I sprinkled some baking powder over a couple of potatoes, but it
didn't work."
*/


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] random rows...what about tables

2002-12-17 Thread Hutchins, Richard
I think it's because mysql_list_tables returns a resource identifier
($result). You have to iterate through the resource identifier ($result)
with a while() loop to get the actual table names out. From the PHP.NET
site:



In the example above, I think the output would just be one table name.
However, you're going to have (and want) a list of multiple table names, if
I understand your problem correctly. In which case you'd have to put the
table names in an array called $tablenames so your array_rand($tablenames)
will work.

Haven't tested this out or done this specifically before, so I hope this
helps.
> -Original Message-
> From: Bruce Levick [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, December 17, 2002 9:19 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP-DB] random rows...what about tables
> 
> 
> Sorry,
> Have updated my script with a little help. Upon output i am 
> recieving this.
> 
> Warning: Argument to array_rand() has to be an array in
> C:\WORKING\portfolio\vivamotion\site\php\request.php on line 51
> 
> this is the code below.
> //
> //
> /
> 
>  //listing table in database
> $alltables = mysql_list_tables("portfolio");
> 
> //random array
>  $randomtable = array_rand($alltables);
> 
>  $all = mysql_query("SELECT * FROM Illustrations");
>  $totalRows_Recordset1 = mysql_num_rows($all);
>  $rndm = mysql_query("SELECT * FROM Illustrations ORDER BY 
> RAND() LIMIT
> 4,$totalRows_Recordset1");
>  if (!$rndm) {
>   echo("Error performing query: " .
>mysql_error() . "");
>   exit();
> }
> 
>  $randrow = mysql_fetch_array($rndm);
>  ?>
> 
> //output to browser
>  print "$randomtable\n";
> ?>
> 
> 
> Hope that helps
> 
> 
> 
> 
> - Original Message -
> From: "Jason Wong" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Tuesday, December 17, 2002 11:48 PM
> Subject: Re: [PHP-DB] random rows...what about tables
> 
> 
> > On Tuesday 17 December 2002 21:38, Bruce Levick wrote:
> > > Bruce Levick - Vivamotion
> > > Been searching for an answer to selecting a random table 
> and then a
> random
> > > row within the selected table.
> > >
> > > I have this code which successfully selects a random row 
> within a hard
> > > coded table. But just can't get the random table working.
> >
> > [snip]
> >
> > > Anybody see the solution??
> >
> > First we need to know _what_ the problem is. I think we can 
> assume your
> code
> > doesn't work the way you expected. Can you tell us _how_ it 
> doesn't work?
> > Error messages?
> >
> > --
> > Jason Wong -> Gremlins Associates -> www.gremlins.biz
> > Open Source Software Systems Integrators
> > * Web Design & Hosting * Internet & Intranet Applications 
> Development *
> >
> >
> > /*
> > We place two copies of PEOPLE magazine in a DARK, HUMID mobile home.
> > 45 minutes later CYNDI LAUPER emerges wearing a BIRD CAGE 
> on her head!
> > */
> >
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] random rows...what about tables

2002-12-17 Thread Bruce Levick
Sorry,
Have updated my script with a little help. Upon output i am recieving this.

Warning: Argument to array_rand() has to be an array in
C:\WORKING\portfolio\vivamotion\site\php\request.php on line 51

this is the code below.

/

Error performing query: " .
   mysql_error() . "");
  exit();
}

 $randrow = mysql_fetch_array($rndm);
 ?>

//output to browser



Hope that helps




- Original Message -
From: "Jason Wong" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, December 17, 2002 11:48 PM
Subject: Re: [PHP-DB] random rows...what about tables


> On Tuesday 17 December 2002 21:38, Bruce Levick wrote:
> > Bruce Levick - Vivamotion
> > Been searching for an answer to selecting a random table and then a
random
> > row within the selected table.
> >
> > I have this code which successfully selects a random row within a hard
> > coded table. But just can't get the random table working.
>
> [snip]
>
> > Anybody see the solution??
>
> First we need to know _what_ the problem is. I think we can assume your
code
> doesn't work the way you expected. Can you tell us _how_ it doesn't work?
> Error messages?
>
> --
> Jason Wong -> Gremlins Associates -> www.gremlins.biz
> Open Source Software Systems Integrators
> * Web Design & Hosting * Internet & Intranet Applications Development *
>
>
> /*
> We place two copies of PEOPLE magazine in a DARK, HUMID mobile home.
> 45 minutes later CYNDI LAUPER emerges wearing a BIRD CAGE on her head!
> */
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] random rows...what about tables

2002-12-17 Thread Wico de Leeuw
At 23:38 17-12-02 +1000, Bruce Levick wrote:

Bruce Levick - Vivamotion
Been searching for an answer to selecting a random table and then a random
row within the selected table.

I have this code which successfully selects a random row within a hard coded
table. But just can't get the random table working.



 $randomtabel = array_rand($alltables);




// this selects everything from the Illustrations table. I need to make the
FROM table_name a random selection
 $all = mysql_query("SELECT * FROM Illustrations");

//acquires total rows
 $totalRows_Recordset1 = mysql_num_rows($all);

// selects random row from total rows
$rndm = mysql_query("SELECT * FROM Illustrations ORDER BY RAND() LIMIT
4,$totalRows_Recordset1");
 if (!$rndm) {
  echo("Error performing query: " .
   mysql_error() . "");
  exit();
}

 $randrow = mysql_fetch_array($rndm);
 ?>

Anybody see the solution??

Winxp Pro, php 4.2.2 Mysql 3.2

Cheers


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] random rows...what about tables

2002-12-17 Thread Jason Wong
On Tuesday 17 December 2002 21:38, Bruce Levick wrote:
> Bruce Levick - Vivamotion
> Been searching for an answer to selecting a random table and then a random
> row within the selected table.
>
> I have this code which successfully selects a random row within a hard
> coded table. But just can't get the random table working.

[snip]

> Anybody see the solution??

First we need to know _what_ the problem is. I think we can assume your code 
doesn't work the way you expected. Can you tell us _how_ it doesn't work? 
Error messages?

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *


/*
We place two copies of PEOPLE magazine in a DARK, HUMID mobile home.
45 minutes later CYNDI LAUPER emerges wearing a BIRD CAGE on her head!
*/


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DB] random rows...what about tables

2002-12-17 Thread Bruce Levick
Bruce Levick - Vivamotion
Been searching for an answer to selecting a random table and then a random
row within the selected table.

I have this code which successfully selects a random row within a hard coded
table. But just can't get the random table working.

Error performing query: " .
   mysql_error() . "");
  exit();
}

 $randrow = mysql_fetch_array($rndm);
 ?>

Anybody see the solution??

Winxp Pro, php 4.2.2 Mysql 3.2

Cheers


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] random select

2002-12-17 Thread Bruce Levick
thankyou that seemed to work well.


- Original Message -
From: "Jason Wong" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, December 17, 2002 9:32 PM
Subject: Re: [PHP-DB] random select


> On Tuesday 17 December 2002 18:46, Bruce Levick wrote:
> > Bruce Levick - VivamotionI was curious as to what is the best way to
select
> > a random row from a table in my database.
> >
> > I have currently five rows and will be expanding on that as well. I have
> > tried this code.
> >
> > 
> > //retrieve random row
> >  >  $rndm = mysql_query("SELECT * FROM Illustrations ORDER BY RAND() LIMIT
>
> You need to use one of the mysql_fetch_*() functions. Details and examples
in
> manual.
>
> >  but am not getting anything when output with PHP in a browser. I am
> > working off localhost on a WINXP machine. PHP 4.2.2.
>
>
> --
> Jason Wong -> Gremlins Associates -> www.gremlins.biz
> Open Source Software Systems Integrators
> * Web Design & Hosting * Internet & Intranet Applications Development *
>
>
> /*
> "Ain't that something what happened today.  One of us got traded to
> Kansas City."
> -- Casey Stengel, informing outfielder Bob Cerv he'd
>been traded.
> */
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] random select

2002-12-17 Thread Jason Wong
On Tuesday 17 December 2002 18:46, Bruce Levick wrote:
> Bruce Levick - VivamotionI was curious as to what is the best way to select
> a random row from a table in my database.
>
> I have currently five rows and will be expanding on that as well. I have
> tried this code.
>
> 
> //retrieve random row
>   $rndm = mysql_query("SELECT * FROM Illustrations ORDER BY RAND() LIMIT

You need to use one of the mysql_fetch_*() functions. Details and examples in 
manual.

>  but am not getting anything when output with PHP in a browser. I am
> working off localhost on a WINXP machine. PHP 4.2.2.


-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *


/*
"Ain't that something what happened today.  One of us got traded to
Kansas City."
-- Casey Stengel, informing outfielder Bob Cerv he'd
   been traded.
*/


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DB] random select

2002-12-17 Thread Bruce Levick
Bruce Levick - VivamotionI was curious as to what is the best way to select
a random row from a table in my database.

I have currently five rows and will be expanding on that as well. I have
tried this code.


//retrieve random row
Error performing query: " .
   mysql_error() . "");
  exit();
}
 ?>

##
output random row

$rndm[titletext]\n";
 ?>

##

 but am not getting anything when output with PHP in a browser. I am working
off localhost on a WINXP machine. PHP 4.2.2.

Cheers









-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] Random numbers with range in mysql?

2002-09-28 Thread John W. Holmes

> I'm trying to make "shops" that sell virtual objects.  They restock
once
> every 15 minutes.  This is all set up.  The problem is, I would like
to
> have objects in these shops with a random chance of being restocked.
My
> idea is to store two numbers in the restock list: chance, and outof.
>  (For a 1/5 chance on each restock, those values would be 1 for
chance,
> 5 for outof).  The problem is, I need a way of generating a random
> number within a certain range.  I thought of going through php and
> mt_rand(), but that would make for a very inefficient script.  Any
ideas?

MySQL has a RAND() function. Returns a random number between zero and
one. Multiply it by your limit and add one to get a range.

SELECT FLOOR(RAND()*5)+1 

To get a random number between one and five. To make an update random,
try something like this:

UPDATE yourtable SET ... WHERE FLOOR(RAND()*5)+1 = 1 AND ...

---John Holmes...



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DB] Random numbers with range in mysql?

2002-09-28 Thread Leif K-Brooks

I'm trying to make "shops" that sell virtual objects.  They restock once 
every 15 minutes.  This is all set up.  The problem is, I would like to 
have objects in these shops with a random chance of being restocked.  My 
idea is to store two numbers in the restock list: chance, and outof. 
 (For a 1/5 chance on each restock, those values would be 1 for chance, 
5 for outof).  The problem is, I need a way of generating a random 
number within a certain range.  I thought of going through php and 
mt_rand(), but that would make for a very inefficient script.  Any ideas?


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DB] Random

2002-08-11 Thread zhamrock

can someone help me to generate a random records from the database?
eg,

rec 1 john doe
rec 2 jay williams
rec 3 anie boo

random results:

rec 2 jay williams
rec 1 john doe
rec 3 anie boo

.




TIA'
zham


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] random

2002-06-04 Thread Jason Wong

On Wednesday 05 June 2002 03:56, Natividad Castro wrote:
> hi to all,
>
> I have a drop down menu where users will select a word. After they submit
> it, I will generate a code number where I want to display the first three
> characters of the word they selected follow by Month and Date and three
> number that will be generating randomly.
> I don't have any problem displaying the MM/DD and the three numbers, but I
> don't know how to get the first three characters.

substr()

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *


/*
Lake Erie died for your sins.
*/


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] random

2002-06-04 Thread Beau Lebens

substr($foo, 0, 3);

check the other string functions in the manual - they are *very* useful

Beau
// -Original Message-
// From: Natividad Castro [mailto:[EMAIL PROTECTED]]
// Sent: Wednesday, 5 June 2002 3:57 AM
// To: [EMAIL PROTECTED]
// Subject: [PHP-DB] random
// 
// 
// hi to all,
// 
// I have a drop down menu where users will select a word. 
// After they submit
// it, I will generate a code number where I want to display 
// the first three
// characters of the word they selected follow by Month and 
// Date and three
// number that will be generating randomly.
// I don't have any problem displaying the MM/DD and the three 
// numbers, but I
// don't know how to get the first three characters.
// 
// //first page
// 
// 
// //second page
// $firsThreecharacter = $word;
// 
// //here is MM/DD
//$date = gmDate("md");
//$number = rand(100,999);
//$code_number = $str_char.$date.$number;
//echo $code_number." ";
// 
// Any help is  greatly appreciate it
// 
// Many thanks in advanced
// 
// Nato
// 
// 
// 
// -- 
// PHP Database Mailing List (http://www.php.net/)
// To unsubscribe, visit: http://www.php.net/unsub.php
// 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DB] random

2002-06-04 Thread Natividad Castro

hi to all,

I have a drop down menu where users will select a word. After they submit
it, I will generate a code number where I want to display the first three
characters of the word they selected follow by Month and Date and three
number that will be generating randomly.
I don't have any problem displaying the MM/DD and the three numbers, but I
don't know how to get the first three characters.

//first page


//second page
$firsThreecharacter = $word;

//here is MM/DD
   $date = gmDate("md");
   $number = rand(100,999);
   $code_number = $str_char.$date.$number;
   echo $code_number." ";

Any help is  greatly appreciate it

Many thanks in advanced

Nato



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] Random Selecting from mySQL

2002-03-13 Thread Gurhan Ozen

Hi!
Do you have a primary key field in the table? If yes, you can after
displaying the first 10 records you can put the primary key values of those
records in an array and have "primary_key_fiels NOT IN
(array_values_seperated_by_commas)" in your quesry.. So when you display
your first page with 10 records, then you won't have any restricting values
because the array will be empty. When you display it second time then you
will have the first 10 records excluded and your array will be populated 20
values so that when you display the third page thos 20 will be excluded and
vice versa.. Did I confuse you enough?:)
  I hope this helps..

Gurhan


-Original Message-
From: Georgie Casey [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 13, 2002 7:11 PM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: [PHP-DB] Random Selecting from mySQL


yea, i know how to display 10 results per page, but that doesnt work when
you want to do a ORDER BY rand() query.

"Gurhan Ozen" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> are you just looking for a way to display 10  results per page? If yes
then
> you can just use LIMIT to limit your result to 10 .. So, for the first
page,
> you can do "SELECT  LIMIT 1, 10;" and for the second page "SELECT ...
> LIMIT 11, 20" etc etc .
>   You can sure use "ORDER BY" with "LIMIT" to to sort the results for a
> given criteria ..
>
> Gurhan
>
>
> -Original Message-
> From: Georgie Casey [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, March 13, 2002 2:00 PM
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: [PHP-DB] Random Selecting from mySQL
>
>
> I know how to use the "ORDER BY rand()" command on the end of queries to
> randomize selection, but that's no good when you want to only display 10
> results per page. The next page the user chooses, randomizes again and
could
> show duplicate fields and not at all show other fields.
>
> Does anyone know a way round this?
>
> --
> Regards,
> Georgie Casey
> [EMAIL PROTECTED]
>
> ***
> http://www.filmfind.tv
> Ireland's Online Film Production Directory
> ***
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] Random Selecting from mySQL

2002-03-13 Thread Billy S Halsey

Hi,

You might try something like this:

1) Create a temporary table in MySQL using the data from the table you 
are selecting from.
2) On each page, do your select with "order by rand() limit 10" from the 
temporary table
3) Do a second query to delete the rows that you just selected from the 
temporary table
4) On the next page, go back to step 2.

Syntax for copying a table into an identical temporary table:

CREATE TEMPORARY TABLE my_tbl SELECT * FROM tbl

(courtesy of "MySQL" by Paul DuBois).

/bsh/

Beau Lebens wrote:

>could you perhaps do the select on the first page, then store the results in
>a session (array) and just load different indexed portions of the resultset
>each page?
>
>only problem there is that you wouldn't get any refreshed results while
>browsing those pages - but i don't know if this matters for you or not.
>
>HTH
>
>Beau
>
>// -Original Message-
>// From: Georgie Casey [mailto:[EMAIL PROTECTED]]
>// Sent: Thursday, 14 March 2002 3:00 AM
>// To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
>// Subject: [PHP-DB] Random Selecting from mySQL
>// 
>// 
>// I know how to use the "ORDER BY rand()" command on the end 
>// of queries to
>// randomize selection, but that's no good when you want to 
>// only display 10
>// results per page. The next page the user chooses, randomizes 
>// again and could
>// show duplicate fields and not at all show other fields.
>// 
>// Does anyone know a way round this?
>// 
>// --
>// Regards,
>// Georgie Casey
>// [EMAIL PROTECTED]
>// 
>// ***
>// http://www.filmfind.tv
>// Ireland's Online Film Production Directory
>// ***
>// 
>// 
>// 
>// -- 
>// PHP Database Mailing List (http://www.php.net/)
>// To unsubscribe, visit: http://www.php.net/unsub.php
>// 
>
-- 


/-=[ BILLY S HALSEY ]=--\
| Member of Technical Staff, Sun Microsystems, Inc. ESP Solaris SW  |
| "All opinions and technical advice offered in this message are my |
| own and not necessarily endorsed by my employer." |
\--=[ [EMAIL PROTECTED] ]=/




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] Random Selecting from mySQL

2002-03-13 Thread Demitrious S. Kelly

Pass along a hidden form which documents exactly what rows have already
been shown



then you could use 

$seen=explode(':', $seen); to break it into an array...

after that use a foreach to add a 'and id != '.$seen into the sql query
for every element in $seen... thus not allowing duplicates on a per
visit basis...

-Original Message-
From: Georgie Casey [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, March 13, 2002 4:11 PM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: [PHP-DB] Random Selecting from mySQL

yea, i know how to display 10 results per page, but that doesnt work
when
you want to do a ORDER BY rand() query.

"Gurhan Ozen" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> are you just looking for a way to display 10  results per page? If yes
then
> you can just use LIMIT to limit your result to 10 .. So, for the first
page,
> you can do "SELECT  LIMIT 1, 10;" and for the second page "SELECT
...
> LIMIT 11, 20" etc etc .
>   You can sure use "ORDER BY" with "LIMIT" to to sort the results for
a
> given criteria ..
>
> Gurhan
>
>
> -Original Message-
> From: Georgie Casey [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, March 13, 2002 2:00 PM
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: [PHP-DB] Random Selecting from mySQL
>
>
> I know how to use the "ORDER BY rand()" command on the end of queries
to
> randomize selection, but that's no good when you want to only display
10
> results per page. The next page the user chooses, randomizes again and
could
> show duplicate fields and not at all show other fields.
>
> Does anyone know a way round this?
>
> --
> Regards,
> Georgie Casey
> [EMAIL PROTECTED]
>
> ***
> http://www.filmfind.tv
> Ireland's Online Film Production Directory
> ***
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] Random Selecting from mySQL

2002-03-13 Thread Beau Lebens

could you perhaps do the select on the first page, then store the results in
a session (array) and just load different indexed portions of the resultset
each page?

only problem there is that you wouldn't get any refreshed results while
browsing those pages - but i don't know if this matters for you or not.

HTH

Beau

// -Original Message-
// From: Georgie Casey [mailto:[EMAIL PROTECTED]]
// Sent: Thursday, 14 March 2002 3:00 AM
// To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
// Subject: [PHP-DB] Random Selecting from mySQL
// 
// 
// I know how to use the "ORDER BY rand()" command on the end 
// of queries to
// randomize selection, but that's no good when you want to 
// only display 10
// results per page. The next page the user chooses, randomizes 
// again and could
// show duplicate fields and not at all show other fields.
// 
// Does anyone know a way round this?
// 
// --
// Regards,
// Georgie Casey
// [EMAIL PROTECTED]
// 
// ***
// http://www.filmfind.tv
// Ireland's Online Film Production Directory
// ***
// 
// 
// 
// -- 
// PHP Database Mailing List (http://www.php.net/)
// To unsubscribe, visit: http://www.php.net/unsub.php
// 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] Random Selecting from mySQL

2002-03-13 Thread Georgie Casey

yea, i know how to display 10 results per page, but that doesnt work when
you want to do a ORDER BY rand() query.

"Gurhan Ozen" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> are you just looking for a way to display 10  results per page? If yes
then
> you can just use LIMIT to limit your result to 10 .. So, for the first
page,
> you can do "SELECT  LIMIT 1, 10;" and for the second page "SELECT ...
> LIMIT 11, 20" etc etc .
>   You can sure use "ORDER BY" with "LIMIT" to to sort the results for a
> given criteria ..
>
> Gurhan
>
>
> -Original Message-
> From: Georgie Casey [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, March 13, 2002 2:00 PM
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: [PHP-DB] Random Selecting from mySQL
>
>
> I know how to use the "ORDER BY rand()" command on the end of queries to
> randomize selection, but that's no good when you want to only display 10
> results per page. The next page the user chooses, randomizes again and
could
> show duplicate fields and not at all show other fields.
>
> Does anyone know a way round this?
>
> --
> Regards,
> Georgie Casey
> [EMAIL PROTECTED]
>
> ***
> http://www.filmfind.tv
> Ireland's Online Film Production Directory
> ***
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] Random Selecting from mySQL

2002-03-13 Thread Gurhan Ozen

are you just looking for a way to display 10  results per page? If yes then
you can just use LIMIT to limit your result to 10 .. So, for the first page,
you can do "SELECT  LIMIT 1, 10;" and for the second page "SELECT ...
LIMIT 11, 20" etc etc .
  You can sure use "ORDER BY" with "LIMIT" to to sort the results for a
given criteria ..

Gurhan


-Original Message-
From: Georgie Casey [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 13, 2002 2:00 PM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: [PHP-DB] Random Selecting from mySQL


I know how to use the "ORDER BY rand()" command on the end of queries to
randomize selection, but that's no good when you want to only display 10
results per page. The next page the user chooses, randomizes again and could
show duplicate fields and not at all show other fields.

Does anyone know a way round this?

--
Regards,
Georgie Casey
[EMAIL PROTECTED]

***
http://www.filmfind.tv
Ireland's Online Film Production Directory
***



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DB] Random Selecting from mySQL

2002-03-13 Thread Georgie Casey

I know how to use the "ORDER BY rand()" command on the end of queries to
randomize selection, but that's no good when you want to only display 10
results per page. The next page the user chooses, randomizes again and could
show duplicate fields and not at all show other fields.

Does anyone know a way round this?

--
Regards,
Georgie Casey
[EMAIL PROTECTED]

***
http://www.filmfind.tv
Ireland's Online Film Production Directory
***



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] Random numbers?

2002-02-03 Thread Chris Payne

Hi there,

That is absolutely PERFECT, thank you so much for that you are a lifesaver
:-)

Regards

Chris Payne

www.planetoxygene.com


> On sön, 03 feb 2002, Chris Payne wrote:
>
> > Hi there everyone,
> >
> > I need to generate a random number between 1 and 15 for insertion into a
> > DB, I can easily do the DB side of it but what is the best method for
> > quickly generating a random number between 1 and 15 (including 1 and 15
> > in the equation)?
>
> srand((double)microtime()*100);
> $randomnumber = rand(1,15);
>
> Something like this?
>
> --
> patrik_wallstrom->foodfight->[EMAIL PROTECTED]>+46-709580442


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] Random numbers?

2002-02-03 Thread Patrik Wallstrom

On sön, 03 feb 2002, Chris Payne wrote:

> Hi there everyone,
> 
> I need to generate a random number between 1 and 15 for insertion into a 
> DB, I can easily do the DB side of it but what is the best method for
> quickly generating a random number between 1 and 15 (including 1 and 15  
> in the equation)?

srand((double)microtime()*100);
$randomnumber = rand(1,15);

Something like this?

--
patrik_wallstrom->foodfight->[EMAIL PROTECTED]>+46-709580442

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DB] Random numbers?

2002-02-03 Thread Chris Payne

Hi there everyone,

I need to generate a random number between 1 and 15 for insertion into a DB, I can 
easily do the DB side of it but what is the best method for quickly generating a 
random number between 1 and 15 (including 1 and 15 in the equation)?

Thanks for all your help.

Regards

Chris

www.planetoxygenet.com



[PHP-DB] Random Row From Database

2001-11-10 Thread HEW Staff

Hi,

I'm trying to pull a random row from my database and display the contents.

I know that the code:
SELECT * FROM TABLENAME WHERE RAND() LIMIT 1
should work.

However, there are 19 rows in the database and only the first row ever shows
up.

Is there a way to do this to ensure uniqueness?

The code I am using at the moment also filters so that rows are pulled from
the database given certain other criteria such as:

SELECT * FROM TABLENAME WHERE PayerID=$id AND RAND() LIMIT 1

All of the rows in the database contain the same PayerID and this column is
not the Primary Key.

Any help much appreciated.
Jonathan S Hardiman
President/CEO
Hardiman Enterprises Worldwide



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] random created numbers and letters

2001-09-25 Thread Andreas D. Landmark

At 25.09.2001 22:46, Saulius Jankauskas wrote:
>Hello,
>
>Can you give me a piece of code, where I could see, how to create random
>written numbers and letters?
>
>For example, I'd like to give my visitor temporary passwrord: BS0147. To
>another HF0124 and so on...
>
>How to generate it with PHP?
>
>Sorry, if I didn;t explained clearly what I want.
>
>Thanks.

Did you read _anything_ in the manual before posting?!

(and how on earth is this related to php-DB ?!)

check out

rand()
srand()
mt_rand()
mt_srand()

and so on... and I'll leave it up to the reader to decide how to create
a password-fish out of a row of numbers...

-- 
Andreas D Landmark / noXtension
Real Time, adj.:
 Here and now, as opposed to fake time, which only occurs there
and then.


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DB] random created numbers and letters

2001-09-25 Thread Saulius Jankauskas

Hello,

Can you give me a piece of code, where I could see, how to create random
written numbers and letters?

For example, I'd like to give my visitor temporary passwrord: BS0147. To
another HF0124 and so on...

How to generate it with PHP?

Sorry, if I didn;t explained clearly what I want.

Thanks.




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: RE: [PHP-DB] Random

2001-09-03 Thread Russ Michell

Try:

$result = mysql_db_query ("$DBName","select * from Contacts order by rand()
LIMIT 0,5 ");

As your first example had the '0' and then the '5' after the LIMIT clause, the second 
didn't have 
th any '0'.

Cheers.
Russ

On Fri, 31 Aug 2001 20:59:16 +0100 Seb Frost <[EMAIL PROTECTED]> wrote:

> I know it's documented as rand() but you might want to try random() just in
> case... I'm sure I read that somewhere
> 
> - seb
> 
> 
> -Original Message-
> From: John Hurleston [mailto:[EMAIL PROTECTED]]
> Sent: 31 August 2001 19:18
> To: [EMAIL PROTECTED]
> Subject: [PHP-DB] Random
> 
> 
> I would like to get the first 5 random entries out of my "mysql" database,
> what would be the correct SELECT option?
> 
> I adjusted this line
> 
> $result = mysql_db_query ("$DBName","select * from Contacts LIMIT 0,5 ");
> which works correctly. :)
> 
> $result = mysql_db_query ("$DBName","select * from Contacts order by rand()
> LIMIT 5 ");
> Doesn't work at all. :(
> 
> 
> Can anyone through any light on this subject.
> 
> Thanks.
> 
> 
> 
> 
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.274 / Virus Database: 144 - Release Date: 23/08/2001
> 
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.274 / Virus Database: 144 - Release Date: 23/08/2001
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 

#---#

  "Believe nothing - consider everything"   
  
  Russ Michell
  Anglia Polytechnic University Webteam
  Room 1C 'The Eastings' East Road, Cambridge
  
  e: [EMAIL PROTECTED]
  w: www.apu.ac.uk/webteam
  t: +44 (0)1223 363271 x 2331

  www.theruss.com

#---#


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP-DB] Random

2001-08-31 Thread Seb Frost

I know it's documented as rand() but you might want to try random() just in
case... I'm sure I read that somewhere

- seb


-Original Message-
From: John Hurleston [mailto:[EMAIL PROTECTED]]
Sent: 31 August 2001 19:18
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Random


I would like to get the first 5 random entries out of my "mysql" database,
what would be the correct SELECT option?

I adjusted this line

$result = mysql_db_query ("$DBName","select * from Contacts LIMIT 0,5 ");
which works correctly. :)

$result = mysql_db_query ("$DBName","select * from Contacts order by rand()
LIMIT 5 ");
Doesn't work at all. :(


Can anyone through any light on this subject.

Thanks.




--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.274 / Virus Database: 144 - Release Date: 23/08/2001

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.274 / Virus Database: 144 - Release Date: 23/08/2001


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] Random

2001-08-31 Thread Paul Burney

> according tho the description at
> , that looks

>> $result = mysql_db_query ("$DBName","select * from Contacts order by rand()
>> LIMIT 5 ");
>> Doesn't work at all. :(

What version of MySQL are you using?  I remember something about ordering by
rand() only working in 3.23.xx.  If you're using 3.22.xx, it won't work.

You could do something with mysql_data_seek() and the php mt_rand() function
if that's the case.  It would be klunky, but you could probably get it to
work.

Sincerely,

Paul Burney

+-+-+
| Paul Burney | P: 310.825.8365 |
| Webmaster && Programmer | E: <[EMAIL PROTECTED]>   |
| UCLA -> GSE&IS -> ETU   | W:  |
+-+-+


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] Random

2001-08-31 Thread Chris Hobbs

I was sure there was a syntax error in that SELECT statement, but 
according tho the description at 
, that looks 
right on to me. I know this doesn't help a lot, but at least you've had 
a second set of eyes confirm that your code looks right.

John Hurleston wrote:


> $result = mysql_db_query ("$DBName","select * from Contacts order by rand()
> LIMIT 5 ");
> Doesn't work at all. :(


-- 
Chris Hobbs   Silver Valley Unified School District
Head geek:  Technology Services Coordinator
webmaster:   http://www.silvervalley.k12.ca.us/~chobbs/
postmaster:   [EMAIL PROTECTED]


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DB] Random

2001-08-31 Thread John Hurleston

I would like to get the first 5 random entries out of my "mysql" database,
what would be the correct SELECT option?

I adjusted this line

$result = mysql_db_query ("$DBName","select * from Contacts LIMIT 0,5 ");
which works correctly. :)

$result = mysql_db_query ("$DBName","select * from Contacts order by rand()
LIMIT 5 ");
Doesn't work at all. :(


Can anyone through any light on this subject.

Thanks.




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] Random question selection in PHP w/ MySQL backend.

2001-07-31 Thread John Pickett

Adam,

I'm what I would call a novice to PHP and databases in general, however if I
had to do what you're doing, I might do the following...

Add a field to the table that contains your questions called "displayed" and
have it be an enum of Yes/No True/False, etc...  In your script, you'd then
query for all the questions that haven't already been displayed.  Then get a
random one of those (plenty of randomizing functions in PHP I believe).
Display it, mark it as displayed in the db...  Next time, it won't even get
returned in the query.  I don't know if you have to do this on a per-user
basis or what.  If so, you will probably have to create a session table and
keep track of the questions each user has viewed...  Hope this gets you
started...  Cheers!

My 2 ¢
John Pickett
http://www.bvstudios.com/
Co-Author:  Inside Dreamweaver 4
http://www.amazon.com/exec/obidos/ASIN/0735710848/xtremist

- Original Message -
From: "Adam Lundrigan" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, July 31, 2001 2:32 PM
Subject: [PHP-DB] Random question selection in PHP w/ MySQL backend.


I'm having a bit of trouble creating a random question selector. I'm using
PHP 4.0.6 and MySQL 3.23.36 on Windows 98 SE.
I've tried several different solutions, but none work at all.

What i need to do is select 10 questions from a database (db: vpt, table:
questions), and make sure that the same question doesn't appear twice. The
questions need to appear in a random order each time the script is loaded.
It sounds simple enough, but i just can't seem to get it to work.

Any suggestions??


Thanks in advance,

-Adam Lundrigan
 CEO, VPU
 http://www.vpu-virtual.com/

 ICQ # 73617446
 [EMAIL PROTECTED]





-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DB] Random question selection in PHP w/ MySQL backend.

2001-07-31 Thread Adam Lundrigan

I'm having a bit of trouble creating a random question selector. I'm using PHP 4.0.6 
and MySQL 3.23.36 on Windows 98 SE.
I've tried several different solutions, but none work at all.

What i need to do is select 10 questions from a database (db: vpt, table: questions), 
and make sure that the same question doesn't appear twice. The questions need to 
appear in a random order each time the script is loaded. It sounds simple enough, but 
i just can't seem to get it to work.

Any suggestions??


Thanks in advance,
 
-Adam Lundrigan
 CEO, VPU
 http://www.vpu-virtual.com/
 
 ICQ # 73617446
 [EMAIL PROTECTED]

 



RE: [PHP-DB] Random Password Generation/MSSQL

2001-07-12 Thread Mark Roedel

> -Original Message-
> From: Ryan Marrs [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, July 12, 2001 1:54 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP-DB] Random Password Generation/MSSQL
> 
> 
> Having an issue with this script, the generator works if I 
> just echo out the password, however when I attempt to update
> the table, it times-out in IIS.  I've bumped the IIS Timeout
> up to over 20 minutes, and it still times out.  This is on a
> database with approximately 29,000 entries.  Any ideas?
>
> [snip]
>
> for($i=1;$i<=$count;$i++){
> $DUNSNumber=$row->DUNSNumber;
> 
> echo rand_pass()."";

I bet if you 

  echo $insertquery

right here, you won't see what you were expecting to.  (Hint: $password
and $DUNSNumber aren't set when you give $insertquery its value; neither
is the string updated for each iteration of this loop.)

> MSSQL_QUERY($insertquery);
> }

Perhaps that's not the entire problem, but it can't be helping...if
nothing else, once that's corrected maybe you can start looking at doing
those updates in smaller batches.  20 minutes does seem a bit extreme,
but then it's hard to make much of a judgment on that without knowing
more about the machine in question, what else it's being used for
besides sql services, how heavily it's being utilized, etc.


---
Mark Roedel   | "Nothing in life is so bad that it cannot be
Systems Programmer|   made much, much worse by the addition of
LeTourneau University |lots of spikes and razors."
Longview, Texas, USA  |-- Sean Kozma 

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DB] Random Password Generation/MSSQL

2001-07-12 Thread Ryan Marrs

Having an issue with this script, the generator works if I just echo out the
password, however when I attempt to update the table, it times-out in IIS.
I've bumped the IIS Timeout up to over 20 minutes, and it still times out.
This is on a database with approximately 29,000 entries.  Any ideas?

Ryan



function rand_pass() {
$array = array(
 "a","b","c","d","e","f","g","h","i","j","k","l",
 "m","n","o","p","q","r","s","t","u","v","w","x","y",
  "z","1","2","3","4","5","6","7","8","9"
 );

  $num_letters = 10;
  $uppercased = 3;
  mt_srand ((double)microtime()*100);
  for($i=0; $i<$num_letters; $i++)
$pass .= $array[mt_rand(0, (count($array) - 1))];
  for($i=1; $iDUNSNumber;

echo rand_pass()."";
MSSQL_QUERY($insertquery);
}
MSSQL_CLOSE();


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] Random - not that random

2001-05-17 Thread Ken Wills

Hi Dan,

You need to call mt_srand() first to seed the random number generator. It's all 
described here:

http://www.php.net/manual/en/function.mt-rand.php

Ken

* Dan Eskildsen <[EMAIL PROTECTED]> [010517 14:22]:
> Newbie alert
> 
> Hi!  Here is a piece of coding.  It randomly choose between four options to
> display on my homepage.  The problem is that it doesn't seem to be that
> random - rather biased.  The last option $message[3] is displayed 9 out of
> 10 times.  Any suggestions?
> 
> 
> 
> $message[0] = ' src="images/trolley.jpg">
Rengøringsvogne, mopper m.m.
'; > $message[1] = ' src="images/nilfisk.gif">
Nilfisk Advance rengøringsmaskiner
'; > $message[2] = ' src="images/ladder.jpg">
Har du set vores Vinduespudserstiger?
'; > $message[3] = ' border="0"src="images/logo-bison.gif">
Vi importerer selv vore polisher > fra en af Canadas førende Polishfabrikker.
'; > > $number = mt_rand(0,3) ; > print"$message[$number]"; > > > > -- > == > Regards from Denmark, Europe > Please cc your reply to [EMAIL PROTECTED] > == > I haven't lost my mind, I've got it backed up on TAPE somewhere... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]

[PHP-DB] Random - not that random

2001-05-17 Thread Dan Eskildsen

Newbie alert

Hi!  Here is a piece of coding.  It randomly choose between four options to
display on my homepage.  The problem is that it doesn't seem to be that
random - rather biased.  The last option $message[3] is displayed 9 out of
10 times.  Any suggestions?



$message[0] = '
Rengøringsvogne, mopper m.m.
'; $message[1] = '
Nilfisk Advance rengøringsmaskiner
'; $message[2] = '
Har du set vores Vinduespudserstiger?
'; $message[3] = '
Vi importerer selv vore polisher fra en af Canadas førende Polishfabrikker.
'; $number = mt_rand(0,3) ; print"$message[$number]"; -- == Regards from Denmark, Europe Please cc your reply to [EMAIL PROTECTED] == I haven't lost my mind, I've got it backed up on TAPE somewhere... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]