Welcome to www.HAS.lv - programmējam HTML.

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

Sign in to follow this  
Followers 0
Trixx-

PHP Saīsinājums [Help @Sliede]

Sveiki visiem.

Gribētos vērsties pie sliedes, jo viņš man agrāk ļoti smuki aprakstīja kodu un gribēju pajautāt vai viņš vai kāds cits, kas labi saprot php varētu uzrakstīt šo kodu īsāk, ja ir iespējams un smukāk, lai nebūtu itkā putra?

$sql = "SELECT
            *
        FROM
            categories
        WHERE
            cat_id = " . mysqli_real_escape_string($conn, $_GET['cat_id']);
 
$result = mysqli_query($conn, $sql);
 
if(!$result)
{
    echo 'The category could not be displayed, please try again later.' . mysqli_error($conn);
}
else
{
    if(mysqli_num_rows($result) == 0)
    {
        echo 'This category does not exist.';
    }
    else
    {
        while($row = mysqli_fetch_array($result)){
            if(isset($_GET['cat_id'])){
                echo '<div class="category"><span style="border-bottom: 2px solid #E74C3C;">'.$row['cat_name'].'</span></div>';
            }
            elseif(isset($_GET['cat_id']) && isset($_GET['forum_id'])) {
                echo '<div class="category"><span style="border-bottom: 2px solid #E74C3C;">'.$row['forum_name'].'</span></div>';
            }
        }
        $sql = "SELECT  
                    forum_id,
                    forum_name,
                    forum_description,
                    forum_topics,
                    forum_posts,
                    cat_id
                FROM
                    forum
                WHERE
                    forum_id = '" . mysqli_real_escape_string($conn, $_GET['forum_id']) . "'
                ORDER BY
                    forum_id
                DESC";
         
        $result = mysqli_query($conn, $sql);
         
        if($result)
        {             
        echo '<div class="forum">
        	<div class="forum_body">';      
                while($row = mysqli_fetch_assoc($result))
                {
                    if($_GET['forum_id'] == $row['forum_id']){
                    	echo '';
                    }
                }
        echo '
        </div>
        </div>';
        }
        else {
            echo mysqli_error($conn);
        }
    }
}

 

0

Share this post


Link to post
Share on other sites
<?php

function showTopics($catId, $forumId) {
    $result = mysqli_query($conn, 'SELECT * FROM categories WHERE cat_id = ' . intval($catId));

    if (!$result) {
        return 'The category could not be displayed, please try again later.' . mysqli_error($conn);
    }

    if (mysqli_num_rows($result) === 0) {
        return 'This category does not exist.';
    }

    $return = '';
    while ($row = mysqli_fetch_array($result)) {
        $return .= '<div class="category"><span style="border-bottom: 2px solid #E74C3C;">' . $row['cat_name'] . '</span></div>';
    }


    $result = mysqli_query($conn, 'SELECT
        forum_id,
        forum_name,
        forum_description,
        forum_topics,
        forum_posts,
        cat_id
    FROM forum WHERE forum_id = ' . intval($forumId));

    if (!$result){
        return mysqli_error($conn);
    }

    $return .= '<div class="forum">
      <div class="forum_body">';
    while ($row = mysqli_fetch_assoc($result)) {
        echo '';
    }
    $return .=  '</div></div>';

    return $return;
}

if (isset($_GET['cat_id']) && isset($_GET['forum_id'])) {
    echo showTopics($_GET['cat_id'], $_GET['forum_id']);
} else {
    echo "No cat selected";
}

 

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0