go2go Posted October 27, 2006 Share Posted October 27, 2006 Can someone please help me creating a php file for the following codes:$sql = 'SELECT * FROM library ORDER BY RAND() limit 5;';where Database is: localhostDatabase name is: libuser: guest2pass: guest2Thanks Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 27, 2006 Share Posted October 27, 2006 I might be wrong here dont now try this ok.Where it says the table name your have to specify the table to be round.fully tested working ok.good luck redarrow.[code]$db=mysql_connect('localhost','guest2','guest2');mysql_select_db('lib',$db);$sql = " SELECT table_name FROM library order by round() limit 5 ";$result=mysql_query($sql)or die("query round problam");[/code]And this one for all the tables round.[code]$db=mysql_connect('localhost','guest2','guest2');mysql_select_db('lib',$db);$sql = " SELECT * FROM library order by round() limit 5 ";$result=mysql_query($sql)or die("query round problam");[/code] Quote Link to comment Share on other sites More sharing options...
go2go Posted October 27, 2006 Author Share Posted October 27, 2006 Thanks for your guide. I created a file called test.php as below:[code]<?// file test.php$db=mysql_connect('localhost','user','pass');mysql_select_db('database',$db);$sql = "SELECT * FROM Table_NAME order by round() limit 5";$result=mysql_query($sql)or die("query round problam");?>[/code]The code seems to be working. BUT there was no display of records!!I need to incorporate a template to display the 5 random records.Any idea, please. Quote Link to comment Share on other sites More sharing options...
akitchin Posted October 27, 2006 Share Posted October 27, 2006 you need to change that query back to what you had originally.in order to pass through the resource ID sent back from a mysql_query() function, you need to use a while() loop. any simply PHP/MySQL tutorial out there should give you a good grounding in how this is done, and there is even one on the phpfreaks.com main website by one of our mods. have a look.NOTE: i'm purposely not giving you straight code because although it would be fast and easy, if you follow a tutorial you are much more likely to be able to do this kind of thing again. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.