Jump to content

help with a query please


optrex

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/96582-help-with-a-query-please/
Share on other sites

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

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

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.