mysql_query select help

Status
Not open for further replies.

Divvy

Active Member
806
2009
18
0
Hello guys,

Please give me a little help in a mysql_query (select)...

At the moment, I have this in ID order:
http://i.imgur.com/7fclwVp.png

But I want to order by date... can someone help me how to do it?

This is my code:
PHP:
$listFgpost =mysql_query("select * from $postTab where post_type='freegallery' and post_status='publish' and post_parent='$mrpostParent' order by ID DESC limit $start,$limit");

This is my variables:
Code:
$postTab = $wpdb->prefix."posts";
$postMeta = $wpdb->prefix."postmeta";

And this is my database tables:
http://i.imgur.com/hQfKct8.png
http://i.imgur.com/OizPuST.png
http://i.imgur.com/78dkOy7.png

Like I have, ordered by ID, is getting the info from prefix."posts";
And the date that I want, I need to get from prefix."postmeta";
Here you can see the meta_value that I need: http://i.imgur.com/78dkOy7.png

Here is a mysql_query("select getting from prefix."postmeta"; maybe is useful:
PHP:
$query=mysql_query("select * from $postTab as a,$postMeta as b where a.ID=b.post_id and a.post_type='model' and a.post_status='publish' and b.meta_key='mr_model_appear_sites' and FIND_IN_SET($mrpostParent,b.meta_value) order by a.ID DESC");

Can someone please help me? :)

Thank you very much!!
 
3 comments
[STRIKE]order by ID => order by "column name you want to sort by"

https://dev.mysql.com/doc/refman/5.0/en/sorting-rows.html[/STRIKE]

You have to join the tables first.

Try this:
Code:
select * from $postTab INNER JOIN $postMeta ON $postTab.ID=$postMeta.post_id where post_type='freegallery' and post_status='publish' and post_parent='$mrpostParent' order by ID DESC limit $start,$limit

If it doesn't work try replacing $postTab and $postMeta with the actual table name.
 
Last edited:
CK13, thank you my friend for your reply and help :)

The code almost worked! But is repeating the same thing 6x...

And I think that I need to change from:
Code:
order by ID DESC

To:
Code:
order by meta_value DESC

Right?

Waiting for your reply, thanks :)
 
The code almost worked! But is repeating the same thing 6x...
I don't know why, not that good with mysql and without the ability to change the code and see the output i can't figure it out.


And I think that I need to change from:
Code:
order by ID DESC

To:
Code:
order by meta_value DESC

Right?
Yes, but don't know if it will order your dates correctly.
 
Status
Not open for further replies.
Back
Top