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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.