| FAQ |
| Kalender |
|
|
#1 | |||
|
||||
|
Medlem
|
Hallo!
Jag försöker skriva ut data från två tabeller i min MySQL i en array men gör något fel. Det finns säkert någon bättre metod att göra detta? Kod:
// Select the ad from first table
$getads = mysql_query("SELECT * FROM wi1_posts WHERE post_status='publish' AND post_type='ad_listing' ORDER BY post_date DESC LIMIT 5");
while($row=mysql_fetch_array($getads)){
// Get image
$getimg = mysql_query("SELECT * FROM wi1_postmeta WHERE post_id=".$row['ID']." AND meta_key='_wp_attachment_metadata'");
while($row2=mysql_fetch_array($getimg)){
echo '<h3>';
echo $row['post_title'];
echo '</h3>';
echo $row2['meta_value'];
echo "<br />";
echo $row['post_date'];
echo "<br />";
echo $row['post_content'];
echo "<br /><br /><br />";
}
}
|
|||
|
|
Svara med citat
|
|
|
#2 | |||
|
||||
|
Medlem
|
Fick det att nästan fungera med detta:
Kod:
$getads = mysql_query("SELECT wi1_posts.post_title, wi1_posts.post_content, wi1_posts.post_date, wi1_postmeta.meta_value, wi1_postmeta.meta_key
FROM wi1_posts
INNER JOIN wi1_postmeta
ON wi1_posts.ID=wi1_postmeta.post_id
WHERE wi1_posts.post_status='publish' AND wi1_posts.post_type='ad_listing'
ORDER BY wi1_posts.post_date DESC LIMIT 5");
while($row=mysql_fetch_array($getads)){
echo '<h3>';
echo $row['post_title'];
echo '</h3>';
echo $row['meta_value'];
echo "<br />";
echo $row['post_date'];
echo "<br />";
echo $row['post_content'];
echo "<br /><br /><br />";
}
meta_id post_id meta_key meta_value Och jag vill bara skriva ut meta_value där meta_key är "_wp_attached_file". Hur löser man detta månne? |
|||
|
|
Svara med citat
|
|
|
#3 | ||
|
|||
|
Flitig postare
|
if ( $row['meta_key'] == "_wp_attached_file") {
echo $row['meta_value']; } |
||
|
|
Svara med citat
|
|
|
#4 | |||
|
||||
|
Flitig postare
|
PHP-kod:
|
|||
|
|
Svara med citat
|
| Svara |
| Ämnesverktyg | |
| Visningsalternativ | |
|
|