optrex Posted March 17, 2008 Share Posted March 17, 2008 I am trying to run a query with a couple of conditions, unfortunately they are giving me grief. What I am after is the following: if text has a title then skip and continue onto the next if text has a null title, then get that information if status=allowed status, text and title are all text fields, this is what I have so far $result = mysql_query("SELECT username,title,text,date,userid,status FROM table_text ORDER BY date desc LIMIT 5" ) or die(mysql_error()); while($row = mysql_fetch_array( $result )) { can anyone offer some guidance please? Quote Link to comment https://forums.phpfreaks.com/topic/96582-help-with-a-query-please/ Share on other sites More sharing options...
fenway Posted March 17, 2008 Share Posted March 17, 2008 "Skip" and "continue" have no meaning in set theory. Get info from where? Quote Link to comment https://forums.phpfreaks.com/topic/96582-help-with-a-query-please/#findComment-494279 Share on other sites More sharing options...
optrex Posted March 17, 2008 Author Share Posted March 17, 2008 the closest I have got to do what I want to do is this $result = mysql_query("SELECT username,title,text,date,userid,status FROM table_text WHERE title IS NULL AND status = 'allowed' ORDER BY date desc LIMIT 5" ) or die(mysql_error()); while($row = mysql_fetch_array( $result )) { my mistake is that title is not null, therefore I need to replace with something that represents title IS BLANK Quote Link to comment https://forums.phpfreaks.com/topic/96582-help-with-a-query-please/#findComment-494289 Share on other sites More sharing options...
Barand Posted March 17, 2008 Share Posted March 17, 2008 WHERE title = '' Quote Link to comment https://forums.phpfreaks.com/topic/96582-help-with-a-query-please/#findComment-494306 Share on other sites More sharing options...
optrex Posted March 21, 2008 Author Share Posted March 21, 2008 thanks I've not got the query running as $result = mysql_query("SELECT userid,field23,field24 FROM userfield ORDER BY field24 desc LIMIT 5" ) or die(mysql_error()); while($row = mysql_fetch_array( $result )) can anyone tell me how I would randomise the output? I seem to have a sytax error when I change order by field24 desc to order by field24 RAND() Quote Link to comment https://forums.phpfreaks.com/topic/96582-help-with-a-query-please/#findComment-497888 Share on other sites More sharing options...
Barand Posted March 21, 2008 Share Posted March 21, 2008 missing comma order by field24, RAND() Quote Link to comment https://forums.phpfreaks.com/topic/96582-help-with-a-query-please/#findComment-497907 Share on other sites More sharing options...
optrex Posted March 21, 2008 Author Share Posted March 21, 2008 Hi Barand, I've just given that a try, but it returns no results Quote Link to comment https://forums.phpfreaks.com/topic/96582-help-with-a-query-please/#findComment-497927 Share on other sites More sharing options...
Barand Posted March 21, 2008 Share Posted March 21, 2008 any error message? Quote Link to comment https://forums.phpfreaks.com/topic/96582-help-with-a-query-please/#findComment-497956 Share on other sites More sharing options...
optrex Posted March 22, 2008 Author Share Posted March 22, 2008 no nothing, just a blank return Quote Link to comment https://forums.phpfreaks.com/topic/96582-help-with-a-query-please/#findComment-498273 Share on other sites More sharing options...
Barand Posted March 22, 2008 Share Posted March 22, 2008 What code have you to output it then? Quote Link to comment https://forums.phpfreaks.com/topic/96582-help-with-a-query-please/#findComment-498351 Share on other sites More sharing options...
optrex Posted March 23, 2008 Author Share Posted March 23, 2008 this is my code, following the database connect $result = mysql_query("SELECT userid,field23,field24 FROM userfield ORDER BY field24 desc LIMIT 5" ) or die(mysql_error()); while($row = mysql_fetch_array( $result )) { $comms .= <<<PRINT <tr> <td class="$bgclass" align="left"> <span class="{$Style['small']}"> <a href="$row[field23]" target="_blank">$row[field24]</a> </td> </tr> PRINT; } Quote Link to comment https://forums.phpfreaks.com/topic/96582-help-with-a-query-please/#findComment-498943 Share on other sites More sharing options...
Barand Posted March 23, 2008 Share Posted March 23, 2008 do you then echo $comms; Quote Link to comment https://forums.phpfreaks.com/topic/96582-help-with-a-query-please/#findComment-498945 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.