Programming

  • 5 {{ upvoteCount | shortNum }}

    Need Help Converting Database Query into a Model and Output to a View

    scottlpool2003 in Programming

    The query is: PHP Code: <?php //Set default number of columns //GET CATEGORIES $numCols = 2; $count = 0; $result = mysql_query("SELECT * FROM categories"); //Count number of rows and divide into 2 $numPerCol = ceil(mysql_num_rows($result) / $numCols); echo "<div style=\"width:369px;\">\n"; for($col = 1; $col <= $numCols; $col++) {     echo "<div style=\"width:46.7%;float:right;margin-left:5px;\">";     for($row = 0; $row < $numPerCol; $row++) {         $resultRow = mysql_fetch_assoc($result);         if($resultRow == false) {             break;         } //Convert data         $title = $resultRow['title'];         $id = $resultRow['id'];         $url = $resultRow['url']; //Output data         echo "<h3>$title</h3>"; //Get subcategories         $resultb = mysql_query("SELECT * FROM cat_objects WHERE parent_id = '$id' LIMIT 5"); //Check if no results ... [read more]