PHP hjälp
Visa första olästa |
| #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? CODE
// 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 />";
}
}
|
| #2 | |
|
Medlem
|
Fick det att nästan fungera med detta:
CODE
$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 />";
}
Problemet är att tabellen wi1_postmeta innehåller följande fält: 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? |
| #3 | |
|
Flitig postare
|
if ( $row['meta_key'] == "_wp_attached_file") {
echo $row['meta_value']; } |
| #4 | |
|
Flitig postare
|
PHP $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' AND wi1_postmeta.meta_key='_wp_attached_file'
ORDER BY wi1_posts.post_date DESC LIMIT 5") or die(mysql_error());Inte provat men tror att det fungerar. |
Aktiva användare som för närvarande tittar på det här ämnet: 0 (0 medlemmar och 0 gäster)

Visa första olästa