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!
 
 html
 
 head
 
 titleTop Frame/title
 
 /head
 
 body bgcolor=#ff text=#00 link=#ff vlink=#800080
 alink=#ff
 EMBED SRC= autostart=true hidden=true loop=true volume=100%
 ?
 
 $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







 }
 ?
 
 
 /body
 
 /html

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

html

head

titleTop Frame/title

/head

body bgcolor=#ff text=#00 link=#ff vlink=#800080
alink=#ff
EMBED SRC= autostart=true hidden=true loop=true volume=100%
?

$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;
}
?


/body

/html

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

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
?php
 $rndm = mysql_query(SELECT * FROM Illustrations ORDER BY RAND() LIMIT 1);
 if (!$rndm) {
  echo(PError performing query:  .
   mysql_error() . /P);
  exit();
}
 ?

##
output random row

?php
 print b$rndm[titletext]/b\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 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
 ?php
  $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