I ran mysql_query
and queried the table I selected, then used mysql_fetch_assoc
to put the results into an array. Then I tried to loop through that array and, basically, I ran an if
statement saying that if a post was of a certain category ID, I want it to go to another array, but it just doesn't seem to work. Here's what I currently have:
$getPostType = "SELECT * FROM myTable";
$queryPostType = mysql_query($getPostType) or die("Could Not Connect: ".mysql_error());
$postTypeArray = mysql_fetch_assoc($queryPostType);
$queryPostType1 = array();
foreach ($postTypeArray as $key => $value) {
echo $key;
echo $value;
if($postTypeArray['category']===7){
echo $key;
echo $value;
$queryPostType1[]=$postTypeArray[$value];
//array_push($queryPostType1, $postTypeArray);
}
}
It would also help to know, that each element is a row from a table with multiple columns.
so far the way im doing, and it works is:
<?php $queryPostType = mysql_query($getPostType) or die("Could Not Connect: ".mysql_error()); ?>
<?php $postTypeArray = mysql_fetch_assoc($queryPostType); ?>
<?php do{ ?>
<?php if($postTypeArray['category'] == 7){ ?>
<article>
<h3><strong><?php echo $postTypeArray['title']; ?></strong></h3>
<div><?php echo $postTypeArray['html']; ?></div>
</article>
<?php } ?>
<?php }while($postTypeArray = mysql_fetch_assoc($queryPostType)) ?>
Where "category" is the category ID, "title" is the post title, and "html" is the actual post content.
But the only problem with that is that I do that over and over again and make a query for each category ID. Im some places I'm making as much as 12 queries but I'd like to make only one query, close my connection, loop through the data, push them into separate arrays and distribute the date from there.
Thanks again for any help.
$queryPostType1[]=$postTypeArray[$key];
nah ? – mpgn Sep 16 '14 at 18:43