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