fantomel Posted May 7, 2008 Share Posted May 7, 2008 <?php rand(1,$count_row); $sql = "SELECT * FROM vacante LIMIT $rand,1"; $count_row = mysql_num_rows($res); $sql = "SELECT * FROM vacante LIMIT $rand,1"; $res = mysql_query($sql) or die(mysql_error()); { $titlu=$prod_sel['titlu']; $subtitlu=$prod_sel['subtitlu']; $desc=$prod_sel['poze']; } ?> error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1 please someone corect my code it's for a random result from mysql in table vacations i have some offers and i want to random in a table on the first page random offers but only title subtitle picture and price. thank you for helping me Link to comment https://forums.phpfreaks.com/topic/104548-please-corect-my-code/ Share on other sites More sharing options...
conker87 Posted May 7, 2008 Share Posted May 7, 2008 Put your line declaring what $count_row is before it's actually used. Link to comment https://forums.phpfreaks.com/topic/104548-please-corect-my-code/#findComment-535163 Share on other sites More sharing options...
Fadion Posted May 7, 2008 Share Posted May 7, 2008 What rand() returns must be assigned to a variable. Your $rand has no value in it. $rand = rand(1,$count_row); Link to comment https://forums.phpfreaks.com/topic/104548-please-corect-my-code/#findComment-535180 Share on other sites More sharing options...
fantomel Posted May 7, 2008 Author Share Posted May 7, 2008 What rand() returns must be assigned to a variable. Your $rand has no value in it. $rand = rand(1,$count_row); <?php $rand = rand(1,$count_row); $sql = "SELECT * FROM vacante LIMIT $rand,1"; $res = mysql_query($sql) or die(mysql_error()); { $count_row = mysql_num_rows($res); $titlu=$prod_sel['titlu']; $subtitlu=$prod_sel['subtitlu']; $desc=$prod_sel['poze']; ?> so this is how it must look ? :-s Link to comment https://forums.phpfreaks.com/topic/104548-please-corect-my-code/#findComment-535195 Share on other sites More sharing options...
Fadion Posted May 7, 2008 Share Posted May 7, 2008 Why not test i yourself . Remove that curly brace ( { ) at the query line (line 3), and it should work correctly. Link to comment https://forums.phpfreaks.com/topic/104548-please-corect-my-code/#findComment-535198 Share on other sites More sharing options...
fantomel Posted May 7, 2008 Author Share Posted May 7, 2008 Why not test i yourself . Remove that curly brace ( { ) at the query line (line 3), and it should work correctly. thank you for your help GuiltyGear it work's perfectly Link to comment https://forums.phpfreaks.com/topic/104548-please-corect-my-code/#findComment-535201 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.